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
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Read `npm run delivery -- report` before delivery work. Preserve an active owner

When completing a new lesson, register its path, title and summary in site/src/data/chapters.ts. Home chapter cards and the Learn index share this list; keep it in reading order and include only complete lessons present in the build. Verify both surfaces and base-path links before handoff.

When a change spans adjacent V3 chapters, the delivery owner uses the [Editor role](agents/EDITOR.md) to read and edit the revised chapters in sequence before the final preview. Move examples and trim repeated setup where this helps the reader understand the next engineering decision.

## V2 transition (Stage 0–1 draft)

For the proposed future learning design, read project/TUTORIAL-SPEC.md, project/CURRICULUM-MAP.md, project/ENGINEERING-WORKFLOW.md, project/DEMONSTRATOR-LEARNING-PLAN.md, project/EDITORIAL-GUIDE.md and project/INFORMATION-ARCHITECTURE.md, then the relevant chapters/ brief. See docs/v2/ADOPTION-STATUS.md for scope, conflicts and verification. These are proposed educational targets, not evidence of implemented capabilities or authorization for later stages.
Expand Down
12 changes: 10 additions & 2 deletions agents/EDITOR.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Editor — v2 role contract
# Editor

## Purpose

Write American English engineer-to-engineer. Lead with concrete decisions. Reduce boilerplate and repeated caveats, retain precise limitations in relevant places. Ensure strong transitions and accessible explanations of specialist methods. Check that every paragraph advances learning and AI appears as an operational rather than late theoretical topic.

## Editing adjacent V3 chapters

Use the [current curriculum map](../project/CURRICULUM-MAP.md) and [revised manuscript index](../project/v3/manuscripts/revised/INDEX.md) to locate the active chapters in reading order. Follow the [editorial guide](../project/EDITORIAL-GUIDE.md) for voice and chapter composition.

Before the final preview, read the affected chapters together. Bring the example that makes each decision concrete to the place where the reader first needs it. You may move or shorten passages across the chapters in scope. Read each closing paragraph alongside the next opening. Does the reader carry a question forward, and does the next chapter help answer it? Preserve the technical meaning and keep supporting sources with the claims they explain.

## Shared instructions
Read `AGENTS.md`, v2 tutorial/curriculum/workflow specs, relevant chapter briefs, existing repository implementation and migration plan. Differentiate historical V0 truth from future aspirations. Implement only an explicitly approved scope. Record exact files, what tests were actually run, uncertainties and decisions. Do not fabricate execution, approvals or deployed features. Defer shared-file merges to reviewer/integrator.

Read the [contributor guidance](../AGENTS.md), the relevant chapter briefs and the existing implementation. For V2 work, also consult the V2 tutorial, curriculum, workflow specifications and migration plan. Differentiate historical V0 truth from future aspirations. Implement only an explicitly approved scope. Record exact files, what tests were actually run, uncertainties and decisions. Do not fabricate execution, approvals or deployed features. Defer shared-file merges to reviewer/integrator.
42 changes: 32 additions & 10 deletions site/src/components/learning/QueueExperiment.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
---
import inputs from '../../../../project/v3/case-study/model-inputs-v1.json';
import observations from '../../../../project/v3/case-study/data-quality-v1.json';
import { moveArrival, runQueue } from '../../../../models/intersection/queue.mjs';
import QueueTimeline from './QueueTimeline.astro';
import { makeTimeline, type Direction } from './queue-timeline';

