feat(perimeters): colour fire perimeters by age

The Fire Perimeters layer now draws a snapshot of fires and the pieces of
their burned area, each piece coloured by its age at the snapshot's moment
(under 6 h, 6-24 h, 1-3 days, older or unknown). Containment stays on the
card; the legend counts fires by last growth and shows the source's note.

- One source method, getSnapshot, returning {at, fetchedAt, stale,
  revision, note, fires, pieces}; getSnapshotDetail is removed.
- WFIGS: one piece per polygon, born at poly_PolygonDateTime, else
  poly_DateCurrent; a time more than 10 minutes ahead is unknown.
- Outlines are drawn apart from fills, so cut pieces have no line along
  the cut; redraws happen only on a new revision or a change of age band.
- The card ages from `at` and adds "last growth ... ago"; with a past
  `at` it links only to an InciWeb incident that began by then.
- perimeterOptions: { inciweb: false } creates no InciWeb sources.
- get_fire_perimeters filters by pieces, places fires at their anchor and
  returns last_growth; analyst items carry lastGrowthTime; spot
  conditions use the anchor.
This commit is contained in:
German Khokhlov committed 2026-11-23 15:48:54 +04:00
1 parent e51853de3d
commit d303d48693
48 files changed
+2127 -734

No files matched your search

+12 -2
View File
@@ -64,7 +64,8 @@ export const ANALYST_LAYERS = Object.freeze(
/** Fields every record carries regardless of layer. */
const COMMON_FIELDS = Object.freeze(['id', 'lat', 'lon']);
/** Derived per-record field for layers with a time field (hours before now). */
/** Derived per-record field for layers with a time field (hours before the
* moment the layer's records show: now, or its past snapshot's time). */
const AGE_FIELD = 'ageHours';
/** Spatial scope kinds `query()` accepts. */
const ANALYST_SCOPE_KINDS = Object.freeze([
@@ -582,6 +583,8 @@ function offerTop(top, candidate, limit, dir) {
* engine and the Contacts-window path so both format and rank alike.
* @param {Array<{key: string, rows: object[]}>} groups Candidate rows.
* @param {object} options
* @param {Map<string, number|null>} [options.recordsAt] Per-layer snapshot times in epoch ms.
* Ages count from the layer’s snapshot time when given, otherwise from now.
* @returns {Promise<object|null>} Selection, or null when cancelled.
*/
export async function selectAnalystRows(
@@ -595,6 +598,7 @@ export async function selectAnalystRows(
ref = null,
inScope = null,
now = Date.now(),
recordsAt = null,
isCurrent = () => true,
distanceOf = null,
} = {},
@@ -603,8 +607,10 @@ export async function selectAnalystRows(
const ageOf = (key, row) => {
const field = timeFieldOf(key);
const t = field ? row[field] : null;
const from = recordsAt?.get(key);
const ref = Number.isFinite(from) ? from : now;
return Number.isFinite(t)
? Math.round(((now - t) / 3_600_000) * 10) / 10
? Math.round(((ref - t) / 3_600_000) * 10) / 10
: null;
};
const distance = (row) => {
@@ -771,6 +777,7 @@ export function createAnalystEngine(providers) {
spec = normalized.spec;
// 1) Source records, grouped by layer and never copied.
const recordsAt = followUp ? lastResult.recordsAt : new Map();
let groups;
let layersQueried;
let queriedSnapshots;
@@ -786,6 +793,7 @@ export function createAnalystEngine(providers) {
queriedSnapshots = [];
for (const key of layers) {
const rows = providers.getRecords(key) || [];
recordsAt.set(key, providers.getRecordsAt?.(key) ?? null);
const snapshot = providers.getLayerSnapshot?.(key);
if (snapshot) queriedSnapshots.push(snapshot);
const coverage = providers.getRecordCoverage?.(key, rows) || {};
@@ -1048,6 +1056,7 @@ export function createAnalystEngine(providers) {
: null,
inScope,
now: providers.now?.() ?? Date.now(),
recordsAt,
isCurrent,
});
if (!selection || !isCurrent()) return cancelled();
@@ -1147,6 +1156,7 @@ export function createAnalystEngine(providers) {
if (!isCurrent()) return cancelled();
lastResult = {
matched: memoryOverride?.matched || selection.matched,
recordsAt,
distanceOf: memoryOverride?.distanceOf || rememberedDistanceOf,
layerKeys: [...(memoryOverride?.layerKeys || layers)],
coverage: memoryOverride?.coverage || result.coverage,
+18
View File
@@ -896,6 +896,24 @@ test('time fields filter by ISO and derive ageHours; the feed window is exposed'
assert.equal(age.coverage.layersQueried[0].window, 'last 24 h');
});
test('perimeter age follows the snapshot time of the remembered rows', async () => {
const discoveredTime = Date.UTC(2024, 6, 1);
let at = Date.UTC(2024, 6, 2);
const engine = createAnalystEngine({
now: () => Date.UTC(2026, 6, 2),
getRecords: () => [{ id: 'Pine', discoveredTime }],
getRecordsAt: () => at,
});
const first = await engine.query({
layers: ['fire-perimeters'],
scope: { kind: 'anywhere' },
});
assert.equal(first.items[0].ageHours, 24);
at = null;
const followUp = await engine.query({ followUp: true });
assert.equal(followUp.items[0].ageHours, 24);
});
test('follow-up provenance stays attached to old rows after a feed recovers', async () => {
let state = 'stale';
const engine = createAnalystEngine({
+28
View File
@@ -57,6 +57,34 @@ function install(options = {}, hook = 'configureServer') {
};
}
test('the WFIGS query asks for the mapping and edit times, and rows keep both', async () => {
let url;
const request = install({
now: () => 1234,
fetchImpl: async (input) => {
url = new URL(input);
return Response.json({
features: [
{
...feature('timed'),
properties: {
attr_UniqueFireIdentifier: 'timed',
poly_PolygonDateTime: 100,
poly_DateCurrent: 200,
},
},
],
});
},
});
const res = await request();
const fields = url.searchParams.get('outFields').split(',');
assert.ok(fields.includes('poly_PolygonDateTime'));
assert.ok(fields.includes('poly_DateCurrent'));
assert.equal(res.body.rows[0].polygonTime, 100);
assert.equal(res.body.rows[0].updatedTime, 200);
});
for (const hook of ['configureServer', 'configurePreviewServer']) {
test(`${hook}: paging stops at five pages and normalizes the combined snapshot`, async () => {
const calls = [];