| 1 | <!doctype html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | <meta name="robots" content="noindex, nofollow"> |
| 7 | <title>Codewhale telemetry stats</title> |
| 8 | <style> |
| 9 | :root{--bg:#f7f7f5;--fg:#1b1b1a;--mut:#6a6a66;--card:#fff;--line:#deded9;--bar:#2f6fed;--bar2:#9bb8f5} |
| 10 | @media (prefers-color-scheme:dark){:root{--bg:#121212;--fg:#ececea;--mut:#9a9a95;--card:#1c1c1b;--line:#333330;--bar:#6c9bff;--bar2:#35508f}} |
| 11 | *{box-sizing:border-box} |
| 12 | body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.45 system-ui,sans-serif} |
| 13 | main{max-width:1080px;margin:0 auto;padding:20px 16px 48px} |
| 14 | h1{font-size:20px;margin:0 0 4px} |
| 15 | p.sub{color:var(--mut);margin:0 0 20px} |
| 16 | .grid{display:grid;gap:14px;grid-template-columns:repeat(auto-fill,minmax(320px,1fr))} |
| 17 | section{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:14px} |
| 18 | h2{font-size:14px;margin:0 0 10px} |
| 19 | svg{width:100%;height:auto;display:block} |
| 20 | .row{display:grid;grid-template-columns:minmax(0,38%) 1fr auto;gap:8px;align-items:center;font-size:13px;margin:3px 0} |
| 21 | .row span.k{overflow:hidden;text-overflow:ellipsis;white-space:nowrap} |
| 22 | .track{background:var(--line);height:8px;border-radius:4px;overflow:hidden} |
| 23 | .track i{display:block;height:100%;background:var(--bar)} |
| 24 | .num{font-variant-numeric:tabular-nums;color:var(--mut)} |
| 25 | .caveats{color:var(--mut);font-size:12.5px;margin-top:22px} |
| 26 | .err{color:#b3261e} |
| 27 | </style> |
| 28 | </head> |
| 29 | <body> |
| 30 | <main> |
| 31 | <h1>Codewhale telemetry stats</h1> |
| 32 | <p class="sub" id="sub">Loading</p> |
| 33 | <div class="grid" id="grid"></div> |
| 34 | <ul class="caveats" id="caveats"></ul> |
| 35 | </main> |
| 36 | <script> |
| 37 | const grid = document.getElementById("grid"); |
| 38 | const NS = "http://www.w3.org/2000/svg"; |
| 39 | const fmt = (n) => n >= 1e9 ? (n/1e9).toFixed(1)+"B" : n >= 1e6 ? (n/1e6).toFixed(1)+"M" : n >= 1e4 ? (n/1e3).toFixed(1)+"k" : String(Math.round(n)); |
| 40 | |
| 41 | function card(title) { |
| 42 | const s = document.createElement("section"); |
| 43 | const h = document.createElement("h2"); |
| 44 | h.textContent = title; |
| 45 | s.appendChild(h); |
| 46 | grid.appendChild(s); |
| 47 | return s; |
| 48 | } |
| 49 | |
| 50 | function series(rows, metric, dim, key) { |
| 51 | const m = new Map(); |
| 52 | for (const r of rows) if (r.metric === metric && r.dim === dim && (key === undefined || r.key === key)) m.set(r.day, (m.get(r.day) || 0) + r.value); |
| 53 | return [...m].sort((a, b) => a[0].localeCompare(b[0])); |
| 54 | } |
| 55 | |
| 56 | function totals(rows, metric, dim, top) { |
| 57 | const m = new Map(); |
| 58 | for (const r of rows) if (r.metric === metric && r.dim === dim) m.set(r.key, (m.get(r.key) || 0) + r.value); |
| 59 | let list = [...m].sort((a, b) => b[1] - a[1]); |
| 60 | if (top && list.length > top) { |
| 61 | const rest = list.slice(top).reduce((s, x) => s + x[1], 0); |
| 62 | list = list.slice(0, top).concat([["other (rest)", rest]]); |
| 63 | } |
| 64 | return list; |
| 65 | } |
| 66 | |
| 67 | function bars(parent, points) { |
| 68 | if (!points.length) { parent.appendChild(document.createTextNode("No data in window.")); return; } |
| 69 | const w = 320, h = 110, pad = 18, max = Math.max(...points.map((p) => p[1]), 1); |
| 70 | const svg = document.createElementNS(NS, "svg"); |
| 71 | svg.setAttribute("viewBox", `0 0 ${w} ${h + pad}`); |
| 72 | const bw = w / points.length; |
| 73 | points.forEach(([day, v], i) => { |
| 74 | const r = document.createElementNS(NS, "rect"); |
| 75 | const bh = (v / max) * h; |
| 76 | r.setAttribute("x", i * bw + 1); r.setAttribute("y", h - bh); r.setAttribute("width", Math.max(bw - 2, 1)); r.setAttribute("height", bh); |
| 77 | r.setAttribute("fill", "var(--bar)"); |
| 78 | const t = document.createElementNS(NS, "title"); t.textContent = `${day}: ${fmt(v)}`; r.appendChild(t); |
| 79 | svg.appendChild(r); |
| 80 | }); |
| 81 | const label = (x, anchor, text) => { const t = document.createElementNS(NS, "text"); t.setAttribute("x", x); t.setAttribute("y", h + 13); t.setAttribute("text-anchor", anchor); t.setAttribute("font-size", "10"); t.setAttribute("fill", "var(--mut)"); t.textContent = text; svg.appendChild(t); }; |
| 82 | label(0, "start", points[0][0]); label(w, "end", `${points[points.length - 1][0]} max ${fmt(max)}`); |
| 83 | parent.appendChild(svg); |
| 84 | } |
| 85 | |
| 86 | function list(parent, entries) { |
| 87 | if (!entries.length) { parent.appendChild(document.createTextNode("No data in window.")); return; } |
| 88 | const max = Math.max(...entries.map((e) => e[1]), 1); |
| 89 | for (const [k, v] of entries) { |
| 90 | const row = document.createElement("div"); row.className = "row"; |
| 91 | const a = document.createElement("span"); a.className = "k"; a.textContent = k; a.title = k; |
| 92 | const tr = document.createElement("div"); tr.className = "track"; const i = document.createElement("i"); i.style.width = (v / max * 100) + "%"; tr.appendChild(i); |
| 93 | const n = document.createElement("span"); n.className = "num"; n.textContent = fmt(v); |
| 94 | row.append(a, tr, n); parent.appendChild(row); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | function chart(title, points) { bars(card(title), points); } |
| 99 | function breakdown(title, entries) { list(card(title), entries); } |
| 100 | |
| 101 | async function main() { |
| 102 | const sub = document.getElementById("sub"); |
| 103 | let data; |
| 104 | try { |
| 105 | const res = await fetch("/api/stats"); |
| 106 | if (!res.ok) throw new Error(String(res.status)); |
| 107 | data = await res.json(); |
| 108 | } catch (e) { |
| 109 | sub.textContent = "Could not load stats (" + e.message + ")."; |
| 110 | sub.className = "sub err"; |
| 111 | return; |
| 112 | } |
| 113 | const rows = data.rows; |
| 114 | sub.textContent = `UTC days ${data.from} to ${data.to}, generated ${data.generated_at}. Aggregates only, no install ids.`; |
| 115 | chart("Observed active installs per day", series(rows, "active_installs", "all")); |
| 116 | breakdown("Active installs by version (sum of daily)", totals(rows, "active_installs", "version", 12)); |
| 117 | breakdown("Active installs by surface (sum of daily)", totals(rows, "active_installs", "surface")); |
| 118 | breakdown("Active installs by OS (sum of daily)", totals(rows, "active_installs", "os")); |
| 119 | chart("Sessions per day", series(rows, "sessions", "all")); |
| 120 | chart("Turns per day", series(rows, "turns", "all")); |
| 121 | chart("Tool calls per day", series(rows, "tool_calls", "all")); |
| 122 | breakdown("Tool calls by tool", totals(rows, "tool_calls", "tool", 15)); |
| 123 | breakdown("Model turns by provider", totals(rows, "model_turns_ok", "provider")); |
| 124 | breakdown("Model turns by catalog model", totals(rows, "model_turns_ok", "model", 15)); |
| 125 | breakdown("Input tokens by provider", totals(rows, "model_input_tokens", "provider")); |
| 126 | breakdown("Output tokens by provider", totals(rows, "model_output_tokens", "provider")); |
| 127 | breakdown("Website funnel (weighted counters)", totals(rows, "website_funnel", "funnel")); |
| 128 | breakdown("Native funnel (distinct ids per day, summed)", [ |
| 129 | ["initialized", series(rows, "native_installs_initialized", "funnel").reduce((s, p) => s + p[1], 0)], |
| 130 | ["successful turn", series(rows, "native_installs_with_successful_turn", "funnel").reduce((s, p) => s + p[1], 0)], |
| 131 | ]); |
| 132 | const caveats = document.getElementById("caveats"); |
| 133 | for (const c of data.caveats) { const li = document.createElement("li"); li.textContent = c; caveats.appendChild(li); } |
| 134 | try { |
| 135 | const res = await fetch("/api/trend?days=365"); |
| 136 | if (res.ok) { |
| 137 | const trend = await res.json(); |
| 138 | chart("Observed active installs per day, kept totals", series(trend.rows, "active_installs", "all")); |
| 139 | chart("Sessions per day, kept totals", series(trend.rows, "sessions", "all")); |
| 140 | } |
| 141 | } catch (e) {} |
| 142 | } |
| 143 | main(); |
| 144 | </script> |
| 145 | </body> |
| 146 | </html> |
| 147 |