Documentation ¶
Index ¶
- type AggregatedFile
- type AggregatedFiles
- type AggregatedSession
- type AggregatedSessions
- type Buffer
- type Clock
- type CodingSession
- func (s *CodingSession) Active() bool
- func (s *CodingSession) Duration() int64
- func (s *CodingSession) End(endedAt int64) Session
- func (s *CodingSession) HasBuffers() bool
- func (s *CodingSession) Pause(time int64)
- func (s *CodingSession) PauseTime() int64
- func (s *CodingSession) PushBuffer(buffer Buffer)
- func (s *CodingSession) Resume(time int64)
- type Event
- type File
- type Files
- type GitFile
- type Period
- type PermanentStorage
- type RealClock
- type Repositories
- type Repository
- type Session
- type Sessions
- type TemporaryStorage
- type TestClock
- func (c *TestClock) Add(d time.Duration)
- func (c *TestClock) GetTime() int64
- func (c *TestClock) NewTicker(d time.Duration) (<-chan time.Time, func())
- func (c *TestClock) NewTimer(d time.Duration) (<-chan time.Time, func() bool)
- func (c *TestClock) Now() time.Time
- func (c *TestClock) Set(t time.Time)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregatedFile ¶
type AggregatedFile struct { Name string `bson:"name"` Path string `bson:"path"` Filetype string `bson:"filetype"` DurationMs int64 `bson:"duration_ms"` }
AggregatedFile represents a file that has been aggregated for a given time period (day, week, month, year).
type AggregatedFiles ¶
type AggregatedFiles []AggregatedFile
AggregatedFiles represents a slice of files that has been aggregated for a given time period (day, week, month, year).
type AggregatedSession ¶
type AggregatedSession struct { ID string `bson:"_id,omitempty"` Period Period `bson:"period"` Date int64 `bson:"date"` DateString string `bson:"date_string"` TotalTimeMs int64 `bson:"total_time_ms"` Repositories Repositories `bson:"repositories"` }
AggregatedSession represents a session that has been aggregated for a given time period (day, week, month, year).
type AggregatedSessions ¶
type AggregatedSessions []AggregatedSession
func (AggregatedSessions) MergeByDay ¶
func (s AggregatedSessions) MergeByDay() AggregatedSessions
MergeByDay merges sessions that occurred the same day.
func (AggregatedSessions) MergeByMonth ¶
func (s AggregatedSessions) MergeByMonth() AggregatedSessions
MergeByWeek merges sessions that occurred the same month.
func (AggregatedSessions) MergeByWeek ¶
func (s AggregatedSessions) MergeByWeek() AggregatedSessions
MergeByWeek merges sessions that occurred the same week.
func (AggregatedSessions) MergeByYear ¶
func (s AggregatedSessions) MergeByYear() AggregatedSessions
MergeByYear merges sessions that occurred the same year.
type Buffer ¶
type Buffer struct { OpenedClosed []int64 Filename string Repository string Filepath string Filetype string }
Buffer represents a buffer that has been opened during an active coding session.
func (*Buffer) LastOpened ¶
LastOpened returns the last time the buffer was opened.
type Clock ¶
type Clock interface { Now() time.Time NewTicker(d time.Duration) (<-chan time.Time, func()) NewTimer(d time.Duration) (<-chan time.Time, func() bool) GetTime() int64 }
Clock is a simple abstraction to allow for time based assertions in tests.
type CodingSession ¶
type CodingSession struct { EditorID string StartedAt int64 OS string Editor string // contains filtered or unexported fields }
CodingSession represents an ongoing coding session.
func StartSession ¶
func StartSession(editorID string, startedAt int64, os, editor string) *CodingSession
StartSession creates a new coding session.
func (*CodingSession) Active ¶
func (s *CodingSession) Active() bool
Active returns true if the coding session is considered active.
func (*CodingSession) Duration ¶
func (s *CodingSession) Duration() int64
Duration returns the total duration of the coding session.
func (*CodingSession) End ¶
func (s *CodingSession) End(endedAt int64) Session
End ends the active coding sessions. It sets the total duration in milliseconds, and turns the stack of buffers into a slice of files.
func (*CodingSession) HasBuffers ¶
func (s *CodingSession) HasBuffers() bool
HasBuffers returns true if the coding session has opened any file backed buffers.
func (*CodingSession) Pause ¶
func (s *CodingSession) Pause(time int64)
Pause should be called when another editor process gains focus.
func (*CodingSession) PauseTime ¶
func (s *CodingSession) PauseTime() int64
PauseTime is used to determine which coding session to resume.
func (*CodingSession) PushBuffer ¶
func (s *CodingSession) PushBuffer(buffer Buffer)
PushBuffer pushes a new buffer to the current sessions buffer stack.
func (*CodingSession) Resume ¶
func (s *CodingSession) Resume(time int64)
Resume should be called when the editor regains focus.
type File ¶
type File struct { Name string `json:"name"` Path string `json:"path"` Repository string `json:"repository"` Filetype string `json:"filetype"` DurationMs int64 `json:"duration_ms"` }
File represents a file that has been opened during a coding session.
type Period ¶
type Period int8
Period represents the time period for which the coding sessions have been aggregated.
type PermanentStorage ¶
type PermanentStorage interface { Write(s []AggregatedSession) error Aggregate(timeperiod Period) error }
PermanentStorage is an abstraction for a storage that allows you to store sessions permanently.
type Repositories ¶
type Repositories []Repository
Repositories represents a list of git repositories.
type Repository ¶
type Repository struct { Name string `bson:"name"` Files AggregatedFiles `bson:"files"` DurationMs int64 `bson:"duration_ms"` }
Repository represents a git repository. A coding session might open files across any number of repos. The files of the coding session are later grouped by repository.
type Session ¶
type Session struct { StartedAt int64 `json:"started_at"` EndedAt int64 `json:"ended_at"` DurationMs int64 `json:"duration_ms"` OS string `json:"os"` Editor string `json:"editor"` Files Files `json:"files"` }
Session is the raw representation of a past coding session. These sessions are stored temporarily on disk, and are later aggregated and and moved to a database.
func (Session) TotalFileDuration ¶
TotalFileDuration calculates the total duration of all files in the session.
type Sessions ¶
type Sessions []Session
Sessions is a slice of several Session structs.
func (Sessions) Aggregate ¶
func (s Sessions) Aggregate() []AggregatedSession
Aggregate takes a list of locally stored sessions and aggregates them by day.
type TemporaryStorage ¶
TemporaryStorage is an abstraction for a storage that can be used to store the session data temporarily. Every editor instance is going to have its own session. Therefore, it's common to have several sessions for any given day. To not exceed any database free tier limits, the sessions are first stored temporarily, and can then be aggregated to a permanent storage once a day.