mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
Supersedes #218 by @spcpza, ported onto the current component layout with fixes from review. Verified before merge: format, package boundaries, unit suite, build, and the browser tracking suite; a browser harness for the change where one applies; adversarial review applied. Contributor: @spcpza. His original commit is the base of this branch, and his own re-port onto main (2026-09-15, `5b69011`) was consulted while finishing the height work. That port reads every vehicle's surface from the app's shared ground-floor system (`cachedGroundFloor` / `warmGroundFloor` / `GROUND_FLOOR_LIFT_M`) rather than sampling the scene per layer, keeps a vehicle hidden until its cell answers, warms a bounded batch per poll on a timer instead of per frame, and renders at the ellipsoid above the altitude gate. That is the sounder primitive — one floor system for the app, with the rooftop-versus-street question already settled against a datum-correct DEM prior — and this branch's height work was rebuilt on it, replacing a bespoke cell cache, ground prior and rooftop rule written here. Credit for that direction is his. Future work (not in this PR), both written up in docs/CURRENT-STATE.md: - Readable route names. The realtime feeds carry only `route_id`; `route_short_name` / `route_long_name` live in each operator's static GTFS `routes.txt`, and headsigns in `trips.txt`. Doing it properly wants a server-side metadata loader beside the transit proxy with fixed registered static sources, bounded indexes built once and persisted, a slow conditional refresh, and a versioned route dictionary the browser caches. Shipped here: ids are never rewritten, and a cut one carries an ellipsis instead of reading as a typo. - Below-ground rendering. Subway vehicles are drawn on the surface directly above themselves, because the feeds carry no depth and a train nobody can see is not worth drawing; the card says so plainly. Real treatment wants OSM tunnel geometry per city and a ghosted sprite tethered to the surface. The owner recorded it and left it. Round four and after (2026-09-15). The owner tested round three under FLIR and NVG, and then asked for the design to be taken further: elegant in performance, beautiful on camera, trails with a cache for public transport, Cesium-native, and a core other moving layers can adopt. Codex Astra reviewed the plan (it confirmed the speed fault: a glide started from the drawn position at receipt time but spanned the gap between report times, so with MBTA reporting every ~10 s against a 15 s poll every second glide ran at 1.5x; it rejected a queued-segment patch), then wrote the design, then implemented it in commit-sized passes with adversarial review between them and real-browser harness runs by the integrator. What this PR now contains beyond the contributor's original port: - Delayed playback in a contact-agnostic core (`src/data/contactPlayback.js`): each vehicle keeps a typed, bounded fix history and a display clock that runs at one second per second through it, a feed-derived lag behind real time, holding at its newest fix rather than extrapolating and never sprinting to catch up. Marker, course, motion word, card and trail all read the same displayed sample. The clock has an explicit time-offset and seek API so a rewind is a later feature, not a rewrite; flights and vessels are untouched. - A selected-vehicle trail (`src/data/contactTrailRenderer.js`, `src/layers/transit/trails.js`): the retained history drawn with batched Cesium primitives, clipped at display time so the head is exactly the sprite, faded by age, in the mode colour (white under sensor presets), on the same surface path as the marker. - Bounded proxy-side history (`server/providers/transitHistory.js`): fifteen minutes and at most 128 fixes per vehicle with hard byte ceilings, MBTA only for now (opt-in per feed), served by a small endpoint that never fetches upstream, so a selected trail survives a browser reload while the server keeps running. - Scene work bounded to what is visible and moving, an occluder, cached DETECT candidates, holds on the render loop only while something visible moves. - Sensor presets: white-hot haloed sprites under NVG/FLIR/noir (black-hot inverts), saturated mode colours under CRT, per-mode bracket tiers in every theme, the selected card keeping its mode colour. - A discriminating browser harness (`scripts/qa-transit.mjs`) that samples postRender frames, reads the real card anchor, and measures fleet budgets at 800 and 3,000 vehicles. Not built, recorded as follow-ups: curated route display names (lowest priority per the owner), fleet-wide tails, route snapping, a rewind UI, adoption of the playback core by flights and vessels. Verified at merge (2026-09-15 morning): unit suite 3,896 passing, build clean, format and boundary gates clean, tracking regression 109/109, browser harness keyless 200 pass / 0 fail (13 sensor checks unexercised because the live view offered fewer than six isolated sprites; every judged sprite passed), keyed on Google 3D tiles 198 pass with the per-frame allocation gate as the only failure. Follow-ups recorded: the keyed build's playback sampler still allocates per frame (CPU and frame time stay within budget; the 3,000-vehicle metro view sits at a 27.6 ms frame interval against a 25 ms budget), the shared detection overlay's per-paint allocation, friendlier route names, fleet-wide tails, a rewind UI, and adopting the playback core for vessels and flights. Co-authored-by: spcpza <[email protected]>
205 lines
5.9 KiB
JavaScript
205 lines
5.9 KiB
JavaScript
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
export const BOSTON = {
|
|
id: 'boston',
|
|
label: 'Boston (MBTA)',
|
|
lat: 42.3554,
|
|
lon: -71.0605,
|
|
heading: 25,
|
|
zone: 'America/New_York',
|
|
};
|
|
const LIVE_CITIES = [
|
|
BOSTON,
|
|
{
|
|
id: 'austin',
|
|
label: 'Austin (CapMetro)',
|
|
lat: 30.2672,
|
|
lon: -97.7431,
|
|
heading: 340,
|
|
zone: 'America/Chicago',
|
|
},
|
|
{
|
|
id: 'minneapolis',
|
|
label: 'Minneapolis (Metro Transit)',
|
|
lat: 44.9778,
|
|
lon: -93.265,
|
|
heading: 0,
|
|
zone: 'America/Chicago',
|
|
},
|
|
{
|
|
id: 'helsinki',
|
|
label: 'Helsinki (HSL)',
|
|
lat: 60.1699,
|
|
lon: 24.9384,
|
|
heading: 0,
|
|
zone: 'Europe/Helsinki',
|
|
},
|
|
{
|
|
id: 'oslo',
|
|
label: 'Oslo (Entur)',
|
|
lat: 59.9139,
|
|
lon: 10.7522,
|
|
heading: 0,
|
|
zone: 'Europe/Oslo',
|
|
},
|
|
];
|
|
export function chooseLiveCities(now = new Date()) {
|
|
return LIVE_CITIES.filter((city) => {
|
|
const hour = Number(
|
|
new Intl.DateTimeFormat('en-US', {
|
|
timeZone: city.zone,
|
|
hour: 'numeric',
|
|
hourCycle: 'h23',
|
|
}).format(now),
|
|
);
|
|
return hour >= 6 && hour < 22;
|
|
}).slice(0, 2);
|
|
}
|
|
|
|
/**
|
|
* Switch the post-FX style the way a user does — the preset button — and
|
|
* fall back to the style manager only when the tray is not clickable, saying
|
|
* so. Then set any style parameters through their sliders.
|
|
* @param {import('puppeteer').Page} page
|
|
* @param {string} name
|
|
* @param {Record<string, number>} [params] aria-label → slider value
|
|
* @returns {Promise<string>} how the style was set
|
|
*/
|
|
export async function selectStyle(page, name, params = {}, wait = pause) {
|
|
let how = 'button';
|
|
// The presets live in the bottom control panel, which auto-dismisses when
|
|
// the pointer leaves it: pin it open the way a user does, once.
|
|
await page.evaluate(() => {
|
|
const panel = document.getElementById('control-panel');
|
|
if (panel && !panel.classList.contains('dock-pinned')) {
|
|
document
|
|
.querySelector('.dock-pin-btn[data-pin-target="control-panel"]')
|
|
?.click();
|
|
}
|
|
window.__godsEyeView.styleManager.setPanelCollapsed?.(
|
|
'control-panel',
|
|
false,
|
|
{ explicit: true },
|
|
);
|
|
});
|
|
await wait(400);
|
|
try {
|
|
await page.$eval(`.style-btn[data-style="${name}"]`, (el) =>
|
|
el.scrollIntoView({ block: 'center' }),
|
|
);
|
|
await page.click(`.style-btn[data-style="${name}"]`);
|
|
} catch {
|
|
how = 'styleManager.setStyle (button not clickable)';
|
|
await page.evaluate(
|
|
(n) => window.__godsEyeView.styleManager.setStyle(n),
|
|
name,
|
|
);
|
|
}
|
|
// A click can be swallowed by a loading cover or a collapsed tray without
|
|
// Puppeteer throwing. Verify the active style before querying generated rows.
|
|
if (
|
|
!(await page.evaluate(
|
|
(n) => document.documentElement.dataset.gevStyle === n,
|
|
name,
|
|
))
|
|
) {
|
|
how = 'styleManager.setStyle (button did not activate style)';
|
|
await page.evaluate(
|
|
(n) => window.__godsEyeView.styleManager.setStyle(n),
|
|
name,
|
|
);
|
|
}
|
|
await page.waitForFunction(
|
|
(n) => document.documentElement.dataset.gevStyle === n,
|
|
{ timeout: 10000 },
|
|
name,
|
|
);
|
|
await wait(1_800);
|
|
for (const [label, value] of Object.entries(params)) {
|
|
const selector = `#param-sliders input.param-slider[aria-label="${label}"]`;
|
|
await page.waitForSelector(selector, { timeout: 10000 });
|
|
await page.$eval(
|
|
selector,
|
|
(el, v) => {
|
|
el.value = String(v);
|
|
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
},
|
|
value,
|
|
);
|
|
await wait(700);
|
|
}
|
|
return how;
|
|
}
|
|
|
|
/**
|
|
* Turn DETECT on through its own button, cycling until the dense profile is
|
|
* reported on the detection surface.
|
|
* @param {import('puppeteer').Page} page
|
|
* @returns {Promise<string>} the profile reached
|
|
*/
|
|
export async function detectOn(page, wait = pause) {
|
|
// The real button toggles OFF/restore. Density determines its on-profile.
|
|
const mode = () =>
|
|
page.evaluate(() => {
|
|
const button = document.getElementById('detection-toggle');
|
|
const label = button?.getAttribute('aria-label') || '';
|
|
return {
|
|
on: button?.getAttribute('aria-pressed') === 'true',
|
|
mode: (label.split(':')[1] || 'off').trim().toUpperCase(),
|
|
};
|
|
});
|
|
// The loading screen swallows the first click of a fresh page.
|
|
await page
|
|
.waitForFunction(() => !document.getElementById('loading-screen'), {
|
|
timeout: 30_000,
|
|
})
|
|
.catch(() => {});
|
|
// The DISPLAY rail starts collapsed on a first run: open it the way a user
|
|
// does, then press DETECT until it reports on.
|
|
await page.evaluate(() => {
|
|
const rail = document.getElementById('pp-toggles');
|
|
if (rail?.classList.contains('collapsed'))
|
|
document
|
|
.querySelector('.panel-collapse-btn[data-collapse-target="pp-toggles"]')
|
|
?.click();
|
|
});
|
|
await page.waitForFunction(
|
|
() =>
|
|
document.getElementById('detection-toggle')?.getBoundingClientRect()
|
|
.width > 0,
|
|
{ timeout: 10_000 },
|
|
);
|
|
if (!(await mode()).on) {
|
|
await page.click('#detection-toggle');
|
|
await wait(300);
|
|
}
|
|
await page.$eval('#detection-density-slider', (el) => {
|
|
el.value = '100';
|
|
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
});
|
|
await page.waitForFunction(
|
|
() =>
|
|
document
|
|
.getElementById('detection-toggle')
|
|
?.getAttribute('aria-label') === 'Detection overlay: dense',
|
|
{ timeout: 10000 },
|
|
);
|
|
// Prove the button's actual OFF/restore cycle preserves DENSE.
|
|
await page.click('#detection-toggle');
|
|
await page.waitForFunction(
|
|
() =>
|
|
document
|
|
.getElementById('detection-toggle')
|
|
?.getAttribute('aria-pressed') === 'false',
|
|
{ timeout: 10000 },
|
|
);
|
|
await page.click('#detection-toggle');
|
|
await page.waitForFunction(
|
|
() =>
|
|
document
|
|
.getElementById('detection-toggle')
|
|
?.getAttribute('aria-label') === 'Detection overlay: dense',
|
|
{ timeout: 10000 },
|
|
);
|
|
return (await mode()).mode;
|
|
}
|