-
Notifications
You must be signed in to change notification settings - Fork 2
/
session.go
30 lines (26 loc) · 846 Bytes
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package pulse
import (
"encoding/json"
)
// 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.
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"`
}
// TotalFileDuration calculates the total duration of all files in the session.
func (s Session) TotalFileDuration() int64 {
totalDuration := int64(0)
for _, file := range s.Files {
totalDuration += file.DurationMs
}
return totalDuration
}
// Serialize serializes the session to a JSON byte slice.
func (s Session) Serialize() ([]byte, error) {
return json.MarshalIndent(s, "", " ")
}