mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +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
+151
-21
No files matched your search
@@ -248,6 +248,12 @@ export function createWeatherClock({
|
||||
},
|
||||
getTimeline,
|
||||
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) {
|
||||
if (destroyed) return Promise.resolve(false);
|
||||
if (!Number.isFinite(Date.parse(time)))
|
||||
|
||||
@@ -120,9 +120,17 @@ export function createWeatherLayer({
|
||||
rendering?.cancelPrefetch?.();
|
||||
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 = () =>
|
||||
manifest?.latest &&
|
||||
Date.now() - Date.parse(manifest.latest) >
|
||||
worldNow() - Date.parse(manifest.latest) >
|
||||
(product === 'clouds' ? 240 : lightning ? 45 : 20) * 60_000;
|
||||
const stop = () => {
|
||||
if (clock) return;
|
||||
@@ -573,7 +581,7 @@ export function createWeatherLayer({
|
||||
const index = times.indexOf(time);
|
||||
const current = index >= 0;
|
||||
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;
|
||||
const lag =
|
||||
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(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);
|
||||
});
|
||||
Reference in new issue
Block a user