mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-06 11:24:00 +00:00
Merge main into PR #1390
This commit is contained in:
commit
f4b3517e9b
8 files changed
+100
-4
No files matched your search
@@ -152,7 +152,7 @@ export function localAdsbCardModel(
|
||||
t('ALT {altitude} FT · GS {speed} KT · TRK {track}', {
|
||||
altitude: grouped(altitude),
|
||||
speed: speed === null ? DASH : speed,
|
||||
track: track === null ? DASH : `${track}°`,
|
||||
track: track === null ? DASH : `${track % 360}°`,
|
||||
}),
|
||||
vertical === null
|
||||
? t('V/S {rate}', { rate: DASH })
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { setLocale } from '../../i18n/index.js';
|
||||
import { localAdsbCardModel } from './card.js';
|
||||
|
||||
test('a track of 359.7° reads TRK 0°, not TRK 360°', () => {
|
||||
setLocale('en');
|
||||
const { details } = localAdsbCardModel(
|
||||
{
|
||||
icao: 'abc123',
|
||||
altitudeFt: 12500,
|
||||
groundSpeedKt: 240,
|
||||
trackDeg: 359.7,
|
||||
lastPositionAt: 1000,
|
||||
},
|
||||
5000,
|
||||
);
|
||||
assert.equal(details[1], 'ALT 12,500 FT · GS 240 KT · TRK 0°');
|
||||
});
|
||||
@@ -5,6 +5,24 @@ import { defineTool, ToolError } from '../catalog.js';
|
||||
import { AREA_SCHEMA, areaContains, resolveArea } from '../area.js';
|
||||
import { LIMIT_SCHEMA, capRows, countNoun, isoTime } from '../results.js';
|
||||
|
||||
function acquiredMsUtc(acqDate, acqTime) {
|
||||
if (typeof acqDate !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(acqDate))
|
||||
return NaN;
|
||||
const timeText = String(acqTime ?? '').trim();
|
||||
if (!/^\d{1,4}$/.test(timeText)) return NaN;
|
||||
const hhmm = timeText.padStart(4, '0');
|
||||
const hours = Number(hhmm.slice(0, 2));
|
||||
const minutes = Number(hhmm.slice(2, 4));
|
||||
if (hours > 23 || minutes > 59) return NaN;
|
||||
const timestamp = Date.parse(
|
||||
`${acqDate}T${hhmm.slice(0, 2)}:${hhmm.slice(2, 4)}:00.000Z`,
|
||||
);
|
||||
return Number.isFinite(timestamp) &&
|
||||
new Date(timestamp).toISOString().slice(0, 10) === acqDate
|
||||
? timestamp
|
||||
: NaN;
|
||||
}
|
||||
|
||||
export const getEarthquakes = defineTool({
|
||||
name: 'get_earthquakes',
|
||||
title: 'Recent earthquakes',
|
||||
@@ -114,8 +132,7 @@ export const getActiveFires = defineTool({
|
||||
lon: fire.lon,
|
||||
frp_mw: fire.frp ?? null,
|
||||
confidence: fire.confidence ?? null,
|
||||
acquired:
|
||||
[fire.acqDate, fire.acqTime].filter(Boolean).join(' ') || null,
|
||||
acquired: isoTime(acquiredMsUtc(fire.acqDate, fire.acqTime)),
|
||||
satellite: fire.satellite ?? null,
|
||||
day_night: fire.daynight ?? null,
|
||||
})),
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { composeCatalog } from '../catalog.js';
|
||||
import { getActiveFires } from './hazards.js';
|
||||
|
||||
const catalogWith = (fires) =>
|
||||
composeCatalog({
|
||||
tools: [getActiveFires],
|
||||
services: { fires: { getSnapshot: async () => ({ fires }) } },
|
||||
});
|
||||
|
||||
test('a fire acquired at 00:45 UTC reads as 00:45, not "45"', async () => {
|
||||
const result = await catalogWith([
|
||||
{ lat: 24, lon: 121, frp: 5, acqDate: '2026-01-01', acqTime: '45' },
|
||||
]).call('get_active_fires', { area: { bbox: [120, 23, 122, 25] } });
|
||||
assert.equal(result.data.rows[0].acquired, '2026-01-01T00:45:00.000Z');
|
||||
});
|
||||
|
||||
test('fire acquisition timestamps reject impossible calendar dates', async () => {
|
||||
for (const acqDate of [
|
||||
'2026-02-29',
|
||||
'2026-02-30',
|
||||
'2026-04-31',
|
||||
'1900-02-29',
|
||||
'2026-13-01',
|
||||
'2026-01-00',
|
||||
]) {
|
||||
const result = await catalogWith([
|
||||
{ lat: 24, lon: 121, acqDate, acqTime: '45' },
|
||||
]).call('get_active_fires', { area: { bbox: [120, 23, 122, 25] } });
|
||||
assert.equal(result.data.rows[0].acquired, null, acqDate);
|
||||
}
|
||||
});
|
||||
|
||||
test('fire acquisition timestamps preserve valid leap days and UTC times', async () => {
|
||||
for (const [acqDate, acqTime, expected] of [
|
||||
['2024-02-29', '45', '2024-02-29T00:45:00.000Z'],
|
||||
['2000-02-29', 0, '2000-02-29T00:00:00.000Z'],
|
||||
['2026-04-30', '2359', '2026-04-30T23:59:00.000Z'],
|
||||
]) {
|
||||
const result = await catalogWith([
|
||||
{ lat: 24, lon: 121, acqDate, acqTime },
|
||||
]).call('get_active_fires', { area: { bbox: [120, 23, 122, 25] } });
|
||||
assert.equal(result.data.rows[0].acquired, expected);
|
||||
}
|
||||
});
|
||||
@@ -125,7 +125,7 @@ test('fires need an area and report a missing key as unavailable', async () => {
|
||||
result.data.rows.map((row) => row.frp_mw),
|
||||
[40, 12],
|
||||
);
|
||||
assert.equal(result.data.rows[1].acquired, '2026-01-01 0130');
|
||||
assert.equal(result.data.rows[1].acquired, '2026-01-01T01:30:00.000Z');
|
||||
|
||||
const keyless = composeCatalog({
|
||||
tools: coreTools,
|
||||
|
||||
Reference in new issue
Block a user