Files
gosleep/history/stats.go
T
forust 8501fd074c feat: initial gosleep-timer implementation
Go TUI sleep timer with modular architecture.
- Config: YAML-based, profile inheritance, auto WM detection
- Engine: timer, executor, stage pipeline (pre→timer→post)
- Modules: workspace (niri/hyprland/kde), media, lock, kill,
  notify, sound, brightness, mute, custom, script
- TUI: bubbletea app with profiles, module toggles, progress bar
- CLI: run, list-profiles, export, import, history, stats
- History: JSONL log with statistics
- QR: config export as ASCII QR
2026-07-03 01:43:22 +02:00

55 lines
925 B
Go

package history
import "time"
type Stats struct {
TotalRuns int
CompletedRuns int
KilledRuns int
ErrorRuns int
TotalDuration time.Duration
AvgDuration time.Duration
MostUsedProfile string
LastRun *Record
}
func Calculate(records []Record) Stats {
var s Stats
profileCount := make(map[string]int)
s.TotalRuns = len(records)
for _, r := range records {
switch r.Status {
case "completed":
s.CompletedRuns++
case "killed":
s.KilledRuns++
case "error":
s.ErrorRuns++
}
profileCount[r.Profile]++
d, err := time.ParseDuration(r.Duration)
if err == nil {
s.TotalDuration += d
}
s.LastRun = &r
}
if s.TotalRuns > 0 {
s.AvgDuration = time.Duration(int64(s.TotalDuration) / int64(s.TotalRuns))
}
maxCount := 0
for name, count := range profileCount {
if count > maxCount {
maxCount = count
s.MostUsedProfile = name
}
}
return s
}