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
+26
-15
@@ -21,11 +21,12 @@ const utc = (time) =>
|
||||
? `${formatUtcDayMonth(time)} ${utcClock(time)}`
|
||||
: t('Unavailable');
|
||||
const clockTime = (time) => utcClock(time) || t('Unavailable');
|
||||
const age = (time) => {
|
||||
const minutes = Math.max(
|
||||
0,
|
||||
Math.floor((Date.now() - Date.parse(time)) / 60_000),
|
||||
);
|
||||
// Ages are measured from `nowMs`: the world clock's time at a past time, the
|
||||
// wall clock while live.
|
||||
const minutesBefore = (time, nowMs = Date.now()) =>
|
||||
Math.max(0, Math.floor((nowMs - Date.parse(time)) / 60_000));
|
||||
const age = (time, nowMs) => {
|
||||
const minutes = minutesBefore(time, nowMs);
|
||||
return minutes >= 60
|
||||
? t('{hours}h {minutes}m ago', {
|
||||
hours: Math.floor(minutes / 60),
|
||||
@@ -33,12 +34,21 @@ const age = (time) => {
|
||||
})
|
||||
: t('{minutes}m ago', { minutes });
|
||||
};
|
||||
const historyTime = (time) =>
|
||||
t('{time} · {minutes} min ago', {
|
||||
time: clockTime(time),
|
||||
minutes: Math.max(0, Math.floor((Date.now() - Date.parse(time)) / 60_000)),
|
||||
});
|
||||
const dated = (time) => `${utc(time)} · ${age(time)}`;
|
||||
// A frame's time on the timeline: its age while live; at a past time, the
|
||||
// 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),
|
||||
minutes: minutesBefore(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) => {
|
||||
if (node[key] !== value) node[key] = value;
|
||||
};
|
||||
@@ -90,7 +100,7 @@ export function createWeatherPanel({
|
||||
},
|
||||
transport: {
|
||||
onCommit: (tick) => clock?.setTarget(tick),
|
||||
onPreview: historyTime,
|
||||
onPreview: (time) => historyTime(time, clock?.getState()),
|
||||
onStep: (direction) => clock?.step(direction),
|
||||
onLatest: () => clock?.latest(),
|
||||
onPlay: () => clock?.togglePlay(),
|
||||
@@ -149,7 +159,7 @@ export function createWeatherPanel({
|
||||
readout:
|
||||
state.mode === 'latest'
|
||||
? t('LATEST · newest per product')
|
||||
: historyTime(state.target),
|
||||
: historyTime(state.target, state),
|
||||
};
|
||||
const models = active.map((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} h of {time}', { gap: gap / 60, time });
|
||||
} else if (shown) {
|
||||
detail = dated(shown);
|
||||
detail = dated(shown, shownNow(state));
|
||||
if (state.mode === 'history')
|
||||
detail =
|
||||
Date.parse(shown) === Date.parse(state.target)
|
||||
@@ -179,7 +189,8 @@ export function createWeatherPanel({
|
||||
valid: utc(summary.validTime),
|
||||
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 });
|
||||
}
|
||||
const lines = [
|
||||
|
||||
@@ -506,9 +506,10 @@ test('compact lines show observation age, forecast validity, storm selection or
|
||||
'Forecast · valid 09-22 01:00 UTC',
|
||||
);
|
||||
f.state({ mode: 'history', target: ticks[1] });
|
||||
// At a past time a frame's age counts from the timeline time.
|
||||
assert.equal(
|
||||
compact(radar.id).textContent,
|
||||
'09-22 01:05 UTC · 8m ago · synced',
|
||||
'09-22 01:05 UTC · 0m ago · synced',
|
||||
);
|
||||
assert.equal(
|
||||
compact(wind.id).textContent,
|
||||
@@ -523,7 +524,7 @@ test('compact lines show observation age, forecast validity, storm selection or
|
||||
});
|
||||
assert.equal(
|
||||
compact(radar.id).textContent,
|
||||
'09-22 01:00 UTC · 13m ago · nearest',
|
||||
'09-22 01:00 UTC · 5m ago · nearest',
|
||||
);
|
||||
clickHeader(f, wind.id);
|
||||
assert.equal(
|
||||
@@ -787,3 +788,44 @@ test('source-supplied legend units are shown as given; catalog units are transla
|
||||
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