Update the alert digest wording

This commit is contained in:
2026-06-16 21:09:17 -05:00
parent d321492995
commit 6532e8824a
11 changed files with 97 additions and 27 deletions

View File

@@ -65,6 +65,7 @@ type AlertOverlap struct {
Period timeutil.Period `json:"period"`
Overlap timeutil.Period `json:"overlap"`
Description string `json:"description,omitempty"`
Instruction string `json:"instruction,omitempty"`
}
type PrecipTiming struct {
@@ -463,6 +464,7 @@ func AlertOverlaps(alertRun *weatherdata.AlertRun, period timeutil.Period) []Ale
Period: alert.Period,
Overlap: intersect(alert.Period, period),
Description: alert.Description,
Instruction: alert.Instruction,
})
}
sort.SliceStable(overlaps, func(i int, j int) bool {
@@ -476,6 +478,7 @@ type parsedAlert struct {
Headline string
Severity string
Description string
Instruction string
Period timeutil.Period
}
@@ -488,7 +491,8 @@ func parseAlert(raw json.RawMessage) (parsedAlert, bool) {
Event: stringField(fields, "event"),
Headline: firstStringField(fields, "headline", "title"),
Severity: stringField(fields, "severity"),
Description: firstStringField(fields, "description", "instruction"),
Description: stringField(fields, "description"),
Instruction: stringField(fields, "instruction"),
}
start, startOK := firstTimeField(fields, "onset", "startsAt", "startTime", "effective", "sent")
end, endOK := firstTimeField(fields, "ends", "endsAt", "endTime", "expires")

View File

@@ -211,7 +211,7 @@ func TestAlertOverlap(t *testing.T) {
}
func TestAlertOverlapUsesOnsetAndEnds(t *testing.T) {
raw := json.RawMessage(`{"event":"Wind Advisory","headline":"Wind Advisory issued June 16 at 12:39PM CDT until June 17 at 8:00PM CDT by NWS St Louis MO","severity":"Moderate","effective":"2026-06-16T17:39:00Z","onset":"2026-06-17T18:00:00Z","ends":"2026-06-18T01:00:00Z","expires":"2026-06-17T08:45:00Z"}`)
raw := json.RawMessage(`{"event":"Wind Advisory","headline":"Wind Advisory issued June 16 at 12:39PM CDT until June 17 at 8:00PM CDT by NWS St Louis MO","severity":"Moderate","description":"Southwest winds 20 to 30 mph with gusts up to 45 mph expected.","instruction":"Secure outdoor objects.","effective":"2026-06-16T17:39:00Z","onset":"2026-06-17T18:00:00Z","ends":"2026-06-18T01:00:00Z","expires":"2026-06-17T08:45:00Z"}`)
alertRun := &weatherdata.AlertRun{Alerts: []json.RawMessage{raw}}
period := timeutil.Period{
Start: mustParse("2026-06-17T12:00:00-05:00"),
@@ -234,6 +234,12 @@ func TestAlertOverlapUsesOnsetAndEnds(t *testing.T) {
if overlaps[0].Overlap.End.Format(time.RFC3339) != "2026-06-18T01:00:00Z" {
t.Fatalf("overlap end = %s, want alert ends", overlaps[0].Overlap.End.Format(time.RFC3339))
}
if overlaps[0].Description != "Southwest winds 20 to 30 mph with gusts up to 45 mph expected." {
t.Fatalf("Description = %q, want preserved description", overlaps[0].Description)
}
if overlaps[0].Instruction != "Secure outdoor objects." {
t.Fatalf("Instruction = %q, want preserved instruction", overlaps[0].Instruction)
}
}
func TestAlertOverlapUsesOnsetAndEndsForLocalDateRelevance(t *testing.T) {