mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Merge main (d49d3d10) into the renderer branch
This commit is contained in:
commit
489c316556
134 files changed
+4980
-229
No files matched your search
@@ -32,7 +32,8 @@ export function createCards({
|
||||
if (!layerState._viewer) return;
|
||||
const { query } = components.rendering.scenePorts();
|
||||
const project = (position) => query?.project(position) ?? null;
|
||||
const now = Date.now();
|
||||
// Ages count back from the time shown: the window's end, or now when live.
|
||||
const now = components.model.ageReferenceMs();
|
||||
const entries = [];
|
||||
/** @type {Array<{x: number, y: number}>} Screen positions of accepted labels. */
|
||||
const accepted = [];
|
||||
|
||||
@@ -310,7 +310,7 @@ export function createModel({
|
||||
* (on top) and never distance-faded by the overlay.
|
||||
* Exported for unit tests.
|
||||
* @param {Object} fire - Detection record.
|
||||
* @param {number} nowMs - Current epoch milliseconds.
|
||||
* @param {number} nowMs - Epoch milliseconds ages count back from.
|
||||
* @returns {Object} firmsLabels entry.
|
||||
*/
|
||||
|
||||
@@ -351,9 +351,10 @@ export function createModel({
|
||||
* Card model for an ambient fire detection, e.g. title "▲ 47 MW", detail
|
||||
* "high · 14h · N20". Ages are computed against each detection's acquisition
|
||||
* time — with the live feed everything reads under 24 h (and a stale cache
|
||||
* reads truthfully old). Exported for unit tests.
|
||||
* reads truthfully old); `nowMs` is the time ages count back from, the end
|
||||
* of the window shown (see {@link ageReferenceMs}). Exported for unit tests.
|
||||
* @param {{fire: Object, position: {x: number, y: number, z: number}}} candidate - Label candidate.
|
||||
* @param {number} nowMs - Current epoch milliseconds.
|
||||
* @param {number} nowMs - Epoch milliseconds ages count back from.
|
||||
* @returns {Object} firmsLabels entry.
|
||||
*/
|
||||
|
||||
@@ -385,7 +386,7 @@ export function createModel({
|
||||
* "max 210 MW · new 3h". Accent comes from the candidate (renderHeat sets
|
||||
* it with {@link cellCardAccent}). Exported for unit tests.
|
||||
* @param {{cell: Object, position: {x: number, y: number, z: number}, accent: string}} candidate
|
||||
* @param {number} nowMs - Current epoch milliseconds.
|
||||
* @param {number} nowMs - Epoch milliseconds ages count back from.
|
||||
* @returns {Object} firmsLabels entry.
|
||||
*/
|
||||
|
||||
@@ -516,6 +517,19 @@ export function createModel({
|
||||
return { unit: 'd', count: Math.round(hours / 24) };
|
||||
}
|
||||
|
||||
/**
|
||||
* The time a card's ages count back from: the end of the 24 hours shown
|
||||
* when the snapshot ends at a set time, now while it runs to now. A window
|
||||
* that ended months ago then reads its fires as hours old, as they were.
|
||||
* @param {number} [nowMs] - Current epoch milliseconds.
|
||||
* @returns {number}
|
||||
*/
|
||||
|
||||
function ageReferenceMs(nowMs = Date.now()) {
|
||||
const at = layerState?._at;
|
||||
return Number.isFinite(at) ? at : nowMs;
|
||||
}
|
||||
|
||||
/** Millisecond delta → "<1h" / "Xh" / "Xd", or '' for invalid input. */
|
||||
|
||||
function formatAge(deltaMs) {
|
||||
@@ -590,6 +604,7 @@ export function createModel({
|
||||
cellCardAccent,
|
||||
formatLatLon,
|
||||
formatFrp,
|
||||
ageReferenceMs,
|
||||
formatAge,
|
||||
formatAgeLabel,
|
||||
formatAgoMinutes,
|
||||
|
||||
@@ -183,7 +183,9 @@ export function createSelection({
|
||||
confidence: components.model.confidenceBucket(fire.confidence),
|
||||
age:
|
||||
fire.acqMs > 0
|
||||
? components.model.formatAge(Date.now() - fire.acqMs)
|
||||
? components.model.formatAge(
|
||||
components.model.ageReferenceMs() - fire.acqMs,
|
||||
)
|
||||
: 'unknown',
|
||||
sensor: fire.sensor || 'unknown',
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import { getLocale, setLocale } from '../../i18n/index.js';
|
||||
import { createModel } from './model.js';
|
||||
import { createQueries } from './queries.js';
|
||||
import { createCards } from './cards.js';
|
||||
|
||||
test('a FIRMS snapshot that ends at a set time names it instead of LIVE', (context) => {
|
||||
const now = 1800000000000;
|
||||
@@ -42,3 +43,60 @@ test('a FIRMS snapshot that ends at a set time names it instead of LIVE', (conte
|
||||
setLocale(previousLocale);
|
||||
}
|
||||
});
|
||||
|
||||
test('fire cards count ages from the end of the window shown, and from now when live', (context) => {
|
||||
const now = Date.UTC(2026, 10, 14, 12);
|
||||
context.mock.method(Date, 'now', () => now);
|
||||
// A window that ended months before now: its newest fire three hours earlier.
|
||||
const at = Date.UTC(2026, 7, 1, 12);
|
||||
const layerState = { _at: at };
|
||||
const model = createModel({ layerState, services: { anchors: {} } });
|
||||
const cell = {
|
||||
count: 4,
|
||||
maxFrp: 210,
|
||||
newestAcqMs: at - 3 * 3_600_000,
|
||||
latCell: 1,
|
||||
lonCell: 2,
|
||||
};
|
||||
const previousLocale = getLocale();
|
||||
try {
|
||||
setLocale('en');
|
||||
assert.equal(model.ageReferenceMs(), at);
|
||||
const card = model.buildCellCard({ cell, position: {} }, model.ageReferenceMs());
|
||||
assert.equal(card.details[0], 'max 210 MW · new 3h', 'not months old');
|
||||
|
||||
// The cards the scene shows use the same time.
|
||||
const entries = [];
|
||||
layerState._viewer = { canvas: { clientWidth: 800, clientHeight: 600 } };
|
||||
layerState._fireByCardId = new Map();
|
||||
layerState._selectedFire = null;
|
||||
layerState._labelCandidates = [{ cell, position: {} }];
|
||||
layerState._labelLodDistance = 0;
|
||||
const { rebuildAmbientLabels } = createCards({
|
||||
layerState,
|
||||
services: {},
|
||||
components: {
|
||||
model,
|
||||
rendering: {
|
||||
scenePorts: () => ({
|
||||
query: { project: () => ({ x: 400, y: 300 }), isOccluded: () => false },
|
||||
}),
|
||||
},
|
||||
},
|
||||
config: { overlayHost: { setEntries: (source, shown) => entries.push(...shown) } },
|
||||
});
|
||||
rebuildAmbientLabels();
|
||||
assert.equal(entries.length, 1);
|
||||
assert.equal(entries[0].details[0], 'max 210 MW · new 3h');
|
||||
|
||||
// Live, they count from now.
|
||||
layerState._at = null;
|
||||
cell.newestAcqMs = now - 5 * 3_600_000;
|
||||
assert.equal(model.ageReferenceMs(), now);
|
||||
entries.length = 0;
|
||||
rebuildAmbientLabels();
|
||||
assert.equal(entries[0].details[0], 'max 210 MW · new 5h');
|
||||
} finally {
|
||||
setLocale(previousLocale);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user