Skip to content
Draft
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
115 changes: 115 additions & 0 deletions src/components/quest/backlog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Quests written and finished on moq-dev/moq, summed day by day: the gap between the lines is the
// open tree, which stays bounded because a finished quest's file is deleted.
import { createSignal, For, Show } from "solid-js";
import { Figure } from "../rind/chart";
import { count, date, days, span } from "./data";
import "./quest.css";
import { scrub } from "./scrub";

const H = 200;

// Running totals of quests written and finished, and the open tree between them.
const RUNS = (() => {
let added = 0;
let deleted = 0;
return days.map((d) => {
added += d.quests.added;
deleted += d.quests.deleted;
return { date: d.date, added, deleted, open: added - deleted };
});
})();
const MAX = RUNS[RUNS.length - 1].added;
const TICKS = days.flatMap((d, i) => (d.date.endsWith("-01") ? [{ i, label: date(d.date) }] : []));

const x = (i: number) => (100 * (i + 0.5)) / RUNS.length;
const y = (n: number) => H - (n / MAX) * H;
const path = (key: "added" | "deleted") => RUNS.map((r, i) => `${i ? "L" : "M"}${x(i)},${y(r[key])}`).join("");
// The open tree as the area between the two lines.
const GAP = `${path("added")}${RUNS.map((_, i) => `L${x(RUNS.length - 1 - i)},${y(RUNS[RUNS.length - 1 - i].deleted)}`).join("")}Z`;

export default function Backlog() {
const [at, setAt] = createSignal<number>();
const last = RUNS[RUNS.length - 1];
const r = () => RUNS[at() ?? RUNS.length - 1];

return (
<Figure
class="quest-fig"
kicker={`moq-dev/moq's quest tree · ${span}`}
number={count(last.deleted)}
headline={
<>
quests finished
<br />
and deleted
</>
}
label={`Quests written and finished on moq-dev/moq, ${span}: ${count(last.added)} written, ${count(last.deleted)} finished, ${count(last.open)} open.`}
table={{
head: ["Day", "Written, so far", "Finished, so far", "Open"],
rows: RUNS.map((r) => [r.date, r.added, r.deleted, r.open]),
}}
source={
<>
Markdown files added and deleted under <code>quest/</code> in moq-dev/moq's main branch history; a moved quest
is neither. Open counts only quests written since quests started.
</>
}
>
<div class="key">
<span>
<i style={{ background: "var(--took)" }} />
written · <strong>{count(r().added)}</strong>
</span>
<span>
<i style={{ background: "var(--own)" }} />
finished · <strong>{count(r().deleted)}</strong>
</span>
<span>
<i style={{ background: "var(--line)" }} />
open · <strong>{count(r().open)}</strong>
</span>
<Show when={at() !== undefined}>
<span>{date(r().date)}</span>
</Show>
</div>
<div class="mt-4" {...scrub(at, setAt, "Pick a day to see the quest tree then")}>
<svg viewBox={`0 0 100 ${H}`} preserveAspectRatio="none" style={{ height: `${H}px` }} aria-hidden="true">
<For each={[0.25, 0.5, 0.75, 1]}>
{(f) => (
<line class="grid" x1="0" x2="100" y1={H - f * H} y2={H - f * H} vector-effect="non-scaling-stroke" />
)}
</For>
<path d={GAP} fill="var(--line)" />
<path
d={path("added")}
fill="none"
stroke="var(--took)"
stroke-width="2"
vector-effect="non-scaling-stroke"
/>
<path
d={path("deleted")}
fill="none"
stroke="var(--own)"
stroke-width="2"
vector-effect="non-scaling-stroke"
/>
<Show when={at() !== undefined}>
{/* biome-ignore lint/style/noNonNullAssertion: shown only when set */}
<line class="cursor" x1={x(at()!)} x2={x(at()!)} y1="0" y2={H} vector-effect="non-scaling-stroke" />
</Show>
</svg>
<div class="axis relative mt-1 h-4">
<For each={TICKS}>
{(t) => (
<span class="absolute" style={{ left: `${(100 * t.i) / RUNS.length}%`, "font-family": "var(--mono)" }}>
{t.label}
</span>
)}
</For>
</div>
</div>
</Figure>
);
}
34 changes: 34 additions & 0 deletions src/components/quest/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// The quest post's daily activity, and how its figures name days and counts.
import json from "./data/activity.json";

export interface Day {
date: string;
merged: Record<string, number>;
decisions: Record<string, number>;
messages: number;
sessions: number;
costUsd: number;
quests: { added: number; deleted: number };
reviews: Record<string, number>;
}

export const source = json.source;
export const days = json.days as unknown as Day[];

const sum = (xs: number[]) => xs.reduce((a, x) => a + x, 0);
export const total = (fn: (d: Day) => number) => sum(days.map(fn));
export const merged = (d: Day) => sum(Object.values(d.merged));
export const decided = (d: Day) => sum(Object.values(d.decisions));

// How a person answered an agent's question, in the order the figures stack them.
export const ANSWERS = [
{ key: "recommended", label: "took the recommendation", color: "var(--took)" },
{ key: "other", label: "picked another option", color: "var(--other)" },
{ key: "own", label: "typed my own answer", color: "var(--own)" },
{ key: "unranked", label: "no recommendation given", color: "var(--plain)" },
] as const;

export const count = (n: number) => n.toLocaleString("en-US");
export const date = (iso: string) =>
new Date(`${iso}T12:00:00Z`).toLocaleDateString("en-US", { month: "short", day: "numeric", timeZone: "UTC" });
export const span = `${date(source.since)} to ${date(source.until)}`;
Loading
Loading