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:
160
cmd/school/codes.go
Normal file
160
cmd/school/codes.go
Normal file
@@ -0,0 +1,160 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"gitea.lab.audasmedia.com.au/sam/compass_teams_nhs/internal/config"
|
||||
"gitea.lab.audasmedia.com.au/sam/compass_teams_nhs/internal/store"
|
||||
)
|
||||
|
||||
// codesCommand is the `school codes` entry point: the editable decode map for
|
||||
// Compass periods (AGENTS.md §4 FR-17). An unknown code renders as the raw
|
||||
// code, so a missing entry is safe but unreadable; this is how Sam corrects it.
|
||||
func codesCommand(args []string) {
|
||||
if len(args) == 0 {
|
||||
usage("school codes list [--kind KIND] | set --kind KIND --code CODE --name NAME | delete --kind KIND --code CODE")
|
||||
}
|
||||
switch args[0] {
|
||||
case "list":
|
||||
codesList(args[1:])
|
||||
case "set":
|
||||
codesSet(args[1:])
|
||||
case "delete":
|
||||
codesDelete(args[1:])
|
||||
default:
|
||||
usage("school codes list | set | delete")
|
||||
}
|
||||
}
|
||||
|
||||
func openCodes(ctx context.Context) (*store.Store, error) {
|
||||
cfg, err := config.LoadDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
st, err := store.Open(cfg.DBPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := st.Migrate(ctx); err != nil {
|
||||
_ = st.Close()
|
||||
return nil, err
|
||||
}
|
||||
if err := st.SeedCodes(ctx); err != nil {
|
||||
_ = st.Close()
|
||||
return nil, err
|
||||
}
|
||||
return st, nil
|
||||
}
|
||||
|
||||
func codesList(args []string) {
|
||||
fs := flag.NewFlagSet("codes list", flag.ContinueOnError)
|
||||
var (
|
||||
kind string
|
||||
asJSON bool
|
||||
)
|
||||
fs.StringVar(&kind, "kind", "", "limit to subject, room, teacher or period")
|
||||
fs.BoolVar(&asJSON, "json", false, "print as JSON")
|
||||
_ = fs.Parse(args)
|
||||
|
||||
ctx := context.Background()
|
||||
st, err := openCodes(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "school codes:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer st.Close()
|
||||
|
||||
codes, err := st.ListCodes(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "school codes:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if kind != "" {
|
||||
filtered := codes[:0]
|
||||
for _, c := range codes {
|
||||
if c.Kind == kind {
|
||||
filtered = append(filtered, c)
|
||||
}
|
||||
}
|
||||
codes = filtered
|
||||
}
|
||||
if asJSON {
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
if err := enc.Encode(codes); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "school codes:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
tw := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
|
||||
fmt.Fprintln(tw, "KIND\tCODE\tREADS AS")
|
||||
for _, c := range codes {
|
||||
fmt.Fprintf(tw, "%s\t%s\t%s\n", c.Kind, c.Code, c.Name)
|
||||
}
|
||||
_ = tw.Flush()
|
||||
}
|
||||
|
||||
func codesSet(args []string) {
|
||||
fs := flag.NewFlagSet("codes set", flag.ContinueOnError)
|
||||
var kind, code, name string
|
||||
fs.StringVar(&kind, "kind", "", "subject, room, teacher or period")
|
||||
fs.StringVar(&code, "code", "", "the raw Compass code")
|
||||
fs.StringVar(&name, "name", "", "the plain-English name")
|
||||
_ = fs.Parse(args)
|
||||
|
||||
if kind == "" || code == "" || name == "" {
|
||||
fmt.Fprintln(os.Stderr, "school codes set: --kind, --code and --name are required")
|
||||
os.Exit(2)
|
||||
}
|
||||
ctx := context.Background()
|
||||
st, err := openCodes(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "school codes:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer st.Close()
|
||||
|
||||
c, err := st.SetCode(ctx, kind, code, name)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "school codes:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("%s %s reads as %q\n", c.Kind, c.Code, c.Name)
|
||||
}
|
||||
|
||||
func codesDelete(args []string) {
|
||||
fs := flag.NewFlagSet("codes delete", flag.ContinueOnError)
|
||||
var kind, code string
|
||||
fs.StringVar(&kind, "kind", "", "subject, room, teacher or period")
|
||||
fs.StringVar(&code, "code", "", "the raw Compass code")
|
||||
_ = fs.Parse(args)
|
||||
|
||||
if kind == "" || code == "" {
|
||||
fmt.Fprintln(os.Stderr, "school codes delete: --kind and --code are required")
|
||||
os.Exit(2)
|
||||
}
|
||||
ctx := context.Background()
|
||||
st, err := openCodes(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "school codes:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer st.Close()
|
||||
|
||||
ok, err := st.DeleteCode(ctx, kind, code)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "school codes:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !ok {
|
||||
fmt.Printf("%s %s was not mapped\n", kind, code)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%s %s now renders as the raw code\n", kind, code)
|
||||
}
|
||||
Reference in New Issue
Block a user