garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/usage-stats.md

raw


topic: usage-stats triggers: [crates/simulator/src/stats, "/api/admin/accounts/activity", account-stats.ts, stats.db, migrations_stats, "/api/stats/hit", "/api/admin/stats", "/api/communities/{id}/stats", stats_view, stats_positions, WsQuery, docs/mockups/stats] updated: 2026-11-14

Usage statistics count what the server already sees, and keep counts

crate::stats counts how the world is used and who visits the sites, for Admin › Stats and a community's moderators (docs/mockups/stats/, decided 2026-10-18). The rules the design rests on — break one and the page stops being cookie-free and consent-free:

One account, by name: Admin › Accounts

The one place these numbers are about a person rather than a count (stats::accounts, docs/mockups/admin-accounts/, decided 2026-11-14): each account's line shows whether it is online and when it was last seen, and an opened line its sign-ins, last app and build, and minutes online per day over 30 days, beside counts from the world (communities, posts, prims, buildings, contacts, chat devices, linked sign-ins, last place). It is read with accounts_manage, not stats_view: the operator who already sees the account's address and can delete it. Nothing new is recorded for it — it reads the per-account sessions above, so it reaches back [KEEP_DAYS] and no further, and a session's minutes overlap-merge so two apps open at once count once. Who is online comes from memory, not the rows: a session is written a minute after it starts.

Where it is

stats.db beside world.db, its own file with its own migrations (crates/simulator/migrations_stats/, numbered from V1 independently of the world's — the two histories never collide). Kept apart because stats grow every minute, need no backup with the world, and can be wiped alone. Its migrations are exercised by --create-admin, which the deploy smoke test runs on a copy of the live files.

Recording is a mutex and a hash insert, never the disk: everything is tallied in memory and written once a minute (stats::spawn). What the last minute counted is lost on a stop, and a restart mid-day makes that day's distinct counts (visitors, people per square) a little low, because the in-memory sets start over and the stored value is the larger of the two. Days are UTC; hour rows are unix hours, for the page to draw in its reader's zone.

Which app opened a session

From /ws?client=android|desktop|web|chat&build=<commit>. Not a field in ClientHello: postcard is positional, so a field there is a protocol revision, and every installed app older than it would be refused at sign-in. An app that sends no parameter is unknown; so is plain TCP (local tooling).

The pages

Admin › Stats (crates/atlas/web/src/components/pages/stats/) and a community's Stats pane (community-stats.tsx) draw the answers; their types in types.ts are checked against the live answers by the integration test stats::the_web_pages_types_match_what_the_server_sends. The site counts a page view on every change of address (main.tsx's route resolvers), the viewer once on load (crates/cartopolis/index.html, before the WebGPU gate). Busy squares are named by our own nominatim.cartopolis.org, from the operator's browser, only for the ranked lists (never per square on the map). There is no raster base map: the tile server serves vector tiles only, and loading map images from a third party would send operators' browsers elsewhere.

Cannot be counted, and why

Counted from outside the simulator

Deploying

The public paths must be in the host Caddyfile's API matchers, or they answer the web UI's index.html with a 200 (hosted-simulator.md): /api/stats/hit and /api/communities/*/stats. /api/admin/stats/* is already covered by /api/admin/*. The two settings above live in /etc/cartopolis-sim.env.