sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / docs / archive / drakestapleton.com-old / src / components / PracticeTimeline.tsx
| 1 | import { useState } from "react"; |
| 2 | import { PRACTICE_SNAPSHOT, PRACTICE_TIMELINE } from "../data/practice"; |
| 3 | import { HisWords } from "./VoiceMark"; |
| 4 | |
| 5 | type TimelineMetric = "linesAdded" | "commits" | "conversationTokens"; |
| 6 | |
| 7 | const CHARTS: Record< |
| 8 | TimelineMetric, |
| 9 | { |
| 10 | button: string; |
| 11 | title: string; |
| 12 | subtitle: string; |
| 13 | totalLabel: string; |
| 14 | source: string; |
| 15 | color: string; |
| 16 | } |
| 17 | > = { |
| 18 | linesAdded: { |
| 19 | button: "Lines added", |
| 20 | title: "Weekly source lines added", |
| 21 | subtitle: "Text additions across 94 SHA-deduped project trees I own", |
| 22 | totalLabel: "source lines added in the timeline", |
| 23 | source: "Git history", |
| 24 | color: "#a9462b", |
| 25 | }, |
| 26 | commits: { |
| 27 | button: "Commits", |
| 28 | title: "Weekly unique commits", |
| 29 | subtitle: "Distinct commit SHAs across the same 94 project trees", |
| 30 | totalLabel: "unique commits in the timeline", |
| 31 | source: "Git history", |
| 32 | color: "#5a4668", |
| 33 | }, |
| 34 | conversationTokens: { |
| 35 | button: "AI conversation", |
| 36 | title: "Weekly retained AI conversation tokens", |
| 37 | subtitle: "Human and assistant message text from the coding desks I operated", |
| 38 | totalLabel: "conversation tokens in the detailed timeline", |
| 39 | source: "Claude, Codex, and Grok transcripts", |
| 40 | color: "#9a712d", |
| 41 | }, |
| 42 | }; |
| 43 | |
| 44 | const compactNumber = new Intl.NumberFormat("en-US", { |
| 45 | notation: "compact", |
| 46 | maximumFractionDigits: 1, |
| 47 | }); |
| 48 | |
| 49 | const fullNumber = new Intl.NumberFormat("en-US"); |
| 50 | |
| 51 | const shortDate = new Intl.DateTimeFormat("en-US", { |
| 52 | month: "short", |
| 53 | year: "2-digit", |
| 54 | timeZone: "UTC", |
| 55 | }); |
| 56 | |
| 57 | const longDate = new Intl.DateTimeFormat("en-US", { |
| 58 | month: "short", |
| 59 | day: "numeric", |
| 60 | year: "numeric", |
| 61 | timeZone: "UTC", |
| 62 | }); |
| 63 | |
| 64 | function dateFromWeek(week: string): Date { |
| 65 | return new Date(`${week}T00:00:00Z`); |
| 66 | } |
| 67 | |
| 68 | function getLabelIndexes(length: number): Set<number> { |
| 69 | const count = Math.min(length, 6); |
| 70 | const indexes = Array.from({ length: count }, (_, index) => |
| 71 | Math.round((index * (length - 1)) / Math.max(count - 1, 1)), |
| 72 | ); |
| 73 | return new Set(indexes); |
| 74 | } |
| 75 | |
| 76 | export function PracticeTimeline() { |
| 77 | const [metric, setMetric] = useState<TimelineMetric>("linesAdded"); |
| 78 | const chart = CHARTS[metric]; |
| 79 | const points = |
| 80 | metric === "conversationTokens" |
| 81 | ? PRACTICE_TIMELINE.filter((point) => point.conversationTokens > 0) |
| 82 | : PRACTICE_TIMELINE; |
| 83 | const values = points.map((point) => point[metric]); |
| 84 | const maximum = Math.max(...values); |
| 85 | const total = values.reduce((sum, value) => sum + value, 0); |
| 86 | const peakIndex = values.indexOf(maximum); |
| 87 | const peak = points[peakIndex]; |
| 88 | const labelIndexes = getLabelIndexes(points.length); |
| 89 | |
| 90 | const width = 1040; |
| 91 | const height = 350; |
| 92 | const padding = { top: 24, right: 18, bottom: 50, left: 76 }; |
| 93 | const innerWidth = width - padding.left - padding.right; |
| 94 | const innerHeight = height - padding.top - padding.bottom; |
| 95 | const step = innerWidth / points.length; |
| 96 | const barWidth = Math.max(3, step * 0.72); |
| 97 | const yTicks = [0, 0.25, 0.5, 0.75, 1]; |
| 98 | const coverageStart = points[0]?.week ?? PRACTICE_TIMELINE[0].week; |
| 99 | |
| 100 | return ( |
| 101 | <section className="practice-timeline" aria-labelledby="practice-timeline-title"> |
| 102 | <header className="practice-timeline-header"> |
| 103 | <div> |
| 104 | <p className="portrait-index">What I made over time</p> |
| 105 | <h2 id="practice-timeline-title"><HisWords>I can see the work accumulate.</HisWords></h2> |
| 106 | </div> |
| 107 | <div className="practice-timeline-total" aria-live="polite"> |
| 108 | <strong>{compactNumber.format(total)}</strong> |
| 109 | <span>{chart.totalLabel}</span> |
| 110 | </div> |
| 111 | </header> |
| 112 | |
| 113 | <div className="practice-chart-controls" role="group" aria-label="Choose a timeline measure"> |
| 114 | {(Object.keys(CHARTS) as TimelineMetric[]).map((key) => ( |
| 115 | <button |
| 116 | type="button" |
| 117 | key={key} |
| 118 | className={metric === key ? "active" : undefined} |
| 119 | aria-pressed={metric === key} |
| 120 | onClick={() => setMetric(key)} |
| 121 | > |
| 122 | {CHARTS[key].button} |
| 123 | </button> |
| 124 | ))} |
| 125 | </div> |
| 126 | |
| 127 | <figure className="practice-chart-figure"> |
| 128 | <figcaption> |
| 129 | <strong>{chart.title}</strong> |
| 130 | <span>{chart.subtitle}</span> |
| 131 | </figcaption> |
| 132 | <div className="practice-chart-frame"> |
| 133 | <svg |
| 134 | viewBox={`0 0 ${width} ${height}`} |
| 135 | role="img" |
| 136 | aria-labelledby="practice-chart-title practice-chart-description" |
| 137 | > |
| 138 | <title id="practice-chart-title">{chart.title}</title> |
| 139 | <desc id="practice-chart-description"> |
| 140 | {`${chart.subtitle}. The peak week is ${longDate.format(dateFromWeek(peak.week))} at ${fullNumber.format(maximum)}.`} |
| 141 | </desc> |
| 142 | |
| 143 | {yTicks.map((tick) => { |
| 144 | const y = padding.top + innerHeight - tick * innerHeight; |
| 145 | return ( |
| 146 | <g key={tick}> |
| 147 | <line |
| 148 | x1={padding.left} |
| 149 | x2={width - padding.right} |
| 150 | y1={y} |
| 151 | y2={y} |
| 152 | stroke="rgba(43, 34, 51, 0.16)" |
| 153 | strokeWidth="1" |
| 154 | /> |
| 155 | <text |
| 156 | x={padding.left - 12} |
| 157 | y={y + 4} |
| 158 | textAnchor="end" |
| 159 | fill="#6d626a" |
| 160 | fontFamily="ui-monospace, SFMono-Regular, Menlo, monospace" |
| 161 | fontSize="11" |
| 162 | > |
| 163 | {compactNumber.format(maximum * tick)} |
| 164 | </text> |
| 165 | </g> |
| 166 | ); |
| 167 | })} |
| 168 | |
| 169 | {points.map((point, index) => { |
| 170 | const value = point[metric]; |
| 171 | const barHeight = maximum === 0 ? 0 : (value / maximum) * innerHeight; |
| 172 | const x = padding.left + index * step + (step - barWidth) / 2; |
| 173 | const y = padding.top + innerHeight - barHeight; |
| 174 | return ( |
| 175 | <g key={`${metric}-${point.week}`}> |
| 176 | <rect |
| 177 | x={x} |
| 178 | y={y} |
| 179 | width={barWidth} |
| 180 | height={barHeight} |
| 181 | rx="2" |
| 182 | fill={chart.color} |
| 183 | > |
| 184 | <title>{`${longDate.format(dateFromWeek(point.week))}: ${fullNumber.format(value)}`}</title> |
| 185 | </rect> |
| 186 | {labelIndexes.has(index) && ( |
| 187 | <text |
| 188 | x={padding.left + index * step + step / 2} |
| 189 | y={height - 18} |
| 190 | textAnchor="middle" |
| 191 | fill="#6d626a" |
| 192 | fontFamily="ui-monospace, SFMono-Regular, Menlo, monospace" |
| 193 | fontSize="11" |
| 194 | > |
| 195 | {shortDate.format(dateFromWeek(point.week))} |
| 196 | </text> |
| 197 | )} |
| 198 | </g> |
| 199 | ); |
| 200 | })} |
| 201 | </svg> |
| 202 | </div> |
| 203 | </figure> |
| 204 | |
| 205 | <div className="practice-chart-facts"> |
| 206 | <p> |
| 207 | <span>Coverage</span> |
| 208 | {longDate.format(dateFromWeek(coverageStart))} to {PRACTICE_SNAPSHOT.display} |
| 209 | </p> |
| 210 | <p> |
| 211 | <span>Peak week</span> |
| 212 | {longDate.format(dateFromWeek(peak.week))} ยท {fullNumber.format(maximum)} |
| 213 | </p> |
| 214 | <p> |
| 215 | <span>Source</span> |
| 216 | {chart.source} |
| 217 | </p> |
| 218 | </div> |
| 219 | <p className="practice-chart-note"> |
| 220 | The final week covers 10 through 13 August. I keep each measure attached to its own unit and source. |
| 221 | </p> |
| 222 | </section> |
| 223 | ); |
| 224 | } |