Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions backend/app/routers/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}],
Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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 {
Expand All @@ -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}}},
},
},
},
},
Expand Down Expand Up @@ -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
Expand All @@ -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 = []
Expand All @@ -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,
Expand Down
50 changes: 46 additions & 4 deletions backend/tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -121,14 +124,32 @@ 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": {
"days": _terms(("2026-11-09", 78), ("2026-11-10", 194)),
"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(),
},
},
}
Expand Down Expand Up @@ -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"
Expand All @@ -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"] == [
Expand Down
96 changes: 76 additions & 20 deletions frontend/src/components/dashboard/TimelineChart.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<KindGroup, { label: string; color: string }> = {
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<HTMLDivElement>()
const [active, setActive] = useState<number | null>(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)

Expand All @@ -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
Expand All @@ -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 (
<div className="dash-timeline">
<ul className="dash-legend" aria-label="Session kinds">
{KIND_GROUPS.map((k) => (
<li key={k} className={kindTotals[k] === 0 ? 'is-zero' : undefined}>
<svg width="10" height="10" aria-hidden="true">
<rect width="10" height="10" rx="2" fill={KINDS[k].color} />
</svg>
{KINDS[k].label} <span className="dash-legend-n">{fmt(kindTotals[k])}</span>
</li>
))}
</ul>
{(showNow || mineTotal > 0) && (
<ul className="dash-legend" aria-label="Chart marks">
{mineTotal > 0 && (
Expand Down Expand Up @@ -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 (
<g key={b.start}>
{b.total > 0 && (
<path
d={topRounded(x, top, barW, TOP + PLOT_H - top, RADIUS)}
fill="var(--accent)"
fillOpacity={isPast(b) ? 0.38 : 1}
/>
)}
<g opacity={isPast(b) ? 0.45 : 1}>
{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 <path key={k} d={d} fill={KINDS[k].color} stroke="var(--panel)" strokeWidth={1} />
})}
</g>
{b.mine > 0 && (
<circle
cx={x + barW / 2}
Expand All @@ -181,8 +221,8 @@ export default function TimelineChart({ data }: { data: DashboardData }) {
})}

{hourTicks.map((m) => (
<text key={m} x={xOfMinutes(m)} y={TOP + PLOT_H + 16} textAnchor="middle" className="dash-tick">
{hourShort(m)}
<text key={m} x={xOfMinutes(m)} y={TOP + PLOT_H + 16} textAnchor="middle" className="dash-tick dash-tick-time">
{hhmmFromMinutes(m)}
</text>
))}

Expand All @@ -203,9 +243,17 @@ export default function TimelineChart({ data }: { data: DashboardData }) {
{activeBucket && (
<div className="dash-tip" style={{ left: tipLeft }} aria-hidden="true">
<p>
<strong>{fmt(activeBucket.total)}</strong> {activeBucket.total === 1 ? 'session starts' : 'sessions start'}{' '}
at {hhmm(activeBucket.start)}
<strong>{fmt(activeBucket.total)}</strong> starting {hhmm(activeBucket.start)} to{' '}
{endText(activeBucket, interval)}
</p>
{KIND_GROUPS.filter((k) => activeBucket.kinds[k] > 0).map((k) => (
<p key={k} className="dash-tip-row">
<svg width="8" height="8" aria-hidden="true">
<rect width="8" height="8" rx="2" fill={KINDS[k].color} />
</svg>
{activeBucket.kinds[k]} {KINDS[k].label}
</p>
))}
{activeBucket.mine > 0 && (
<p className="dash-tip-row">
<svg width="8" height="8" aria-hidden="true">
Expand All @@ -229,6 +277,11 @@ export default function TimelineChart({ data }: { data: DashboardData }) {
<tr>
<th scope="col">Half hour</th>
<th scope="col">Sessions starting</th>
{KIND_GROUPS.map((k) => (
<th key={k} scope="col">
{KINDS[k].label}
</th>
))}
<th scope="col">On your agenda</th>
</tr>
</thead>
Expand All @@ -237,6 +290,9 @@ export default function TimelineChart({ data }: { data: DashboardData }) {
<tr key={b.start}>
<th scope="row">{hhmm(b.start)}</th>
<td>{b.total}</td>
{KIND_GROUPS.map((k) => (
<td key={k}>{b.kinds[k]}</td>
))}
<td>{b.mine}</td>
</tr>
))}
Expand Down
13 changes: 5 additions & 8 deletions frontend/src/components/dashboard/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** Shape of GET /api/dashboard (see backend/app/routers/dashboard.py). */

export type TimelineBucket = { start: string; total: number; mine: number }
export const KIND_GROUPS = ['talks', 'keynotes', 'colocated', 'food', 'other'] as const
export type KindGroup = (typeof KIND_GROUPS)[number]
export type KindCounts = Record<KindGroup, number>
export type TimelineBucket = { start: string; total: number; mine: number; kinds: KindCounts }
export type Named = { name: string; count: number; pinned?: boolean }

export type DashboardData = {
Expand All @@ -9,7 +12,7 @@ export type DashboardData = {
is_today: boolean
days: { day: string; sessions: number }[]
sessions: { total: number; day: number }
timeline: { interval_minutes: number; buckets: TimelineBucket[] }
timeline: { interval_minutes: number; buckets: TimelineBucket[]; kind_totals: KindCounts }
tracks: { name: string; sessions: number }[]
filling: { id: string; title: string; starts_at: string; room: string; going: number }[]
my_day: { hours: number; goal_hours: number; sessions: number; meetings: number; requests: number }
Expand Down Expand Up @@ -40,12 +43,6 @@ export const minutesOf = (iso: string) => Number(iso.slice(11, 13)) * 60 + Numbe
export const hhmmFromMinutes = (m: number) =>
`${String(Math.floor(m / 60)).padStart(2, '0')}:${String(m % 60).padStart(2, '0')}`

/** 480 -> "8a", 720 -> "12p": compact hour labels for a time axis. */
export function hourShort(m: number): string {
const h = Math.floor(m / 60)
return `${h % 12 === 0 ? 12 : h % 12}${h < 12 ? 'a' : 'p'}`
}

/** "2026-11-09" -> "Mon 9" or "Monday, Nov 9". Noon avoids any date shift from the browser's own time zone. */
export function dayLabel(day: string, style: 'short' | 'long' = 'short'): string {
const d = new Date(`${day}T12:00:00`)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default function Dashboard() {
<BarChart3 size={16} aria-hidden="true" />
{data.is_today ? 'Today at a glance' : `${dayLabel(data.day)} at a glance`}
</h2>
<p className="dash-card-sub">Sessions starting each half hour.</p>
<p className="dash-card-sub">Sessions starting each half hour, by kind.</p>
<TimelineChart data={data} />
</article>

Expand Down
Loading
Loading