mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
Merge PR #1395 contribution for review
This commit is contained in:
commit
5ae18032fc
4 files changed
+37
-3
No files matched your search
@@ -0,0 +1,4 @@
|
||||
- Report a fire detection's acquisition time as a UTC timestamp in
|
||||
`get_active_fires`. The tool joined FIRMS's unpadded date and time, so a
|
||||
00:45 UTC detection read "2026-01-01 45"; it now reads
|
||||
`2026-01-01T00:45:00.000Z` (Rudy Celekli, @rudycelekli, #1395).
|
||||
@@ -5,6 +5,20 @@ 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;
|
||||
return Date.parse(
|
||||
`${acqDate}T${hhmm.slice(0, 2)}:${hhmm.slice(2, 4)}:00.000Z`,
|
||||
);
|
||||
}
|
||||
|
||||
export const getEarthquakes = defineTool({
|
||||
name: 'get_earthquakes',
|
||||
title: 'Recent earthquakes',
|
||||
@@ -114,8 +128,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,17 @@
|
||||
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');
|
||||
});
|
||||
@@ -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