mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
fix: keep a named place's own point in situation briefs
Brief sections received a named place as its bounding box, so they centered on the box's middle: Tokyo's aircraft were sorted from a point in the Pacific. Sections now receive the place name and resolve it like a direct query, and place lookups are cached briefly so a brief resolves it once.
This commit is contained in:
1 parent
1b3aa8de8b
commit
4af15aa6a9
5 files changed
+137
-21
No files matched your search
+29
-13
@@ -21,7 +21,9 @@ const SECTIONS = [
|
||||
label: 'Weather',
|
||||
tool: 'get_weather',
|
||||
args: (area, center) => ({
|
||||
location: { lat: center.lat, lon: center.lon },
|
||||
location: area.argument.place
|
||||
? { place: area.argument.place }
|
||||
: { lat: center.lat, lon: center.lon },
|
||||
}),
|
||||
},
|
||||
{
|
||||
@@ -93,19 +95,30 @@ function sectionFeedState(section) {
|
||||
: 'nominal';
|
||||
}
|
||||
|
||||
/** The resolved area, plus the argument sections receive in its place. */
|
||||
function sectionArea(resolved) {
|
||||
/**
|
||||
* The resolved area, plus the argument sections receive. A named place is
|
||||
* passed by name, so sections resolve it to the same point and label as a
|
||||
* direct query does (place lookups are cached).
|
||||
*/
|
||||
function sectionArea(resolved, original) {
|
||||
return {
|
||||
...resolved,
|
||||
argument: resolved.center
|
||||
? {
|
||||
lat: resolved.center.lat,
|
||||
lon: resolved.center.lon,
|
||||
radius_km: resolved.center.radiusKm,
|
||||
}
|
||||
: {
|
||||
bbox: [resolved.west, resolved.south, resolved.east, resolved.north],
|
||||
},
|
||||
argument: original?.place
|
||||
? { place: original.place }
|
||||
: resolved.center
|
||||
? {
|
||||
lat: resolved.center.lat,
|
||||
lon: resolved.center.lon,
|
||||
radius_km: resolved.center.radiusKm,
|
||||
}
|
||||
: {
|
||||
bbox: [
|
||||
resolved.west,
|
||||
resolved.south,
|
||||
resolved.east,
|
||||
resolved.north,
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -143,7 +156,10 @@ async function runSections(all, area, { tools, signal }) {
|
||||
|
||||
async function buildBrief(args, { services, signal, tools }) {
|
||||
// Sections receive the resolved box so a place name is looked up once.
|
||||
const area = sectionArea(await resolveArea(args.area, { services, signal }));
|
||||
const area = sectionArea(
|
||||
await resolveArea(args.area, { services, signal }),
|
||||
args.area,
|
||||
);
|
||||
const { center, answers, lines } = await runSections(SECTIONS, area, {
|
||||
tools,
|
||||
signal,
|
||||
|
||||
@@ -421,8 +421,8 @@ test('the situation brief combines available sections and marks failures', async
|
||||
});
|
||||
assert.equal(
|
||||
result.summary,
|
||||
'Situation in Austin, Texas: Weather at 30.3100, -97.7500: overcast, 26°C, wind 5 km/h. ' +
|
||||
'1 earthquake of M2.5+ in the last 24 hours in the requested box; strongest M3.1 near Austin.',
|
||||
'Situation in Austin, Texas: Weather at Austin, Texas: overcast, 26°C, wind 5 km/h. ' +
|
||||
'1 earthquake of M2.5+ in the last 24 hours in Austin, Texas; strongest M3.1 near Austin.',
|
||||
);
|
||||
assert.deepEqual(Object.keys(result.data.sections), [
|
||||
'weather',
|
||||
@@ -642,3 +642,26 @@ test('the HUD caption context carries each section feed state', async () => {
|
||||
assert.equal(sent[0].feedProvenance.overall, 'unavailable');
|
||||
assert.match(sent[0].feedProvenance.note, /Aircraft is STALE/);
|
||||
});
|
||||
|
||||
test('brief sections use a named place at its own point', async () => {
|
||||
const tokyo = {
|
||||
resolve: async () => ({
|
||||
name: 'Tokyo, Japan',
|
||||
point: { lat: 35.6769, lon: 139.7639 },
|
||||
bounds: { west: 135, south: 20, east: 155, north: 36 },
|
||||
}),
|
||||
};
|
||||
const queries = [];
|
||||
const aircraft = {
|
||||
getSnapshot: async (query) => {
|
||||
queries.push(query);
|
||||
return { records: [], complete: true, source: 'Test feed' };
|
||||
},
|
||||
};
|
||||
const result = await catalogWith({ weather, places: tokyo, aircraft }).call(
|
||||
'situation_brief',
|
||||
{ area: { place: 'Tokyo' } },
|
||||
);
|
||||
assert.deepEqual(queries[0], { latitude: 35.6769, longitude: 139.7639 });
|
||||
assert.match(result.data.sections.aircraft.summary, /in Tokyo, Japan\.$/);
|
||||
});
|
||||
Reference in new issue
Block a user