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
@@ -4,6 +4,52 @@ export const RADAR_MAX_GAP_MS = 30 * 60_000;
|
||||
export const REGIONAL_INFRARED_MAX_GAP_MS = 30 * 60_000;
|
||||
export const GLOBAL_INFRARED_MAX_GAP_MS = 3 * 60 * 60_000;
|
||||
export const LIGHTNING_MAX_GAP_MS = 30 * 60_000;
|
||||
/** How many of a feed's latest frames say how far apart its frames come. */
|
||||
const SPACING_FRAMES = 12;
|
||||
/** A frame holds this many of its feed's frame spacings before it lapses. */
|
||||
const SPACING_SLACK = 1.5;
|
||||
|
||||
/**
|
||||
* How far apart a feed's frames come: the median spacing of its latest
|
||||
* frames, in ms, or null with fewer than two. Takes UTC times or epoch ms.
|
||||
* @param {Array<string|number>} times
|
||||
* @returns {number|null}
|
||||
*/
|
||||
export function frameSpacingMs(times) {
|
||||
const at = [
|
||||
...new Set(
|
||||
(times ?? [])
|
||||
.map((time) => (typeof time === 'number' ? time : Date.parse(time)))
|
||||
.filter(Number.isFinite),
|
||||
),
|
||||
]
|
||||
.sort((a, b) => a - b)
|
||||
.slice(-(SPACING_FRAMES + 1));
|
||||
if (at.length < 2) return null;
|
||||
const gaps = at
|
||||
.slice(1)
|
||||
.map((time, i) => time - at[i])
|
||||
.sort((a, b) => a - b);
|
||||
const middle = gaps.length >> 1;
|
||||
return gaps.length % 2 ? gaps[middle] : (gaps[middle - 1] + gaps[middle]) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* A product's least time, `leastMs`, held to its feed's own frame spacing:
|
||||
* never less than one and a half spacings, so a feed whose frames come an
|
||||
* hour apart covers the whole hour between them, while one with frames
|
||||
* minutes apart keeps `leastMs`.
|
||||
* @param {number} leastMs
|
||||
* @param {Array<string|number>} times
|
||||
* @returns {number}
|
||||
*/
|
||||
export function atLeastFrameSpacing(leastMs, times) {
|
||||
const spacing = frameSpacingMs(times);
|
||||
return spacing === null
|
||||
? leastMs
|
||||
: Math.max(leastMs, spacing * SPACING_SLACK);
|
||||
}
|
||||
|
||||
/** The longest play waits on a frame before it goes on without it. */
|
||||
export const PLAY_WAIT_MS = 8_000;
|
||||
// Playing on its own, the world does not wait on the frame it is at: that
|
||||
|
||||
@@ -7,6 +7,8 @@ import {
|
||||
GLOBAL_INFRARED_MAX_GAP_MS,
|
||||
LIGHTNING_MAX_GAP_MS,
|
||||
PLAY_WAIT_MS,
|
||||
frameSpacingMs,
|
||||
atLeastFrameSpacing,
|
||||
} from './clock.js';
|
||||
import { createWorldClock } from '../../time/worldClock.js';
|
||||
|
||||
@@ -94,6 +96,68 @@ test('union excludes suspended products; nearest selection never uses future or
|
||||
assert.equal(LIGHTNING_MAX_GAP_MS, 30 * 60_000);
|
||||
});
|
||||
|
||||
test('a feed’s frame spacing is the median of its latest frames', () => {
|
||||
assert.equal(frameSpacingMs([]), null);
|
||||
assert.equal(frameSpacingMs([time(0)]), null);
|
||||
assert.equal(frameSpacingMs([0, 10, 20, 30].map(time)), 10 * 60_000);
|
||||
// Out of order, repeated, unparseable, and one late frame among many.
|
||||
assert.equal(
|
||||
frameSpacingMs([
|
||||
time(60),
|
||||
time(0),
|
||||
'never',
|
||||
time(0),
|
||||
time(10),
|
||||
time(20),
|
||||
time(30),
|
||||
]),
|
||||
10 * 60_000,
|
||||
);
|
||||
assert.equal(frameSpacingMs([0, 60, 120].map(time)), 60 * 60_000);
|
||||
assert.equal(frameSpacingMs([0, 10, 70, 130]), 60);
|
||||
// Only the latest frames count: an hourly start gives way to ten minutes.
|
||||
const times = [
|
||||
...[-600, -540, -480, -420, -360, -300, -240, -180, -120, -60],
|
||||
...[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120],
|
||||
].map(time);
|
||||
assert.equal(frameSpacingMs(times), 10 * 60_000);
|
||||
});
|
||||
|
||||
test('a product’s gap is at least one and a half of its feed’s frame spacings', (t) => {
|
||||
const tenMinutes = [0, 10, 20, 30].map(time);
|
||||
const hourly = [0, 60, 120].map(time);
|
||||
assert.equal(
|
||||
atLeastFrameSpacing(REGIONAL_INFRARED_MAX_GAP_MS, tenMinutes),
|
||||
REGIONAL_INFRARED_MAX_GAP_MS,
|
||||
'frames minutes apart keep the product’s own gap',
|
||||
);
|
||||
assert.equal(
|
||||
atLeastFrameSpacing(REGIONAL_INFRARED_MAX_GAP_MS, hourly),
|
||||
90 * 60_000,
|
||||
);
|
||||
assert.equal(
|
||||
atLeastFrameSpacing(REGIONAL_INFRARED_MAX_GAP_MS, [time(0)]),
|
||||
REGIONAL_INFRARED_MAX_GAP_MS,
|
||||
);
|
||||
assert.equal(
|
||||
atLeastFrameSpacing(GLOBAL_INFRARED_MAX_GAP_MS, hourly),
|
||||
GLOBAL_INFRARED_MAX_GAP_MS,
|
||||
);
|
||||
|
||||
// Selected against it, an hourly feed has a frame all through each hour.
|
||||
const { clock } = harness(t);
|
||||
const clouds = product(
|
||||
'clouds',
|
||||
[0, 60, 120],
|
||||
atLeastFrameSpacing(REGIONAL_INFRARED_MAX_GAP_MS, hourly),
|
||||
);
|
||||
clock.register(clouds);
|
||||
assert.equal(clock.selectFor('clouds', time(45)), time(0));
|
||||
assert.equal(clock.selectFor('clouds', time(119)), time(60));
|
||||
assert.equal(clock.selectFor('clouds', time(210)), time(120));
|
||||
assert.equal(clock.selectFor('clouds', time(211)), null);
|
||||
});
|
||||
|
||||
test('history applies per-product selections, including null; latest restores unequal newest times', async (t) => {
|
||||
const { clock } = harness(t);
|
||||
const radar = product('radar', [0, 10, 20]);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
REGIONAL_INFRARED_MAX_GAP_MS,
|
||||
GLOBAL_INFRARED_MAX_GAP_MS,
|
||||
LIGHTNING_MAX_GAP_MS,
|
||||
atLeastFrameSpacing,
|
||||
} from './clock.js';
|
||||
import { formatUtcDayMonth, t, msg } from '../../i18n/index.js';
|
||||
import { formatScaleLabel } from '../../ui/unitLabels.js';
|
||||
@@ -102,7 +103,10 @@ export function createWeatherLayer({
|
||||
let unregisterClock = null;
|
||||
let frameRequest = null;
|
||||
let noFrame = false;
|
||||
const maxGap = () =>
|
||||
// A product's own gap, and the delay after which its latest frame reads
|
||||
// late. A feed whose frames come further apart holds each frame, and waits
|
||||
// for the next, as long as its frames are apart (see atLeastFrameSpacing).
|
||||
const productGap = () =>
|
||||
radar
|
||||
? RADAR_MAX_GAP_MS
|
||||
: lightning
|
||||
@@ -110,6 +114,23 @@ export function createWeatherLayer({
|
||||
: product === 'clouds'
|
||||
? GLOBAL_INFRARED_MAX_GAP_MS
|
||||
: REGIONAL_INFRARED_MAX_GAP_MS;
|
||||
const productDelay = () =>
|
||||
(product === 'clouds' ? 240 : lightning ? 45 : 20) * 60_000;
|
||||
// Read for every frame a selection weighs, so worked out once per product
|
||||
// and frame list.
|
||||
let spaced = null;
|
||||
const spacedTimes = () => {
|
||||
const times = manifest?.times ?? [];
|
||||
if (spaced?.times !== times || spaced?.product !== product)
|
||||
spaced = {
|
||||
times,
|
||||
product,
|
||||
gap: atLeastFrameSpacing(productGap(), times),
|
||||
delay: atLeastFrameSpacing(productDelay(), times),
|
||||
};
|
||||
return spaced;
|
||||
};
|
||||
const maxGap = () => spacedTimes().gap;
|
||||
const isLatest = () =>
|
||||
clock ? clock.getState().mode === 'latest' : followLatest;
|
||||
const getHost = () => imageryHost?.() ?? globeImageryHost(viewer);
|
||||
@@ -130,8 +151,7 @@ export function createWeatherLayer({
|
||||
};
|
||||
const observationDelayed = () =>
|
||||
manifest?.latest &&
|
||||
worldNow() - Date.parse(manifest.latest) >
|
||||
(product === 'clouds' ? 240 : lightning ? 45 : 20) * 60_000;
|
||||
worldNow() - Date.parse(manifest.latest) > spacedTimes().delay;
|
||||
const stop = () => {
|
||||
if (clock) return;
|
||||
playing = false;
|
||||
@@ -560,11 +580,11 @@ export function createWeatherLayer({
|
||||
shared.products.find((entry) => entry.id === id)?.selected === null
|
||||
? maxGap() / 60_000 < 60
|
||||
? t('No frame within {gap} min of {time}', {
|
||||
gap: maxGap() / 60_000,
|
||||
gap: Math.round(maxGap() / 60_000),
|
||||
time: utc(shared.target),
|
||||
})
|
||||
: t('No frame within {gap} h of {time}', {
|
||||
gap: maxGap() / 3600_000,
|
||||
gap: Math.round(maxGap() / 360_000) / 10,
|
||||
time: utc(shared.target),
|
||||
})
|
||||
: null;
|
||||
@@ -699,7 +719,7 @@ export function createWeatherLayer({
|
||||
? t('Global · 60°S–60°N')
|
||||
: t('North America')),
|
||||
shownTime: time,
|
||||
maxGapMinutes: maxGap() / 60_000,
|
||||
maxGapMinutes: Math.round(maxGap() / 60_000),
|
||||
detail,
|
||||
status:
|
||||
missing ||
|
||||
|
||||
@@ -1986,6 +1986,69 @@ test('satellite global selection uses the three-hour gap and preserves the share
|
||||
assert.equal(params.target, undefined);
|
||||
});
|
||||
|
||||
test('satellite clouds from an hourly feed draw all through each hour and read late only past it', async (t) => {
|
||||
const clock = createWeatherClock();
|
||||
const now = Date.now();
|
||||
const hour = 3_600_000;
|
||||
const top = Math.floor(now / hour) * hour;
|
||||
// Frames an hour apart, the latest forty minutes old.
|
||||
const hourly = [3, 2, 1].map((back) =>
|
||||
new Date(top - back * hour + 20 * 60_000).toISOString(),
|
||||
);
|
||||
const latest = hourly.at(-1);
|
||||
const h = layerHarness({
|
||||
clock,
|
||||
id: 'weather-satellite',
|
||||
feed: {
|
||||
getSnapshot: async ({ product }) => ({
|
||||
...snapshot,
|
||||
product,
|
||||
times: hourly,
|
||||
latest,
|
||||
}),
|
||||
},
|
||||
});
|
||||
t.after(() => {
|
||||
h.layer.destroy();
|
||||
clock.destroy();
|
||||
});
|
||||
t.mock.method(Date, 'now', () => Date.parse(latest) + 40 * 60_000);
|
||||
const update = h.layer.update();
|
||||
await flush();
|
||||
h.stages.at(-1).finish();
|
||||
await update;
|
||||
assert.equal(h.layer.getParams().product, 'clouds-regional');
|
||||
assert.equal(h.layer.getRowControls().summary.maxGapMinutes, 90);
|
||||
assert.equal(
|
||||
h.layer.getStats().stale,
|
||||
false,
|
||||
'forty minutes is within the hour',
|
||||
);
|
||||
|
||||
// Forty-five minutes past a frame, between it and the next, it still shows.
|
||||
const between = clock.setTarget(
|
||||
new Date(Date.parse(hourly[0]) + 45 * 60_000).toISOString(),
|
||||
);
|
||||
await flush();
|
||||
h.stages.at(-1).finish();
|
||||
await between;
|
||||
assert.equal(h.layer.getDiagnostics().hidden, false);
|
||||
assert.equal(h.stages.at(-1).time, hourly[0]);
|
||||
|
||||
// Live again (a past time judges delay from the timeline's time), past
|
||||
// one and a half hours it reads late.
|
||||
const live = clock.latest();
|
||||
await flush();
|
||||
h.stages.at(-1).finish();
|
||||
await live;
|
||||
t.mock.method(Date, 'now', () => Date.parse(latest) + 100 * 60_000);
|
||||
assert.equal(
|
||||
h.layer.getStats().stale,
|
||||
true,
|
||||
'past one and a half hours, late',
|
||||
);
|
||||
});
|
||||
|
||||
test('switching to history cancels a still-loading latest refresh and a later target cancels the first history load', async (t) => {
|
||||
const clock = createWeatherClock();
|
||||
const h = layerHarness({ clock });
|
||||
|
||||
Reference in new issue
Block a user