mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 18:34:02 +00:00
Knip, configured with the application, package exports, scripts, QA harnesses, workers, tools and tests as entry points, reports exports that no module imports. Each was checked by hand against string-based and namespace imports. - Symbols that are still used inside their own module lose only the `export` keyword (176 constants and helpers). - Unused re-exports are removed from barrel modules (flight, military, vessel, CCTV, directions, transit history, local ADS-B and street-level policy modules). - Declarations that nothing uses at all are deleted, among them AIS_WATCHDOG_STATUSES, applyFilter, isRadioCountryCode, compactText, DENSITY_STOPS, the unused CCTV endpoint constants, and the SDR band constants. - Default exports that nothing imports are removed. The ones in src/data/earthquakes.js, src/data/telegeographySubmarineCables.js, src/data/wind.js and src/data/bhoteKoshiLocator.js each constructed a layer instance at import time that nothing used; those instances are no longer created. Every export of a package.json entry stays, as does TOMTOM_CREDIT, which the traffic layer reads from the credits namespace it is given.
75 lines
2.7 KiB
JavaScript
75 lines
2.7 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { poseHash } from '../../../src/data/cctvFootprint.js';
|
|
|
|
/** Sidecar written by scripts/precompute-cctv-heights.mjs. */
|
|
const DEFAULT_GROUND_HEIGHTS_FILE =
|
|
'src/data/local_data/cctv_ground_heights/cctv_ground_heights.json';
|
|
|
|
/** @type {{path:string, mtimeMs:number, cameras:object}|null} */
|
|
let _cache = null;
|
|
|
|
/**
|
|
* Load the precomputed ground-height sidecar (heights under each camera's mount
|
|
* and monitor-plane support points, aligned to the Google 3D Tiles surface). Cached by file mtime so a
|
|
* catalog refresh re-reads only when the file changed. Missing or malformed
|
|
* files mean "no shipped heights", never an error.
|
|
* @param {string} sourceRoot
|
|
* @returns {Record<string, object>} camera id → sidecar entry
|
|
*/
|
|
export function loadGroundHeights(sourceRoot = process.cwd()) {
|
|
const file =
|
|
process.env.CCTV_GROUND_HEIGHTS_FILE || DEFAULT_GROUND_HEIGHTS_FILE;
|
|
const resolved = path.isAbsolute(file)
|
|
? file
|
|
: path.resolve(sourceRoot, file);
|
|
try {
|
|
const stat = fs.statSync(resolved);
|
|
if (_cache && _cache.path === resolved && _cache.mtimeMs === stat.mtimeMs) {
|
|
return _cache.cameras;
|
|
}
|
|
const parsed = JSON.parse(fs.readFileSync(resolved, 'utf8'));
|
|
const cameras =
|
|
parsed &&
|
|
typeof parsed === 'object' &&
|
|
parsed.cameras &&
|
|
typeof parsed.cameras === 'object'
|
|
? parsed.cameras
|
|
: {};
|
|
_cache = { path: resolved, mtimeMs: stat.mtimeMs, cameras };
|
|
return cameras;
|
|
} catch {
|
|
_cache = null;
|
|
return {};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Attach a shipped entry to each served source whose id has one AND whose
|
|
* nominal pose still hashes to what the entry was sampled for. A pack whose
|
|
* feed moved a camera or changed its pose simply loses the shipped value and
|
|
* falls back to runtime placement.
|
|
* @param {Array<object>} sources - Normalized served sources.
|
|
* @param {Record<string, object>} entries - Sidecar cameras map.
|
|
* @returns {Array<object>} The same sources, `groundHeights` attached where valid.
|
|
*/
|
|
export function joinGroundHeights(sources, entries) {
|
|
if (!entries || typeof entries !== 'object') return sources;
|
|
for (const source of sources) {
|
|
const entry = entries[source.id];
|
|
if (!entry || entry.status !== 'ok' || !Number.isFinite(entry.mountGroundM))
|
|
continue;
|
|
if (entry.poseHash !== poseHash(source)) continue;
|
|
const supports = {};
|
|
for (const [key, value] of Object.entries(entry.supports || {})) {
|
|
if (Number.isFinite(value)) supports[key] = value;
|
|
}
|
|
source.groundHeights = {
|
|
poseHash: entry.poseHash,
|
|
mountGroundM: entry.mountGroundM,
|
|
supports,
|
|
};
|
|
}
|
|
return sources;
|
|
}
|