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
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user