Phase 6b/7b: per-child decoded periods, separate brief blocks, idempotent calendar (AUD-119)
- Parse each child's own "Today" day widget for the timetable (FR-16); drop the school-wide week calendar's lesson grid and clean the leaked routine rows. - Add the editable codes map (FR-17): subjects, rooms, teachers and period labels, seeded, an unknown code falls back to the raw code; `school codes` CLI. - Brief: Finn's block first, then Harry's, four sections always present (FR-9); periods decoded into plain English; the undated tail is one counted line (FR-18). - Calendar: write periods + work due + work overdue + major events, per child, on every pass. Identity is the stable per-item key, so a re-run never re-inserts (FR-8). morning-brief.sh now runs scan -> calendar push -> notify. - Day-widget labels are 12-hour: 1-6 read as PM, fixing afternoon periods. Proven live on .13: image 0.6.2-phase6b7b; both children's briefs decoded and separate; 35 events in calendar.school; runs 2 and 3 of the scan added nothing. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -15,12 +15,14 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.lab.audasmedia.com.au/sam/compass_teams_nhs/internal/apprise"
|
||||
"gitea.lab.audasmedia.com.au/sam/compass_teams_nhs/internal/config"
|
||||
"gitea.lab.audasmedia.com.au/sam/compass_teams_nhs/internal/dashboard"
|
||||
"gitea.lab.audasmedia.com.au/sam/compass_teams_nhs/internal/decode"
|
||||
"gitea.lab.audasmedia.com.au/sam/compass_teams_nhs/internal/store"
|
||||
)
|
||||
|
||||
@@ -119,7 +121,11 @@ func (s *Service) ChildrenText(ctx context.Context, child store.Child) (string,
|
||||
return "", false, fmt.Errorf("items for %s: %w", child.Name, err)
|
||||
}
|
||||
buckets := dashboard.Classify(items, s.Now(), s.Loc)
|
||||
text := dashboard.RenderWithLimits(child.Name, buckets, s.Loc, dashboard.MorningLimits)
|
||||
dec, err := s.decoder(ctx)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
text := dashboard.RenderBrief(child.Name, buckets, dec, s.Loc)
|
||||
|
||||
sc, err := s.Store.ScanSummaryForChild(ctx, child.ID)
|
||||
if err != nil {
|
||||
@@ -132,18 +138,32 @@ func (s *Service) ChildrenText(ctx context.Context, child store.Child) (string,
|
||||
return notice + "\n" + text, false, nil
|
||||
}
|
||||
|
||||
// decoder loads the editable codes map and returns the lesson-title decoder the
|
||||
// brief uses (FR-17). An unknown code renders raw, never blank.
|
||||
func (s *Service) decoder(ctx context.Context) (func(string) string, error) {
|
||||
codes, err := s.Store.Codes(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decode map: %w", err)
|
||||
}
|
||||
return func(title string) string { return decode.Period(title, codes) }, nil
|
||||
}
|
||||
|
||||
// CombinedText returns the single brief for Jo and Sam — both boys in one
|
||||
// message — and the children whose scan did not complete.
|
||||
func (s *Service) CombinedText(ctx context.Context, children []store.Child) (string, []string, error) {
|
||||
parts := make([]dashboard.Combined, 0, len(children))
|
||||
parts := make([]dashboard.CombinedBrief, 0, len(children))
|
||||
var failed []string
|
||||
var notices []string
|
||||
dec, err := s.decoder(ctx)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
for _, c := range children {
|
||||
items, err := s.Store.ItemsForChild(ctx, c.ID)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("items for %s: %w", c.Name, err)
|
||||
}
|
||||
parts = append(parts, dashboard.Combined{
|
||||
parts = append(parts, dashboard.CombinedBrief{
|
||||
Child: c.Name,
|
||||
Buckets: dashboard.Classify(items, s.Now(), s.Loc),
|
||||
})
|
||||
@@ -156,7 +176,7 @@ func (s *Service) CombinedText(ctx context.Context, children []store.Child) (str
|
||||
failed = append(failed, c.Name)
|
||||
}
|
||||
}
|
||||
text := dashboard.RenderCombinedWithLimits(parts, s.Loc, dashboard.MorningLimits)
|
||||
text := dashboard.RenderCombinedBrief(parts, dec, s.Loc)
|
||||
if len(notices) > 0 {
|
||||
text = strings.Join(notices, "\n") + "\n\n" + text
|
||||
}
|
||||
@@ -328,6 +348,8 @@ func (s *Service) plan(ctx context.Context) ([]planned, error) {
|
||||
if len(children) == 0 {
|
||||
return nil, fmt.Errorf("no children on file: nothing to brief")
|
||||
}
|
||||
// Finn's block first, then Harry's: the required order (FR-9).
|
||||
children = OrderChildren(children)
|
||||
|
||||
var out []planned
|
||||
for _, c := range children {
|
||||
@@ -379,6 +401,15 @@ func (s *Service) plan(ctx context.Context) ([]planned, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// OrderChildren returns the children in brief order: Finn's block first, then
|
||||
// Harry's (FR-9). The order is by name, which puts Finn before Harry; it is
|
||||
// shared by the send path and the dry-run build so both agree.
|
||||
func OrderChildren(children []store.Child) []store.Child {
|
||||
out := append([]store.Child(nil), children...)
|
||||
sort.SliceStable(out, func(i, j int) bool { return out[i].Name < out[j].Name })
|
||||
return out
|
||||
}
|
||||
|
||||
func combinedNames(children []store.Child) string {
|
||||
names := make([]string, 0, len(children))
|
||||
for _, c := range children {
|
||||
|
||||
Reference in New Issue
Block a user