Files
adamfandClaude Opus 5.5 f4ce04875c
Test and publish / test (push) Successful in 2m38s
Test and publish / publish (push) Failing after 2m30s
Add activity tracker server, Hyprland agent and Gitea image publishing
The Go API on PostgreSQL ingests desktop, browser, presence, manual and
Health Auto Export events and serves activities and daily goal summaries.
The Hyprland agent records window focus, idle and lock intervals.

The CI workflow publishes adam-french.co.uk/adamf/activity-tracker to the
Gitea registry and rolls the web_server stack onto it. The image probes
itself through a new `tracker healthcheck` command, because distroless
has no wget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 20:38:12 +01:00

71 lines
1.8 KiB
Go

// Package summary builds daily summaries and evaluates goals against them.
package summary
import (
"time"
"ccp/internal/store"
)
type GoalResult struct {
store.Goal
ActualS int64 `json:"actual_s"`
Met bool `json:"met"`
}
type Daily struct {
Date string `json:"date"`
From time.Time `json:"from"`
To time.Time `json:"to"`
Totals []store.Total `json:"totals"`
ByKind map[string]int64 `json:"by_kind"`
Goals []GoalResult `json:"goals"`
}
// DayBounds returns the start and end of the calendar day containing t in loc.
// It uses AddDate rather than 24h so DST transitions are handled.
func DayBounds(t time.Time, loc *time.Location) (time.Time, time.Time) {
t = t.In(loc)
start := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, loc)
return start, start.AddDate(0, 0, 1)
}
// Build assembles a daily summary from per-label totals and goals.
func Build(date string, from, to time.Time, totals []store.Total, goals []store.Goal) Daily {
d := Daily{
Date: date,
From: from,
To: to,
Totals: totals,
ByKind: map[string]int64{},
Goals: Evaluate(totals, goals),
}
if d.Totals == nil {
d.Totals = []store.Total{}
}
for _, t := range totals {
d.ByKind[t.Kind] += t.Seconds
}
return d
}
// Evaluate checks each goal against the totals. A goal with an empty label
// counts every label of its kind.
func Evaluate(totals []store.Total, goals []store.Goal) []GoalResult {
out := make([]GoalResult, 0, len(goals))
for _, g := range goals {
var actual int64
for _, t := range totals {
if t.Kind == g.Kind && (g.Label == "" || t.Label == g.Label) {
actual += t.Seconds
}
}
met := actual >= g.TargetS
if g.Op == "<=" {
met = actual <= g.TargetS
}
out = append(out, GoalResult{Goal: g, ActualS: actual, Met: met})
}
return out
}