const observation = observations.scenario_edit_observation;
const originalResult = observations.valid_records.find(result => result.id === observation.baseline_result)!;
const worked = inputs.scenarios.find(scenario => scenario.id === originalResult.case)!;
const move = observation.arrival_move;
const group = move.group as Direction;
const original = runQueue(inputs, worked.arrivals);
const edited = runQueue(inputs, moveArrival(worked.arrivals, group, move.from_slot, move.to_slot));
const workedView = makeTimeline(worked.id, group, original, { rows: edited, from: move.from_slot, to: move.to_slot });
---
<section class="queue-experiment" aria-labelledby="arrival-experiment">
<h2 id="arrival-experiment">Move one arrival</h2>
Expand All @@ -8,14 +21,15 @@ import inputs from '../../../../project/v3/case-study/model-inputs-v1.json';
<form>
<div class="queue-fields">
<label>Starting scenario
<select name="scenario">{inputs.scenarios.map(s => <option value={s.id} selected={s.id === 'B'}>{s.id} · {s.name}</option>)}</select>
<select name="scenario">{inputs.scenarios.map(s => <option value={s.id} selected={s.id === worked.id}>{s.id} · {s.name}</option>)}</select>
</label>
<label>Arrival to move <select name="origin" required></select></label>
<label>New arrival slot <select name="destination" required></select></label>
</div>
<div class="learning-actions"><button type="submit">Run comparison</button><button type="reset">Restore baseline</button></div>
</form>
<p class="queue-result" role="status" aria-atomic="true" tabindex="-1"></p>
<QueueTimeline id="queue-timeline" view={makeTimeline(worked.id, group, original)} />
<div class="queue-table-wrap" role="region" aria-label="Queue comparison table" tabindex="0">
<table>
<caption>Vehicles waiting after each slot. NS is north–south and EW is east–west.</caption>
Expand All @@ -28,16 +42,19 @@ import inputs from '../../../../project/v3/case-study/model-inputs-v1.json';
</table>
</div>
</div>
<noscript><p>Enable JavaScript to move an arrival. The tables below show both original scenarios.</p></noscript>
<noscript>
<p>Enable JavaScript to move an arrival. The tables below show both original scenarios.</p>
<details>
<summary>See the worked comparison for scenario {worked.id}</summary>
<QueueTimeline view={workedView} />
</details>
</noscript>
</section>
<script>
import inputs from '../../../../project/v3/case-study/model-inputs-v1.json';
import { moveArrival, runQueue } from '../../../../models/intersection/queue.mjs';
import { directionNames, makeTimeline, phaseLabels, updateTimeline, type Comparison, type Direction } from './queue-timeline';
const directions = ['NS', 'EW'] as const;
const names = { NS: 'North–south', EW: 'East–west' };
const phaseLabels: Record<string, string> = {
NS_GREEN: 'NS green', EW_GREEN: 'EW green', NS_AMBER: 'NS amber', EW_AMBER: 'EW amber', ALL_RED: 'All red',
};

