mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-15 15:52:21 +00:00
fix(fires): parse the detection time inside the tools package
The tools package cannot import firmsCsv. Pad the FIRMS clock here so 00:45 UTC still reads as 00:45.
This commit is contained in:
1 parent
57df5f61ba
commit
224d71753b
1 file changed
+15
-2
@@ -1,11 +1,24 @@
|
|||||||
/** Natural hazard queries: earthquakes and active fires. */
|
/** Natural hazard queries: earthquakes and active fires. */
|
||||||
|
|
||||||
import { acquisitionMsUtc } from '../../data/firmsCsv.js';
|
|
||||||
import { suggestView } from '../views.js';
|
import { suggestView } from '../views.js';
|
||||||
import { defineTool, ToolError } from '../catalog.js';
|
import { defineTool, ToolError } from '../catalog.js';
|
||||||
import { AREA_SCHEMA, areaContains, resolveArea } from '../area.js';
|
import { AREA_SCHEMA, areaContains, resolveArea } from '../area.js';
|
||||||
import { LIMIT_SCHEMA, capRows, countNoun, isoTime } from '../results.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({
|
export const getEarthquakes = defineTool({
|
||||||
name: 'get_earthquakes',
|
name: 'get_earthquakes',
|
||||||
title: 'Recent earthquakes',
|
title: 'Recent earthquakes',
|
||||||
@@ -115,7 +128,7 @@ export const getActiveFires = defineTool({
|
|||||||
lon: fire.lon,
|
lon: fire.lon,
|
||||||
frp_mw: fire.frp ?? null,
|
frp_mw: fire.frp ?? null,
|
||||||
confidence: fire.confidence ?? null,
|
confidence: fire.confidence ?? null,
|
||||||
acquired: isoTime(acquisitionMsUtc(fire.acqDate, fire.acqTime)),
|
acquired: isoTime(acquiredMsUtc(fire.acqDate, fire.acqTime)),
|
||||||
satellite: fire.satellite ?? null,
|
satellite: fire.satellite ?? null,
|
||||||
day_night: fire.daynight ?? null,
|
day_night: fire.daynight ?? null,
|
||||||
})),
|
})),
|
||||||
|
|||||||
Reference in new issue
Block a user