Fallout: say a forecast's last hour is held only when it is; check kept climatology months (#1016)

The winds follow the burst hour chosen, so an out-of-date forecast's last hour is held for the
whole simulation only when it is the hour chosen; otherwise from when the chosen hour's 48 hours
pass it, or not at all.  The panel now says just that, and says separately that the forecast is
out of date.

A kept climatology month is hashed against its pinned sha256 before it is listed or served (again
only once it changes); one that is not what is expected is fetched again.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-11-25 12:19:33 -07:00 • committed by Roland
parent d4d288f84a
commit 3ae978dc53
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
4 changed files with 69 additions and 16 deletions

View file

@ -1000,19 +1000,25 @@ export function Timeline({after, onAfter, playing, onPlaying, startMs}) {
</div>;
}
// Whether the forecast's winds run out before the fallout of bursts at `hour` is down: a warning
// saying so, or null.
// A warning about the forecast for bursts at its hour `hour` (an index), or null: whether it is out of
// date, and whether its winds run out before their fallout is down. The winds follow the hour chosen,
// so the last hour is held for the whole simulation only when it is the hour chosen.
export function forecastShortText(forecast, hour) {
if (!forecast) return null;
const last = forecast.hours.length - 1;
let held = null;
if (hour >= last) {
held = "Its last hour's winds are held for the whole simulation.";
} else if (forecastRunsOut(forecast, hour) !== null) {
held = `It ends at ${hourLabel(forecast.hours[last], false)}, before all the fallout is down: `
+ "its last hour's winds are held from then on.";
}
if (forecastExpired(forecast)) {
return "This forecast has run out: its last hour's winds are held for the whole simulation. "
+ "Download a new one on the map's Manage tab, or use one wind at every height.";
return ["This forecast is out of date: its winds are past ones, not today's.", held,
"Download a new one on the map's Manage tab, or use one wind at every height."]
.filter(Boolean).join(" ");
}
if (forecastRunsOut(forecast, hour) !== null) {
return `This forecast ends at ${hourLabel(forecast.hours[forecast.hours.length - 1], false)}, before `
+ "all the fallout is down: its last hour's winds are held from then on.";
}
return null;
return held && `This forecast is short. ${held}`;
}
// The forecast winds aloft: which hour, how old, where they reach, and whether they last until the

View file

@ -328,12 +328,22 @@ describe('the forecast\'s warning', () => {
const hourMs = Math.floor(Date.now() / 3600000) * 3600000;
const of = (from, count) => ({hours: Array.from({length: count}, (_, h) => new Date(hourMs + (from + h) * 3600000).toISOString())});
test('says when it has run out, or ends before the fallout is down, and else nothing', () => {
test('says when it is out of date, or ends before the fallout is down, and else nothing', () => {
expect(forecastShortText(null, 0)).toBeNull();
expect(forecastShortText(of(-30, 10), 9)).toMatch(/has run out/);
expect(forecastShortText(of(-30, 10), 9)).toMatch(/out of date.*last hour's winds are held for the whole simulation/);
expect(forecastShortText(of(-1, 30), 1)).toMatch(/ends at .*, before all the fallout is down/);
expect(forecastShortText(of(-1, 96), 1)).toBeNull();
});
test('says the last hour is held only from when it is, for the hour chosen', () => {
// Out of date, but its first hour still has 48 hours of winds after it: none is held.
const old = of(-200, 96);
expect(forecastShortText(old, 0)).toMatch(/out of date/);
expect(forecastShortText(old, 0)).not.toMatch(/held/);
expect(forecastShortText(old, 60)).toMatch(/held from then on/);
expect(forecastShortText(old, 60)).not.toMatch(/whole simulation/);
expect(forecastShortText(old, 95)).toMatch(/held for the whole simulation/);
});
});
describe('the targets simulated', () => {
@ -543,9 +553,9 @@ describe('the fallout panel\'s steps', () => {
await act(async () => new Promise((r) => setTimeout(r, 50)));
fireEvent.click(screen.getByRole('textbox', {name: 'Wind'}));
fireEvent.click([...document.querySelectorAll('[role=option]')].find((o) => o.textContent === 'Forecast winds aloft'));
expect(screen.getByText(/This forecast has run out: its last hour's winds are held/)).toBeTruthy();
expect(screen.getByText(/This forecast is out of date: .*last hour's winds are held/)).toBeTruthy();
fireEvent.click(screen.getByRole('button', {name: 'Next: the fallout'}));
expect(screen.getByText(/This forecast has run out/)).toBeTruthy();
expect(screen.getByText(/This forecast is out of date/)).toBeTruthy();
} finally {
mockLatestWinds = null;
}

View file

@ -56,12 +56,31 @@ def month_name(month: int) -> str:
return f'month-{month:02d}.bin.gz'
# The kept files found to be what is expected: path -> (size, mtime) when hashed.
_checked = dict()
def month_path(month: int) -> Optional[Path]:
"""The kept file of `month`, or None."""
if month not in MONTHS:
"""The kept file of `month`, or None if there is none, or it is not the file expected (it is then
fetched again). A file is hashed again only after it changes."""
expected = MONTHS.get(month)
if not expected:
return None
path = climatology_directory() / month_name(month)
return path if path.is_file() else None
try:
stat = path.stat()
except FileNotFoundError:
return None
if _checked.get(path) == (stat.st_size, stat.st_mtime_ns):
return path
with path.open('rb') as fh:
actual = hashlib.file_digest(fh, 'sha256').hexdigest()
if actual != expected:
_checked.pop(path, None)
logger.warning(f'{path} is not the climatology expected (sha256 {actual}); it will be fetched again')
return None
_checked[path] = (stat.st_size, stat.st_mtime_ns)
return path
def months_kept() -> List[int]:

View file

@ -116,3 +116,21 @@ async def test_worker_waits_for_internet_and_drive(test_directory, published, fl
flags.media_mounted.set()
await asyncio.wait_for(worker, timeout=5)
fetch.assert_awaited_once()
@pytest.mark.asyncio
async def test_month_kept_must_be_what_is_expected(test_directory, published):
"""A kept month that is changed, or replaced, is not listed or served, and is fetched again."""
data, bodies = published
get, asked = fake_get(bodies)
with mock.patch('modules.map.climatology.aiohttp_get', get), mock.patch('modules.map.climatology.asyncio.sleep'):
await climatology.fetch_missing()
path = climatology.month_path(1)
assert path
path.write_bytes(gzip.compress(b'WFCL another month'))
assert climatology.month_path(1) is None
assert climatology.months_kept() == [2]
assert await climatology.fetch_missing() == [1]
assert climatology.month_path(1).read_bytes() == data[1]