mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
fix(weather): weather cards measure from the timeline time and know when wind follows it
At a past time the radar, lightning and satellite cards aged the shown frame and judged the source delayed against the wall clock, so a frame from years back read "Source observations delayed" and an age in the millions of minutes. Frame ages, the delayed status and the stale stat now count from the timeline time at a past time, and from now while live, as before. The observed timeline's readout and preview show the time alone at a past time, since its age from the timeline time is always zero. The wind card noted that it does not follow the timeline whenever the observed clock was at a past time, even when a host follows the world clock for wind. The weather clock now reports whether a layer follows the world clock (weatherClock.follows(id), the world clock's follows), and the wind row and card drop that note when its source follows the timeline.
This commit is contained in:
1 parent
7b4b4d4184
commit
6e23a73283
8 files changed
+149
-19
No files matched your search
@@ -8566,7 +8566,12 @@ Playback advances two seconds after all products settle, wraps, and stops with
|
|||||||
fewer than two union times or when all products are suspended. Hidden documents,
|
fewer than two union times or when all products are suspended. Hidden documents,
|
||||||
reduced motion and unavailable imagery hosts suspend products. Re-enabling or
|
reduced motion and unavailable imagery hosts suspend products. Re-enabling or
|
||||||
restoring a host joins the retained history target. The wind row explicitly says
|
restoring a host joins the retained history target. The wind row explicitly says
|
||||||
“Forecast · does not follow history” while the observed clock is in history mode.
|
“Forecast · does not follow history” while the observed clock is in history mode,
|
||||||
|
unless a host follows the world clock for `wind` (`weatherClock.follows('wind')`):
|
||||||
|
its source then follows the timeline and the row says nothing of it. In history
|
||||||
|
mode, frame ages and the “Source observations delayed” status are measured from
|
||||||
|
the timeline time rather than the wall clock, and the timeline readout shows the
|
||||||
|
time alone; live, they count from now as before.
|
||||||
The catalog exposes `weatherClock` and destroys it with its lifetime signal.
|
The catalog exposes `weatherClock` and destroys it with its lifetime signal.
|
||||||
|
|
||||||
Source, opacity, coverage navigation and transport controls live in the WEATHER
|
Source, opacity, coverage navigation and transport controls live in the WEATHER
|
||||||
|
|||||||
@@ -248,6 +248,12 @@ export function createWeatherClock({
|
|||||||
},
|
},
|
||||||
getTimeline,
|
getTimeline,
|
||||||
selectFor,
|
selectFor,
|
||||||
|
/**
|
||||||
|
* Whether layer `id` follows the world clock (see the world clock's
|
||||||
|
* `follows`): a host that follows it for a layer of its own, such as
|
||||||
|
* wind, gives that layer the timeline time rather than the live edge.
|
||||||
|
*/
|
||||||
|
follows: (id) => world.follows(id),
|
||||||
setTarget(time) {
|
setTarget(time) {
|
||||||
if (destroyed) return Promise.resolve(false);
|
if (destroyed) return Promise.resolve(false);
|
||||||
if (!Number.isFinite(Date.parse(time)))
|
if (!Number.isFinite(Date.parse(time)))
|
||||||
|
|||||||
@@ -120,9 +120,17 @@ export function createWeatherLayer({
|
|||||||
rendering?.cancelPrefetch?.();
|
rendering?.cancelPrefetch?.();
|
||||||
notify();
|
notify();
|
||||||
});
|
});
|
||||||
|
// Ages and delays are measured from the time the layer shows: the world
|
||||||
|
// clock's time at a past time, the wall clock while live.
|
||||||
|
const worldNow = () => {
|
||||||
|
const shared = clock?.getState();
|
||||||
|
return shared?.mode === 'history' && shared.target
|
||||||
|
? Date.parse(shared.target)
|
||||||
|
: Date.now();
|
||||||
|
};
|
||||||
const observationDelayed = () =>
|
const observationDelayed = () =>
|
||||||
manifest?.latest &&
|
manifest?.latest &&
|
||||||
Date.now() - Date.parse(manifest.latest) >
|
worldNow() - Date.parse(manifest.latest) >
|
||||||
(product === 'clouds' ? 240 : lightning ? 45 : 20) * 60_000;
|
(product === 'clouds' ? 240 : lightning ? 45 : 20) * 60_000;
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
if (clock) return;
|
if (clock) return;
|
||||||
@@ -573,7 +581,7 @@ export function createWeatherLayer({
|
|||||||
const index = times.indexOf(time);
|
const index = times.indexOf(time);
|
||||||
const current = index >= 0;
|
const current = index >= 0;
|
||||||
const age = time
|
const age = time
|
||||||
? Math.max(0, Math.floor((Date.now() - Date.parse(time)) / 60000))
|
? Math.max(0, Math.floor((worldNow() - Date.parse(time)) / 60000))
|
||||||
: null;
|
: null;
|
||||||
const lag =
|
const lag =
|
||||||
age === null
|
age === null
|
||||||
|
|||||||
@@ -2681,3 +2681,44 @@ test('the layer hands rendering a frame source only when its feed is one', () =>
|
|||||||
assert.equal(typeof seen[1].getTile, 'function');
|
assert.equal(typeof seen[1].getTile, 'function');
|
||||||
assert.equal(seen[1].getImage, undefined);
|
assert.equal(seen[1].getImage, undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('at a past time a frame is aged and its source judged delayed from the timeline time', async (t) => {
|
||||||
|
// Live at twenty minutes past the newest frame: the source is late.
|
||||||
|
t.mock.method(Date, 'now', () => Date.parse(times[2]) + 25 * 60_000);
|
||||||
|
const clock = createWeatherClock();
|
||||||
|
const h = layerHarness({ clock });
|
||||||
|
t.after(() => {
|
||||||
|
h.layer.destroy();
|
||||||
|
clock.destroy();
|
||||||
|
});
|
||||||
|
const update = h.layer.update();
|
||||||
|
await flush();
|
||||||
|
h.stages.at(-1).finish();
|
||||||
|
await update;
|
||||||
|
await flush();
|
||||||
|
assert.equal(
|
||||||
|
h.layer.getRowControls().summary.status,
|
||||||
|
'Source observations delayed',
|
||||||
|
);
|
||||||
|
assert.match(h.layer.getRowControls().summary.detail, /25m ago/);
|
||||||
|
|
||||||
|
// Years later, the world clock is moved back to the newest frame.
|
||||||
|
Date.now.mock.mockImplementation(() => Date.parse('2032-01-01T00:00:00Z'));
|
||||||
|
void clock.setTarget(times[2]);
|
||||||
|
await flush();
|
||||||
|
h.stages.at(-1)?.finish();
|
||||||
|
await flush();
|
||||||
|
assert.equal(clock.getState().mode, 'history');
|
||||||
|
const controls = h.layer.getRowControls();
|
||||||
|
assert.equal(controls.summary.status, null);
|
||||||
|
assert.match(controls.summary.detail, /History · 09-15 20:10 UTC · 0m ago/);
|
||||||
|
assert.equal(h.layer.getStats().stale, false);
|
||||||
|
|
||||||
|
// Ten minutes after the newest frame, the frame is ten minutes old.
|
||||||
|
void clock.setTarget('2026-09-15T20:20:00.000Z');
|
||||||
|
await flush();
|
||||||
|
h.stages.at(-1)?.finish();
|
||||||
|
await flush();
|
||||||
|
assert.match(h.layer.getRowControls().summary.detail, /10m ago · nearest/);
|
||||||
|
assert.equal(h.layer.getRowControls().summary.status, null);
|
||||||
|
});
|
||||||
@@ -258,8 +258,9 @@ export function createWindLayer({
|
|||||||
return { model, overlay, paused, units };
|
return { model, overlay, paused, units };
|
||||||
},
|
},
|
||||||
getRowControls() {
|
getRowControls() {
|
||||||
|
// A source that follows the timeline shows the wind at its time.
|
||||||
const historyStatus =
|
const historyStatus =
|
||||||
clock?.getState().mode === 'history'
|
clock?.getState().mode === 'history' && !clock.follows?.('wind')
|
||||||
? t('Forecast · does not follow history')
|
? t('Forecast · does not follow history')
|
||||||
: null;
|
: null;
|
||||||
const valid = formatWindValidTime(manifest?.cycle?.validIso);
|
const valid = formatWindValidTime(manifest?.cycle?.validIso);
|
||||||
|
|||||||
@@ -454,3 +454,19 @@ test('a parameter replacement during manager enable does not roll the layer back
|
|||||||
assert.equal(layer.getStats().count, 4);
|
assert.equal(layer.getStats().count, 4);
|
||||||
await manager.destroyAll();
|
await manager.destroyAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('wind whose source follows the timeline drops the note that it does not follow the timeline', async () => {
|
||||||
|
const { createWeatherClock } = await import('../weather/clock.js');
|
||||||
|
const { createWorldClock } = await import('../../time/worldClock.js');
|
||||||
|
const world = createWorldClock();
|
||||||
|
const clock = createWeatherClock({ world });
|
||||||
|
const layer = createWindLayer({ feed: { getSnapshot: async () => snapshot('gfs') }, clock });
|
||||||
|
world.follow('wind');
|
||||||
|
await clock.setTarget('2026-09-14T12:00:00.000Z');
|
||||||
|
assert.equal(clock.getState().mode, 'history');
|
||||||
|
assert.doesNotMatch(layer.getRowControls().info, /does not follow history/);
|
||||||
|
world.follow('wind', false);
|
||||||
|
assert.match(layer.getRowControls().info, /Forecast · does not follow history/);
|
||||||
|
layer.destroy();
|
||||||
|
clock.destroy();
|
||||||
|
});
|
||||||
+24
-13
@@ -21,11 +21,12 @@ const utc = (time) =>
|
|||||||
? `${formatUtcDayMonth(time)} ${utcClock(time)}`
|
? `${formatUtcDayMonth(time)} ${utcClock(time)}`
|
||||||
: t('Unavailable');
|
: t('Unavailable');
|
||||||
const clockTime = (time) => utcClock(time) || t('Unavailable');
|
const clockTime = (time) => utcClock(time) || t('Unavailable');
|
||||||
const age = (time) => {
|
// Ages are measured from `nowMs`: the world clock's time at a past time, the
|
||||||
const minutes = Math.max(
|
// wall clock while live.
|
||||||
0,
|
const minutesBefore = (time, nowMs = Date.now()) =>
|
||||||
Math.floor((Date.now() - Date.parse(time)) / 60_000),
|
Math.max(0, Math.floor((nowMs - Date.parse(time)) / 60_000));
|
||||||
);
|
const age = (time, nowMs) => {
|
||||||
|
const minutes = minutesBefore(time, nowMs);
|
||||||
return minutes >= 60
|
return minutes >= 60
|
||||||
? t('{hours}h {minutes}m ago', {
|
? t('{hours}h {minutes}m ago', {
|
||||||
hours: Math.floor(minutes / 60),
|
hours: Math.floor(minutes / 60),
|
||||||
@@ -33,12 +34,21 @@ const age = (time) => {
|
|||||||
})
|
})
|
||||||
: t('{minutes}m ago', { minutes });
|
: t('{minutes}m ago', { minutes });
|
||||||
};
|
};
|
||||||
const historyTime = (time) =>
|
// A frame's time on the timeline: its age while live; at a past time, the
|
||||||
t('{time} · {minutes} min ago', {
|
// clock time alone, as the timeline time is the one it is measured from.
|
||||||
|
const historyTime = (time, state) =>
|
||||||
|
state?.mode === 'history'
|
||||||
|
? clockTime(time)
|
||||||
|
: t('{time} · {minutes} min ago', {
|
||||||
time: clockTime(time),
|
time: clockTime(time),
|
||||||
minutes: Math.max(0, Math.floor((Date.now() - Date.parse(time)) / 60_000)),
|
minutes: minutesBefore(time),
|
||||||
});
|
});
|
||||||
const dated = (time) => `${utc(time)} · ${age(time)}`;
|
const dated = (time, nowMs) => `${utc(time)} · ${age(time, nowMs)}`;
|
||||||
|
/** The time the observed products show: the timeline time, or now while live. */
|
||||||
|
const shownNow = (state) =>
|
||||||
|
state?.mode === 'history' && Number.isFinite(Date.parse(state.target))
|
||||||
|
? Date.parse(state.target)
|
||||||
|
: Date.now();
|
||||||
const set = (node, key, value) => {
|
const set = (node, key, value) => {
|
||||||
if (node[key] !== value) node[key] = value;
|
if (node[key] !== value) node[key] = value;
|
||||||
};
|
};
|
||||||
@@ -90,7 +100,7 @@ export function createWeatherPanel({
|
|||||||
},
|
},
|
||||||
transport: {
|
transport: {
|
||||||
onCommit: (tick) => clock?.setTarget(tick),
|
onCommit: (tick) => clock?.setTarget(tick),
|
||||||
onPreview: historyTime,
|
onPreview: (time) => historyTime(time, clock?.getState()),
|
||||||
onStep: (direction) => clock?.step(direction),
|
onStep: (direction) => clock?.step(direction),
|
||||||
onLatest: () => clock?.latest(),
|
onLatest: () => clock?.latest(),
|
||||||
onPlay: () => clock?.togglePlay(),
|
onPlay: () => clock?.togglePlay(),
|
||||||
@@ -149,7 +159,7 @@ export function createWeatherPanel({
|
|||||||
readout:
|
readout:
|
||||||
state.mode === 'latest'
|
state.mode === 'latest'
|
||||||
? t('LATEST · newest per product')
|
? t('LATEST · newest per product')
|
||||||
: historyTime(state.target),
|
: historyTime(state.target, state),
|
||||||
};
|
};
|
||||||
const models = active.map((entry) => {
|
const models = active.map((entry) => {
|
||||||
const { id, icon, summary, legend = [], list } = entry;
|
const { id, icon, summary, legend = [], list } = entry;
|
||||||
@@ -167,7 +177,7 @@ export function createWeatherPanel({
|
|||||||
? t('No frame within {gap} min of {time}', { gap, time })
|
? t('No frame within {gap} min of {time}', { gap, time })
|
||||||
: t('No frame within {gap} h of {time}', { gap: gap / 60, time });
|
: t('No frame within {gap} h of {time}', { gap: gap / 60, time });
|
||||||
} else if (shown) {
|
} else if (shown) {
|
||||||
detail = dated(shown);
|
detail = dated(shown, shownNow(state));
|
||||||
if (state.mode === 'history')
|
if (state.mode === 'history')
|
||||||
detail =
|
detail =
|
||||||
Date.parse(shown) === Date.parse(state.target)
|
Date.parse(shown) === Date.parse(state.target)
|
||||||
@@ -179,7 +189,8 @@ export function createWeatherPanel({
|
|||||||
valid: utc(summary.validTime),
|
valid: utc(summary.validTime),
|
||||||
issued: utc(summary.issuedTime),
|
issued: utc(summary.issuedTime),
|
||||||
});
|
});
|
||||||
if (state.mode === 'history')
|
// Unless its source follows the timeline, wind stays at the live edge.
|
||||||
|
if (state.mode === 'history' && !clock?.follows?.(id))
|
||||||
detail = t('{detail} · Does not follow history', { detail });
|
detail = t('{detail} · Does not follow history', { detail });
|
||||||
}
|
}
|
||||||
const lines = [
|
const lines = [
|
||||||
|
|||||||
@@ -506,9 +506,10 @@ test('compact lines show observation age, forecast validity, storm selection or
|
|||||||
'Forecast · valid 09-22 01:00 UTC',
|
'Forecast · valid 09-22 01:00 UTC',
|
||||||
);
|
);
|
||||||
f.state({ mode: 'history', target: ticks[1] });
|
f.state({ mode: 'history', target: ticks[1] });
|
||||||
|
// At a past time a frame's age counts from the timeline time.
|
||||||
assert.equal(
|
assert.equal(
|
||||||
compact(radar.id).textContent,
|
compact(radar.id).textContent,
|
||||||
'09-22 01:05 UTC · 8m ago · synced',
|
'09-22 01:05 UTC · 0m ago · synced',
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
compact(wind.id).textContent,
|
compact(wind.id).textContent,
|
||||||
@@ -523,7 +524,7 @@ test('compact lines show observation age, forecast validity, storm selection or
|
|||||||
});
|
});
|
||||||
assert.equal(
|
assert.equal(
|
||||||
compact(radar.id).textContent,
|
compact(radar.id).textContent,
|
||||||
'09-22 01:00 UTC · 13m ago · nearest',
|
'09-22 01:00 UTC · 5m ago · nearest',
|
||||||
);
|
);
|
||||||
clickHeader(f, wind.id);
|
clickHeader(f, wind.id);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@@ -787,3 +788,44 @@ test('source-supplied legend units are shown as given; catalog units are transla
|
|||||||
setLocale('en');
|
setLocale('en');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('at a past time, frame ages and the timeline readout count from the timeline time, not now', (t) => {
|
||||||
|
t.mock.timers.enable({
|
||||||
|
apis: ['Date'],
|
||||||
|
now: Date.parse('2032-01-01T00:00:00Z'),
|
||||||
|
});
|
||||||
|
const f = fixture();
|
||||||
|
const view = createWeatherPanel(f);
|
||||||
|
view.update([radar]);
|
||||||
|
f.state({
|
||||||
|
mode: 'history',
|
||||||
|
target: '2026-09-22T01:20:00Z',
|
||||||
|
products: [{ id: radar.id, shown: ticks[1], selected: ticks[1] }],
|
||||||
|
});
|
||||||
|
assert.equal(
|
||||||
|
line(f, radar.id, 'time').textContent,
|
||||||
|
'09-22 01:05 UTC · 15m ago · nearest',
|
||||||
|
);
|
||||||
|
const readout = f.find((n) => n.textContent === '01:20 UTC');
|
||||||
|
assert.ok(readout, 'the readout names the timeline time');
|
||||||
|
assert.doesNotMatch(timelineHost(f).textContent, /min ago/);
|
||||||
|
view.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the wind card notes it stays live only while its source does not follow the timeline', () => {
|
||||||
|
const f = fixture();
|
||||||
|
const following = new Set();
|
||||||
|
f.clock.follows = (id) => following.has(id);
|
||||||
|
const view = createWeatherPanel(f);
|
||||||
|
view.update([wind, radar]);
|
||||||
|
f.state({ mode: 'history', target: ticks[1] });
|
||||||
|
assert.match(line(f, 'wind', 'time').textContent, /Does not follow history/);
|
||||||
|
following.add('wind');
|
||||||
|
f.state({ target: ticks[0] });
|
||||||
|
assert.match(line(f, 'wind', 'time').textContent, /^Forecast · valid /);
|
||||||
|
assert.doesNotMatch(
|
||||||
|
line(f, 'wind', 'time').textContent,
|
||||||
|
/Does not follow history/,
|
||||||
|
);
|
||||||
|
view.destroy();
|
||||||
|
});
|
||||||
Reference in new issue
Block a user