Show the rankings in the browser (#16) #62

Merged
chris-kreidl merged 2 commits from 16-rankings-table into main 2026-11-13 16:03:02 +00:00
chris-kreidl commented 2026-11-13 15:46:28 +00:00 (Migrated from github.com)

🤖 Claude: Closes #16

bun run web serves the Magic Formula ranking as a sortable, filterable table on 127.0.0.1:3000 (set PORT to change it).

How it works

  • src/server.ts: Bun.serve with an HTML import for / and /api/rankings. The JSON comes from rankedFromDb, the same function that writes the CSV, read fresh on each request.
  • web/table.ts: filtering, re-ranking (assignRanks, now shared with rank), sorting and the Stock Analysis link, without the DOM. web/app.ts draws the page.
  • rankDesc is now O(n log n), because the page re-ranks on every filter change.
  • The root tsconfig.json gains the DOM lib. Two helpers in refresh.test.ts now type their zips as Uint8Array<ArrayBuffer> to satisfy DOM's BodyInit (no behavior change).

Acceptance criteria

  • bun run web binds 127.0.0.1 only, with no login. The test checks the hostname; on real data, the machine's LAN IP refuses connections. HTML imports serve the page.
  • Same companies and ranks as the CSV. test/server.test.ts compares the API with rank()'s CSV. Real data: 1,391 rows in both, identical order.
  • All 11 columns; clicking a header sorts by it, and clicking again reverses the order.
  • Filters: sector (pick any number) and market cap min/max in $M.
  • Every filter re-ranks the companies shown: ROTC, EY and combined ranks are recomputed. Example: Technology with a $1,000M minimum puts GEN (overall #34) at #1.
  • The overall rank keeps its place in the full list under any filter.
  • Tickers link to stockanalysis.com/stocks/<ticker>/ and open in a new tab. Class suffixes use a dot. Checked in the browser: bf.b → Brown-Forman, mog.a → Moog (mog-a is a 404). These are the only two suffix tickers in the list.
  • The page shows "Prices last updated …", taken from the latest successful enrich run.
  • Real data: the API answers in 7 ms (406 KB); a filter change re-renders in about 20 ms.

Definition of Done

  • Acceptance criteria met and demonstrated (above)
  • bun test passes (275 pass, 0 fail); new logic has tests (test/server.test.ts, test/table.test.ts)
  • bun check is clean (37 files) and bun fmt --check passes
  • Runs end to end on real data (company_facts.db, 1,391 eligible companies)
  • Stand-up posted on #51 when the story started and when this PR opened
  • Open product questions filed: #61 (SIC-only sectors such as "Services-Computer Programming…" show as their own sector chips)

🤖 Generated with Claude Code

🤖 **Claude:** Closes #16 `bun run web` serves the Magic Formula ranking as a sortable, filterable table on `127.0.0.1:3000` (set `PORT` to change it). **How it works** - `src/server.ts`: `Bun.serve` with an HTML import for `/` and `/api/rankings`. The JSON comes from `rankedFromDb`, the same function that writes the CSV, read fresh on each request. - `web/table.ts`: filtering, re-ranking (`assignRanks`, now shared with `rank`), sorting and the Stock Analysis link, without the DOM. `web/app.ts` draws the page. - `rankDesc` is now O(n log n), because the page re-ranks on every filter change. - The root `tsconfig.json` gains the `DOM` lib. Two helpers in `refresh.test.ts` now type their zips as `Uint8Array<ArrayBuffer>` to satisfy DOM's `BodyInit` (no behavior change). ### Acceptance criteria - [x] `bun run web` binds `127.0.0.1` only, with no login. The test checks the hostname; on real data, the machine's LAN IP refuses connections. HTML imports serve the page. - [x] Same companies and ranks as the CSV. `test/server.test.ts` compares the API with `rank()`'s CSV. Real data: 1,391 rows in both, identical order. - [x] All 11 columns; clicking a header sorts by it, and clicking again reverses the order. - [x] Filters: sector (pick any number) and market cap min/max in $M. - [x] Every filter re-ranks the companies shown: ROTC, EY and combined ranks are recomputed. Example: Technology with a $1,000M minimum puts GEN (overall #34) at #1. - [x] The overall rank keeps its place in the full list under any filter. - [x] Tickers link to `stockanalysis.com/stocks/<ticker>/` and open in a new tab. Class suffixes use a dot. Checked in the browser: `bf.b` → Brown-Forman, `mog.a` → Moog (`mog-a` is a 404). These are the only two suffix tickers in the list. - [x] The page shows "Prices last updated …", taken from the latest *successful* enrich run. - [x] Real data: the API answers in 7 ms (406 KB); a filter change re-renders in about 20 ms. ### Definition of Done - [x] Acceptance criteria met and demonstrated (above) - [x] `bun test` passes (275 pass, 0 fail); new logic has tests (`test/server.test.ts`, `test/table.test.ts`) - [x] `bun check` is clean (37 files) and `bun fmt --check` passes - [x] Runs end to end on real data (`company_facts.db`, 1,391 eligible companies) - [x] Stand-up posted on #51 when the story started and when this PR opened - [x] Open product questions filed: #61 (SIC-only sectors such as "Services-Computer Programming…" show as their own sector chips) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chris-kreidl commented 2026-11-13 15:58:12 +00:00 (Migrated from github.com)

🤖 Claude: Added browser tests for the page (Chris approved happy-dom as a dev dependency).

  • New dev dependency: @happy-dom/global-registrator 21.0.4.
  • test/app.test.ts (11 tests): loads web/app.ts against index.html's markup with /api/rankings stubbed. It covers rows and number formatting, the prices line (including no enrich run yet), ticker links, sector chips, sector filters re-ranking, market-cap bounds in $M, Clear filters, header sorting both ways with aria-sort, and the error message when loading fails.
  • happy-dom is registered in that file only, not preloaded for every test, so the server and refresh tests keep Bun's own fetch and Response.
  • app.ts changes: aria-sort is now set as an attribute, and checked sectors are read from .checked. happy-dom doesn't support the ariaSort property, and after a form reset its :checked selector still matched cleared boxes. Both changes behave the same in real browsers.

bun test: 286 pass, 0 fail. bun check and bun fmt --check are clean.

🤖 **Claude:** Added browser tests for the page (Chris approved happy-dom as a dev dependency). - New dev dependency: `@happy-dom/global-registrator` 21.0.4. - `test/app.test.ts` (11 tests): loads `web/app.ts` against `index.html`'s markup with `/api/rankings` stubbed. It covers rows and number formatting, the prices line (including no enrich run yet), ticker links, sector chips, sector filters re-ranking, market-cap bounds in $M, Clear filters, header sorting both ways with `aria-sort`, and the error message when loading fails. - happy-dom is registered in that file only, not preloaded for every test, so the server and refresh tests keep Bun's own `fetch` and `Response`. - `app.ts` changes: `aria-sort` is now set as an attribute, and checked sectors are read from `.checked`. happy-dom doesn't support the `ariaSort` property, and after a form reset its `:checked` selector still matched cleared boxes. Both changes behave the same in real browsers. `bun test`: 286 pass, 0 fail. `bun check` and `bun fmt --check` are clean.
socket-security[bot] commented 2026-11-13 15:58:27 +00:00 (Migrated from github.com)

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​happy-dom/​global-registrator@​21.0.41001008796100

View full report

**Review the following changes in direct dependencies.** Learn more about [Socket for GitHub](https://socket.dev?utm_medium=gh). <table> <thead> <tr> <th>Diff</th> <th width="200px">Package</th> <th align="center" width="100px">Supply Chain<br/>Security</th> <th align="center" width="100px">Vulnerability</th> <th align="center" width="100px">Quality</th> <th align="center" width="100px">Maintenance</th> <th align="center" width="100px">License</th> </tr> </thead> <tbody> <tr><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/b9349333-afe5-4b04-abd4-71fbc0169478?tab=dependencies&dependency_item_key=101966711642"><img src="https://github-app-statics.socket.dev/diff-added.svg" title="Added" alt="Added" width="20" height="20"></a></td><td><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/b9349333-afe5-4b04-abd4-71fbc0169478?tab=dependencies&dependency_item_key=101966711642">@​happy-dom/​global-registrator@​21.0.4</a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/b9349333-afe5-4b04-abd4-71fbc0169478?tab=dependencies&dependency_item_key=101966711642"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Supply Chain Security" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/b9349333-afe5-4b04-abd4-71fbc0169478?tab=dependencies&dependency_item_key=101966711642"><img src="https://github-app-statics.socket.dev/score-100.svg" title="Vulnerability" width="40" height="40" alt="100"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/b9349333-afe5-4b04-abd4-71fbc0169478?tab=dependencies&dependency_item_key=101966711642"><img src="https://github-app-statics.socket.dev/score-87.svg" title="Quality" width="40" height="40" alt="87"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/b9349333-afe5-4b04-abd4-71fbc0169478?tab=dependencies&dependency_item_key=101966711642"><img src="https://github-app-statics.socket.dev/score-96.svg" title="Maintenance" width="40" height="40" alt="96"></a></td><td align="center"><a href="https://socket.dev/dashboard/org/chris-kreidl/diff-scan/b9349333-afe5-4b04-abd4-71fbc0169478?tab=dependencies&dependency_item_key=101966711642"><img src="https://github-app-statics.socket.dev/score-100.svg" title="License" width="40" height="40" alt="100"></a></td></tr> </tbody> </table> [View full report](https://socket.dev/dashboard/org/chris-kreidl/diff-scan/b9349333-afe5-4b04-abd4-71fbc0169478?tab=dependencies) <!-- overview-comment -->
claude[bot] commented 2026-11-13 15:59:17 +00:00 (Migrated from github.com)

🤖 Claude: ## Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 **Claude:** ## Code review No issues found. Checked for bugs and CLAUDE.md compliance.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/screener!62
No description provided.