for (const controls of document.querySelectorAll<HTMLElement>('.queue-controls')) {
const form = controls.querySelector('form')!;
Expand All @@ -46,10 +63,14 @@ import inputs from '../../../../project/v3/case-study/model-inputs-v1.json';
const destination = form.querySelector<HTMLSelectElement>('[name=destination]')!;
const body = controls.querySelector('tbody')!;
const result = controls.querySelector<HTMLElement>('.queue-result')!;
const timeline = controls.querySelector<HTMLElement>('.queue-timeline')!;
function scenario() { return inputs.scenarios.find(item => item.id === scenarioSelect.value)!; }

function draw(edited?: ReturnType<typeof runQueue>) {
function draw(edit?: Comparison) {
const baseline = runQueue(inputs, scenario().arrivals);
const edited = edit?.rows;
const group = origin.value.split('/')[0] as Direction;
updateTimeline(timeline, makeTimeline(scenario().id, group, baseline, edit));
const rows = baseline.map((row, index) => {
const tr = document.createElement('tr');
const slot = document.createElement('th');
Expand Down Expand Up @@ -83,7 +104,7 @@ import inputs from '../../../../project/v3/case-study/model-inputs-v1.json';

function restore() {
const options = directions.flatMap(group => scenario().arrivals.flatMap((arrivals, index) =>
arrivals[group] ? [new Option(`${names[group]} arrival in slot ${index + 1}`, `${group}/${index + 1}`)] : []));
arrivals[group] ? [new Option(`${directionNames[group]} arrival in slot ${index + 1}`, `${group}/${index + 1}`)] : []));
origin.replaceChildren(...options);
updateSlots();
}
Expand All @@ -98,8 +119,9 @@ import inputs from '../../../../project/v3/case-study/model-inputs-v1.json';
form.addEventListener('submit', event => {
event.preventDefault();
const [group, from] = origin.value.split('/');
const arrivals = moveArrival(scenario().arrivals, group as 'NS' | 'EW', Number(from), Number(destination.value));
draw(runQueue(inputs, arrivals));
const fromSlot = Number(from), toSlot = Number(destination.value);
const arrivals = moveArrival(scenario().arrivals, group as Direction, fromSlot, toSlot);
draw({ rows: runQueue(inputs, arrivals), from: fromSlot, to: toSlot });
result.focus();
});
restore();
Expand Down
67 changes: 67 additions & 0 deletions site/src/components/learning/QueueTimeline.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
import type { Timeline } from './queue-timeline';
interface Props { view: Timeline; id?: string }
const { view, id } = Astro.props;
---
<figure class="queue-timeline" id={id} style={`--queue-scale:${view.scale}; --slots:${view.lanes[0].cells.length}`}>
<h3>{view.title}</h3>
<div class="timeline-key" aria-hidden="true">
<span><b class="arrival-key">↓</b> Arrivals</span>
<span><i class="bar-key"></i> Waiting after service</span>
</div>
<div class="timeline-axis" aria-hidden="true">
<span class="axis-label">Slot</span>
<div class="timeline-columns">
{view.lanes[0].cells.map(cell => <span class="timeline-tick">{cell.slot}</span>)}
</div>
<div class="timeline-signals">
{view.greenBands.map(band => <span style={`grid-column:${band.start} / span ${band.length}`}>Green</span>)}
</div>
</div>
{view.lanes.map(lane => <div class="timeline-lane" hidden={!lane.visible}>
<div class="lane-label" aria-hidden="true">{lane.label}</div>
<ol class="timeline-columns" role="list" aria-label={`${lane.label} timeline`}>
{lane.cells.map(cell => <li style={`--waiting:${cell.waiting}`} data-first-difference={cell.firstDifference || undefined}>
<span class="timeline-description">{cell.description}</span>
<span class="timeline-arrival" aria-hidden="true">{cell.arrivalMark}</span>
<span class="timeline-track" aria-hidden="true"><span class="timeline-bar"></span></span>
<span class="timeline-count" aria-hidden="true">{cell.waiting}</span>
</li>)}
</ol>
</div>)}
<figcaption>{view.caption}</figcaption>
</figure>

<style>
.queue-timeline {
margin: 1.5rem 0;
padding: 1.2rem 0;
border-block: 1px solid var(--rule);
color: var(--text);
font-variant-numeric: tabular-nums;
}
.queue-timeline h3 { margin: 0; font-size: 1.1rem; }
.timeline-key { display: flex; flex-wrap: wrap; gap: .25rem 1.2rem; margin: .4rem 0 1rem; color: var(--muted); font-size: .85rem; }
.timeline-key span { display: inline-flex; align-items: center; gap: .35rem; }
.arrival-key { color: var(--text); font-size: 1.1em; }
.bar-key { width: .75rem; height: .55rem; background: var(--teal); }
.timeline-columns { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); margin: 0; padding: 0; list-style: none; text-align: center; }
.axis-label, .lane-label { display: block; margin: 0 0 .25rem; font-size: .85rem; font-weight: 600; }
.timeline-tick { font-size: .85rem; }
.timeline-signals { display: grid; grid-template-columns: repeat(var(--slots), minmax(0, 1fr)); min-height: 1.3rem; text-align: center; }
.timeline-signals > :global(span) { border-block-end: 2px solid currentColor; color: var(--teal); background: var(--bg); font-size: .8rem; font-weight: 600; line-height: 1.3rem; }
.timeline-lane { margin-top: .8rem; }
.timeline-columns li { position: relative; min-width: 0; margin: 0; border-inline-start: 1px solid var(--rule); }
.timeline-columns li:last-child { border-inline-end: 1px solid var(--rule); }
.timeline-columns li[data-first-difference] { outline: 1px dashed var(--text); outline-offset: -1px; }
.timeline-arrival, .timeline-count { display: block; line-height: 1.35rem; font-size: .85rem; }
.timeline-arrival { min-height: 1.35rem; font-weight: 600; }
.timeline-track { height: 2.15rem; display: flex; align-items: end; justify-content: center; border-bottom: 1px solid var(--muted); }
.timeline-bar { width: 55%; max-width: 2rem; height: calc(100% * var(--waiting) / var(--queue-scale)); background: var(--teal); }
.timeline-count { color: var(--muted); }
.queue-timeline figcaption { margin: 1rem 0 0; font-size: .9rem; color: var(--muted); line-height: 1.5; }
.timeline-description { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (forced-colors: active) {
.bar-key, .timeline-bar { background: CanvasText; forced-color-adjust: none; }
}
</style>
39 changes: 39 additions & 0 deletions site/src/components/learning/queue-timeline.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { describe, expect, it } from 'vitest';
import inputs from '../../../../project/v3/case-study/model-inputs-v1.json';
import { moveArrival, runQueue } from '../../../../models/intersection/queue.mjs';
import { makeTimeline } from './queue-timeline';

const staggered = inputs.scenarios.find(scenario => scenario.id === 'A')!.arrivals;
const clustered = inputs.scenarios.find(scenario => scenario.id === 'B')!.arrivals;

describe('Chapter 5 queue timeline', () => {
it('distinguishes the extra departure in slot 2 from the first queue difference in slot 3', () => {
const original = runQueue(inputs, clustered);
const rows = runQueue(inputs, moveArrival(clustered, 'NS', 3, 2));
const view = makeTimeline('B', 'NS', original, { rows, from: 3, to: 2 });
const [before, after] = view.lanes;
expect(view.greenBands).toEqual([{ start: 1, length: 2 }]);
expect(after.cells[1]).toMatchObject({ arrivalMark: '↓1', waiting: 0, firstDifference: false });
expect(before.cells[2].waiting).toBe(2);
expect(after.cells.filter(cell => cell.firstDifference).map(cell => cell.slot)).toEqual([3]);
expect(after.cells[2].waiting).toBe(1);
expect(view.caption).toContain('leaves on green in slot 2');
expect(view.caption).toContain('after slot 3, with 2 waiting in the original and 1 in the edit');
});

it('uses the selected direction and clears the comparison for an unedited baseline', () => {
const view = makeTimeline('B', 'EW', runQueue(inputs, clustered));
expect(view.title).toContain('East–west');
expect(view.lanes.map(lane => lane.visible)).toEqual([true, false]);
expect(view.greenBands).toEqual([{ start: 5, length: 2 }]);
expect(view.lanes[0].cells[0]).toMatchObject({ arrivalMark: '↓2', waiting: 2 });
expect(view.lanes[0].cells.some(cell => cell.firstDifference)).toBe(false);
});

it('leaves all slots unmarked when two different arrival patterns yield the same queues', () => {
const rows = runQueue(inputs, moveArrival(staggered, 'NS', 1, 2));
const view = makeTimeline('A', 'NS', runQueue(inputs, staggered), { rows, from: 1, to: 2 });
expect(view.lanes[1].cells.some(cell => cell.firstDifference)).toBe(false);
expect(view.caption).toContain('same count after service in every slot');
});
});
83 changes: 83 additions & 0 deletions site/src/components/learning/queue-timeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type { runQueue } from '../../../../models/intersection/queue.mjs';

type Trace = ReturnType<typeof runQueue>;
export type Direction = keyof Trace[number]['queue'];
export type Comparison = { rows: Trace; from: number; to: number };

export const directionNames = { NS: 'North–south', EW: 'East–west' };
export const phaseLabels: Record<string, string> = {
NS_GREEN: 'NS green', EW_GREEN: 'EW green', NS_AMBER: 'NS amber', EW_AMBER: 'EW amber', ALL_RED: 'All red',
};

export function makeTimeline(scenario: string, group: Direction, original: Trace, edit?: Comparison) {
const firstDifference = edit?.rows.findIndex((row, i) => row.queue[group] !== original[i].queue[group]) ?? -1;
let caption = 'Each bar counts the vehicles still waiting after arrivals and service in that slot.';
if (edit) {
const at = edit.to - 1;
const move = edit.rows[at].departures[group] > original[at].departures[group]
? `The moved vehicle arrives and leaves on green in slot ${edit.to}.`
: `One arrival moved from slot ${edit.from} to slot ${edit.to}.`;
const difference = firstDifference < 0
? 'Both queues have the same count after service in every slot.'
: `The queues first differ after slot ${original[firstDifference].slot}, with ${original[firstDifference].queue[group]} waiting in the original and ${edit.rows[firstDifference].queue[group]} in the edit.`;
caption = `${move} ${difference}`;
}

function cells(rows: Trace, highlight = -1) {
return rows.map((row, i) => {
const arriving = row.arrival[group], waiting = row.queue[group];
return {
slot: row.slot,
arrivalMark: arriving ? `↓${arriving}` : '', waiting, firstDifference: i === highlight,
description: `Slot ${row.slot}, ${phaseLabels[row.phase]}. ${arriving} arriving, ${row.departures[group]} leaving, ${waiting} waiting after service.`,
};
});
}

const greenBands: { start: number; length: number }[] = [];
for (const row of original) {
if (row.phase !== `${group}_GREEN`) continue;
const previous = greenBands.at(-1);
if (previous && previous.start + previous.length === row.slot) previous.length++;
else greenBands.push({ start: row.slot, length: 1 });
}

return {
title: `${directionNames[group]} queue · Scenario\u00a0${scenario}`,
// Use the same scale for both lanes and for every move within this scenario.
scale: Math.max(1, original.reduce((sum, row) => sum + row.arrival[group], 0)),
caption, greenBands,
lanes: [
{ label: 'Original', visible: true, cells: cells(original) },
{ label: 'Edited', visible: Boolean(edit), cells: cells(edit?.rows ?? original, firstDifference) },
],
};
}

export type Timeline = ReturnType<typeof makeTimeline>;

export function updateTimeline(figure: HTMLElement, view: Timeline) {
figure.querySelector('h3')!.textContent = view.title;
figure.querySelector('figcaption')!.textContent = view.caption;
figure.style.setProperty('--queue-scale', String(view.scale));
const signals = figure.querySelector('.timeline-signals')!;
signals.replaceChildren(...view.greenBands.map(band => {
const signal = document.createElement('span');
signal.textContent = 'Green';
signal.style.gridColumn = `${band.start} / span ${band.length}`;
return signal;
}));
const lanes = figure.querySelectorAll<HTMLElement>('.timeline-lane');
for (const [i, lane] of view.lanes.entries()) {
lanes[i].hidden = !lane.visible;
const slots = lanes[i].querySelectorAll('li');
for (const [j, cell] of lane.cells.entries()) {
const slot = slots[j];
slot.toggleAttribute('data-first-difference', cell.firstDifference);
slot.style.setProperty('--waiting', String(cell.waiting));
slot.querySelector('.timeline-description')!.textContent = cell.description;
slot.querySelector('.timeline-arrival')!.textContent = cell.arrivalMark;
slot.querySelector('.timeline-count')!.textContent = String(cell.waiting);
}
}
}
Loading