diff --git a/backend/app/routers/dashboard.py b/backend/app/routers/dashboard.py index 8898084..38bb338 100644 --- a/backend/app/routers/dashboard.py +++ b/backend/app/routers/dashboard.py @@ -15,7 +15,10 @@ "sessions": {"total": 600, "day": 78}, "timeline": { "interval_minutes": 30, - "buckets": [{"start": "2026-11-09T07:00:00", "total": 2, "mine": 0}, ...] # mine: user's confirmed items + "buckets": [{"start": "2026-11-09T07:00:00", "total": 2, "mine": 0, + "kinds": {"talks": 2, "keynotes": 0, "colocated": 0, "food": 0, "other": 0}}, ...], + # mine: user's confirmed items; kinds sum to total + "kind_totals": {"talks": 50, "keynotes": 0, "colocated": 23, "food": 3, "other": 2} # the day }, "tracks": [{"name": "Project Lightning Talks", "sessions": 51}, ...], # top 6 on the day "filling": [{"id": "1289760", "title": "...", "starts_at": "...", "room": "...", "going": 5}], @@ -69,6 +72,11 @@ # Salt Lake City hosts: the local university leads the alumni list (review rule), the rest follow by count. HOST_SCHOOL = "University of Utah" +# Session kinds folded into the five groups the timeline chart stacks, in stacking order. Food (`is_food` or a +# break) wins over the kind; anything not listed (registration, ...) is "other". +KIND_GROUPS = ("talks", "keynotes", "colocated", "food", "other") +TALK_KINDS = {"talk", "lightning", "tutorial", "contribfest", "poster", "showcase"} + TS_FORMAT = "%Y-%m-%dT%H:%M:%S" @@ -104,6 +112,9 @@ def _histogram(field: str, day: str) -> dict: } +FOOD_FILTER = {"filter": {"term": {"is_food": True}}} + + def sessions_body(day: str) -> dict: """Sessions: the week by day, then the day's timeline and tracks under a filter.""" return { @@ -115,7 +126,10 @@ def sessions_body(day: str) -> dict: "filter": {"term": {"day": day}}, "aggs": { "tracks": {"terms": {"field": "track", "size": TOP}}, - "timeline": _histogram("starts_at", day), + "timeline": { + **_histogram("starts_at", day), + "aggs": {"kinds": {"terms": {"field": "kind", "size": 30}, "aggs": {"food": FOOD_FILTER}}}, + }, }, }, }, @@ -298,6 +312,27 @@ def mine_per_bucket(starts: list[str], items: list[dict]) -> list[int]: return counts +def kind_group(kind: str) -> str: + """The chart group of a session kind that is not food.""" + if kind in TALK_KINDS: + return "talks" + if kind == "keynote": + return "keynotes" + if kind == "colocated": + return "colocated" + return "other" + + +def kinds_in_bucket(bucket: dict) -> dict[str, int]: + """Counts per chart group for one histogram bucket (kinds terms, each with its `is_food` count).""" + out = dict.fromkeys(KIND_GROUPS, 0) + for k in bucket.get("kinds", {}).get("buckets", []): + food = k["doc_count"] if k["key"] == "break" else k.get("food", {}).get("doc_count", 0) + out["food"] += food + out[kind_group(k["key"])] += k["doc_count"] - food + return out + + def shape_activity(day_agg: dict, searches: dict, now: datetime, is_today: bool) -> dict: buckets = [{"start": b["key_as_string"], "count": b["doc_count"]} for b in day_agg["timeline"]["buckets"]] if is_today: # the future has no activity yet: stop at the half hour that holds now, not at a row of zeros @@ -318,6 +353,8 @@ def shape(day: str, now: datetime, sessions: dict, people: dict, agenda: dict, a mine = [h["_source"] for h in a["mine"]["items"]["hits"]["hits"]] histogram = s["day"]["timeline"]["buckets"] per_bucket = mine_per_bucket([b["key_as_string"] for b in histogram], mine) + per_kind = [kinds_in_bucket(b) for b in histogram] + kind_totals = {g: sum(k[g] for k in per_kind) for g in KIND_GROUPS} kinds = {b["key"]: b["doc_count"] for b in p["kinds"]["buckets"]} att = p["attendees"] filling = [] @@ -341,9 +378,10 @@ def shape(day: str, now: datetime, sessions: dict, people: dict, agenda: dict, a "timeline": { "interval_minutes": INTERVAL_MINUTES, "buckets": [ - {"start": b["key_as_string"], "total": b["doc_count"], "mine": n} - for b, n in zip(histogram, per_bucket, strict=True) + {"start": b["key_as_string"], "total": b["doc_count"], "mine": n, "kinds": k} + for b, n, k in zip(histogram, per_bucket, per_kind, strict=True) ], + "kind_totals": kind_totals, }, "tracks": [{"name": b["key"], "sessions": b["doc_count"]} for b in s["day"]["tracks"]["buckets"]], "filling": filling, diff --git a/backend/tests/test_dashboard.py b/backend/tests/test_dashboard.py index de939f6..00aafc2 100644 --- a/backend/tests/test_dashboard.py +++ b/backend/tests/test_dashboard.py @@ -32,6 +32,9 @@ def test_sessions_body_scopes_the_day(): assert hist["min_doc_count"] == 0 assert hist["extended_bounds"] == {"min": "2026-11-09T07:00:00", "max": "2026-11-09T18:59:00"} assert hist["hard_bounds"] == {"min": "2026-11-09T07:00:00", "max": "2026-11-09T19:00:00"} + kinds = day["aggs"]["timeline"]["aggs"]["kinds"] + assert kinds["terms"]["field"] == "kind" + assert kinds["aggs"]["food"] == {"filter": {"term": {"is_food": True}}} def test_people_body_looks_at_attendees_and_counts_the_host_school(): @@ -121,6 +124,24 @@ def _hist(*pairs): return {"buckets": [{"key_as_string": k, "doc_count": n} for k, n in pairs]} +def _kinds(*triples): + """A `kinds` sub-aggregation: (kind, count, of which food).""" + return {"buckets": [{"key": k, "doc_count": n, "food": {"doc_count": f}} for k, n, f in triples]} + + +def _session_hist(): + buckets = [ + ("2026-11-09T07:00:00", 2, _kinds(("registration", 2, 0))), + ("2026-11-09T08:30:00", 0, _kinds()), + ( + "2026-11-09T09:00:00", + 9, + _kinds(("colocated", 5, 0), ("lightning", 2, 0), ("break", 1, 1), ("keynote", 1, 0)), + ), + ] + return {"buckets": [{"key_as_string": k, "doc_count": n, "kinds": ks} for k, n, ks in buckets]} + + SESSIONS = { "hits": {"total": {"value": 600, "relation": "eq"}}, "aggregations": { @@ -128,7 +149,7 @@ def _hist(*pairs): "day": { "doc_count": 78, "tracks": _terms(("Project Lightning Talks", 51)), - "timeline": _hist(("2026-11-09T07:00:00", 2), ("2026-11-09T08:30:00", 0), ("2026-11-09T09:00:00", 9)), + "timeline": _session_hist(), }, }, } @@ -193,6 +214,21 @@ def _hist(*pairs): } +def _groups(**counts): + return {"talks": 0, "keynotes": 0, "colocated": 0, "food": 0, "other": 0} | counts + + +def test_kinds_in_bucket_folds_kinds_into_groups_and_food_wins(): + bucket = { + "kinds": _kinds( + ("talk", 3, 0), ("tutorial", 1, 0), ("keynote", 1, 0), ("colocated", 4, 0), + ("break", 2, 2), ("session", 3, 1), ("registration", 1, 0), + ) + } # fmt: skip + assert dash.kinds_in_bucket(bucket) == _groups(talks=4, keynotes=1, colocated=4, food=3, other=3) + assert dash.kinds_in_bucket({}) == _groups() + + def test_shape_builds_the_payload(): out = dash.shape("2026-11-09", NOW, SESSIONS, PEOPLE, AGENDA, ACTIVITY) assert out["now"] == "2026-11-09T08:40:00" @@ -202,10 +238,16 @@ def test_shape_builds_the_payload(): assert out["timeline"] == { "interval_minutes": 30, "buckets": [ - {"start": "2026-11-09T07:00:00", "total": 2, "mine": 0}, - {"start": "2026-11-09T08:30:00", "total": 0, "mine": 0}, - {"start": "2026-11-09T09:00:00", "total": 9, "mine": 1}, + {"start": "2026-11-09T07:00:00", "total": 2, "mine": 0, "kinds": _groups(other=2)}, + {"start": "2026-11-09T08:30:00", "total": 0, "mine": 0, "kinds": _groups()}, + { + "start": "2026-11-09T09:00:00", + "total": 9, + "mine": 1, + "kinds": _groups(talks=2, keynotes=1, colocated=5, food=1), + }, ], + "kind_totals": _groups(talks=2, keynotes=1, colocated=5, food=1, other=2), } assert out["tracks"] == [{"name": "Project Lightning Talks", "sessions": 51}] assert out["filling"] == [ diff --git a/frontend/src/components/dashboard/TimelineChart.tsx b/frontend/src/components/dashboard/TimelineChart.tsx index eb0073b..5200cf0 100644 --- a/frontend/src/components/dashboard/TimelineChart.tsx +++ b/frontend/src/components/dashboard/TimelineChart.tsx @@ -1,6 +1,15 @@ import { useId, useState } from 'react' import { useWidth } from './useWidth.ts' -import { type DashboardData, type TimelineBucket, fmt, hhmm, hhmmFromMinutes, hourShort, minutesOf } from './types.ts' +import { + type DashboardData, + KIND_GROUPS, + type KindGroup, + type TimelineBucket, + fmt, + hhmm, + hhmmFromMinutes, + minutesOf, +} from './types.ts' const PLOT_H = 160 const TOP = 22 // room for the agenda dots and the now label @@ -24,19 +33,30 @@ function topRounded(x: number, y: number, w: number, h: number, r: number): stri return `M${x},${y + h}V${y + rr}Q${x},${y} ${x + rr},${y}H${x + w - rr}Q${x + w},${y} ${x + w},${y + rr}V${y + h}Z` } -const startText = (b: TimelineBucket) => - `${b.total === 1 ? '1 session starts' : `${fmt(b.total)} sessions start`} at ${hhmm(b.start)}` +/** Stacking order, bottom up, with the chart token each kind wears. */ +const KINDS: Record = { + talks: { label: 'Talks', color: 'var(--chart-1)' }, + keynotes: { label: 'Keynotes', color: 'var(--chart-2)' }, + colocated: { label: 'Co-located', color: 'var(--chart-3)' }, + food: { label: 'Breaks and food', color: 'var(--chart-4)' }, + other: { label: 'Other', color: 'var(--chart-5)' }, +} + +const endText = (b: TimelineBucket, interval: number) => hhmmFromMinutes(minutesOf(b.start) + interval) + +const startText = (b: TimelineBucket, interval: number) => + `${fmt(b.total)} starting ${hhmm(b.start)} to ${endText(b, interval)}` -/** Sessions starting per half hour: one colour, past half hours lighter, the user's agenda as dots, a now line. */ +/** Sessions starting per half hour, stacked by kind; past half hours lighter, the user's agenda as dots, a now line. */ export default function TimelineChart({ data }: { data: DashboardData }) { - const { buckets, interval_minutes: interval } = data.timeline + const { buckets, interval_minutes: interval, kind_totals: kindTotals } = data.timeline const [wrapRef, width] = useWidth() const [active, setActive] = useState(null) const titleId = useId() const descId = useId() const n = buckets.length - const peak = buckets.reduce((best, b) => (b.total > best.total ? b : best), buckets[0] ?? { start: '', total: 0, mine: 0 }) + const peak = buckets.reduce((best, b) => (b.total > best.total ? b : best), buckets[0] ?? { start: '', total: 0, mine: 0, kinds: kindTotals }) const dayTotal = buckets.reduce((sum, b) => sum + b.total, 0) const mineTotal = buckets.reduce((sum, b) => sum + b.mine, 0) @@ -59,9 +79,9 @@ export default function TimelineChart({ data }: { data: DashboardData }) { const nowX = xOfMinutes(nowMin) const isPast = (b: TimelineBucket) => data.is_today && (nowMin > last || minutesOf(b.start) + interval <= nowMin) - // Even hours inside the window: 8a 10a 12p 2p 4p 6p. + // Every second hour from the first half hour: 07:00, 09:00, 11:00 ... const hourTicks: number[] = [] - for (let m = Math.ceil(first / 120) * 120; m < last; m += 120) if (m > first) hourTicks.push(m) + for (let m = first; m < last; m += 120) hourTicks.push(m) const indexAt = (clientX: number, el: Element) => { const x = clientX - el.getBoundingClientRect().left - LEFT @@ -86,11 +106,23 @@ export default function TimelineChart({ data }: { data: DashboardData }) { const tipLeft = active === null ? 0 : Math.min(Math.max(LEFT + (active + 0.5) * band, 90), width - 90) const nowIndex = showNow ? Math.min(n - 1, Math.floor((nowMin - first) / interval)) : 0 const readout = activeBucket - ? `${startText(activeBucket)}${activeBucket.mine ? `, ${activeBucket.mine} on your agenda` : ''}` + ? `${startText(activeBucket, interval)}: ${KIND_GROUPS.filter((k) => activeBucket.kinds[k] > 0) + .map((k) => `${activeBucket.kinds[k]} ${KINDS[k].label}`) + .join(', ')}${activeBucket.mine ? `. ${activeBucket.mine} on your agenda` : ''}` : '' return (
+
    + {KIND_GROUPS.map((k) => ( +
  • + + {KINDS[k].label} {fmt(kindTotals[k])} +
  • + ))} +
{(showNow || mineTotal > 0) && (
    {mineTotal > 0 && ( @@ -157,15 +189,23 @@ export default function TimelineChart({ data }: { data: DashboardData }) { {buckets.map((b, i) => { const x = LEFT + i * band + (band - barW) / 2 const top = y(b.total) + const shown = KIND_GROUPS.filter((k) => b.kinds[k] > 0) + const topKind = shown[shown.length - 1] + let base = TOP + PLOT_H return ( - {b.total > 0 && ( - - )} + + {shown.map((k) => { + const h = (b.kinds[k] / yMax) * PLOT_H + const segTop = base - h + const d = + k === topKind + ? topRounded(x, segTop, barW, h, RADIUS) + : `M${x},${segTop}H${x + barW}V${base}H${x}Z` + base = segTop + return + })} + {b.mine > 0 && ( ( - - {hourShort(m)} + + {hhmmFromMinutes(m)} ))} @@ -203,9 +243,17 @@ export default function TimelineChart({ data }: { data: DashboardData }) { {activeBucket && (