8501fd074c
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
55 lines
925 B
Go
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
|
|
}
|