mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Show transit vehicle facts, motion and a fleet breakdown in Context
A transit vehicle picked on the map now finds its record in Context (the click carries the feed and vehicle key), so the card shows its operator, place, route, report age and the operator's last reported state in plain words. The layer card breaks transit in view down by motion (moving, stopped, waiting for an update, no recent fix), mode, operator, last reported state and crowding where the feed has it; vehicle-position feeds carry no timetable, so early or late is not shown. Rows in the in-view list carry a motion icon.
This commit is contained in:
1 parent
5c580cbd4a
commit
0fe6fd2bb8
6 files changed
+159
-5
No files matched your search
+1
-1
@@ -26,7 +26,7 @@
|
||||
with the sources: src/materialSymbolsSubset.test.mjs fails when a source
|
||||
names a glyph this list is missing, because a missing glyph does not draw
|
||||
a box — the ligature never forms and the element renders the literal word. -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20,400,0,0&icon_names=adjust,align_horizontal_left,align_horizontal_right,arrow_drop_down,arrow_forward,arrow_left,arrow_right,bolt,bug_report,category,chevron_left,chevron_right,close,close_fullscreen,dark_mode,delete,directions_boat,draw,east,eco,egg_alt,filter_list,flare,flight,handyman,layers,layers_clear,light_mode,local_fire_department,location_on,more_horiz,movie,my_location,navigation,normal,on,open_in_full,palette,partly_cloudy_day,pause,pentagon,pest_control,pets,play_arrow,public,question_mark,radar,radio,radio_button_checked,radio_button_unchecked,raven,restart_alt,right_panel_close,right_panel_open,rocket_launch,satellite_alt,search,set_meal,settings,skip_next,skip_previous,streetview,timeline,traffic,tune,umbrella,upload_file,videocam,view_in_ar,visibility,visibility_off,water_drop,zoom_in_map" rel="stylesheet" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20,400,0,0&icon_names=add,adjust,ads_click,air,airline_seat_recline_normal,align_horizontal_left,align_horizontal_right,arrow_drop_down,arrow_forward,arrow_left,arrow_right,bolt,bug_report,category,chevron_left,chevron_right,close,close_fullscreen,cloud,cyclone,dark_mode,delete,directions_boat,draw,earthquake,east,eco,egg_alt,emergency_home,factory,filter_list,flare,flight,foggy,handyman,history,label,layers,layers_clear,light_mode,local_fire_department,location_city,location_off,location_on,more_horiz,movie,my_location,navigation,newspaper,normal,on,open_in_full,palette,partly_cloudy_day,pause,pedal_bike,pentagon,pest_control,pets,play_arrow,public,question_mark,radar,radio,radio_button_checked,radio_button_unchecked,rainy,raven,restart_alt,right_panel_close,right_panel_open,rocket_launch,satellite_alt,schedule,search,set_meal,settings,skip_next,skip_previous,star,streetview,sunny,thunderstorm,timeline,traffic,train,travel_explore,tune,umbrella,upload_file,videocam,view_in_ar,visibility,visibility_off,warning,water_drop,weather_snowy,zoom_in_map" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="gev-view" data-gev-view="scene-chrome"></div>
|
||||
|
||||
@@ -53,7 +53,9 @@ const TITLE_FIELDS = [
|
||||
'registration',
|
||||
];
|
||||
/** Fields that identify an item, for matching a click or a search. */
|
||||
const KEY_FIELDS = ['icao24', 'mmsi', 'noradId', 'usgsId', 'id'];
|
||||
// `key` is a layer's own key where it differs from the record's id (a
|
||||
// transit vehicle is keyed by feed and vehicle, and named by its fleet number).
|
||||
const KEY_FIELDS = ['icao24', 'mmsi', 'noradId', 'usgsId', 'id', 'key'];
|
||||
/**
|
||||
* How many records to ask a layer for when all are wanted. Layers read a
|
||||
* missing or unbounded count as their own small default, so this is a number
|
||||
@@ -103,6 +105,7 @@ const HIDDEN_FACTS = new Set([
|
||||
'scale',
|
||||
'routeId',
|
||||
'building',
|
||||
'key',
|
||||
]);
|
||||
|
||||
/** Facts that lead the list when a record has them, in this order. */
|
||||
@@ -318,6 +321,27 @@ const isEpochMs = (value) =>
|
||||
*/
|
||||
/** Codes the feeds use, in words. */
|
||||
const CODE_WORDS = Object.freeze({
|
||||
motion: {
|
||||
moving: 'Moving',
|
||||
stopped: 'Stopped',
|
||||
waiting: 'Waiting for update',
|
||||
'no-fix': 'No recent fix',
|
||||
},
|
||||
// GTFS-RT vehicle states, as the operator last reported them.
|
||||
status: {
|
||||
IN_TRANSIT_TO: 'Heading to next stop',
|
||||
INCOMING_AT: 'Arriving at a stop',
|
||||
STOPPED_AT: 'Stopped at a stop',
|
||||
},
|
||||
occupancy: {
|
||||
EMPTY: 'Empty',
|
||||
MANY_SEATS_AVAILABLE: 'Many seats free',
|
||||
FEW_SEATS_AVAILABLE: 'Few seats free',
|
||||
STANDING_ROOM_ONLY: 'Standing room only',
|
||||
CRUSHED_STANDING_ROOM_ONLY: 'Crowded',
|
||||
FULL: 'Full',
|
||||
NOT_ACCEPTING_PASSENGERS: 'Not taking passengers',
|
||||
},
|
||||
classification: {
|
||||
TD: 'Tropical depression',
|
||||
TS: 'Tropical storm',
|
||||
@@ -995,7 +1019,7 @@ const AIRCRAFT_CLASS_NAMES = {
|
||||
*/
|
||||
export function layerBreakdown(dataManager, layerId, { rect = null } = {}) {
|
||||
const kind = entityKind(layerId).kind;
|
||||
if (!['aircraft', 'vessel', 'satellite', 'earthquake'].includes(kind)) return null;
|
||||
if (!['aircraft', 'vessel', 'satellite', 'earthquake', 'vehicle'].includes(kind)) return null;
|
||||
let records = layerRecords(dataManager, layerId);
|
||||
if (rect) {
|
||||
const wraps = rect.west > rect.east;
|
||||
@@ -1024,6 +1048,22 @@ export function layerBreakdown(dataManager, layerId, { rect = null } = {}) {
|
||||
splits.push({ title: 'Type', parts: tallyBy(records, (record) => AIRCRAFT_CLASS_NAMES[record.aircraftClass] || plainWord(text(record.aircraftClass))) });
|
||||
} else if (kind === 'vessel') {
|
||||
splits.push({ title: 'Type', parts: tallyBy(records, (record) => shipTypeName(record.shipType)) });
|
||||
} else if (kind === 'vehicle') {
|
||||
// What the display shows each vehicle doing, then what kind it is, who
|
||||
// runs it, the operator's own report and crowding where the feed has it.
|
||||
// Feeds of vehicle positions carry no timetable, so early or late is not
|
||||
// something these records can say.
|
||||
const word = (field) => (record) => CODE_WORDS[field][record[field]] || '';
|
||||
splits.push({ title: 'Motion', parts: tallyBy(records, word('motion')) });
|
||||
splits.push({ title: 'Mode', parts: tallyBy(records, (record) => plainWord(text(record.mode))) });
|
||||
const operators = tallyBy(records, (record) => text(record.operator));
|
||||
if (operators.length > 1) splits.push({ title: 'Operator', parts: operators });
|
||||
const reported = records.filter((record) => CODE_WORDS.status[record.status]);
|
||||
if (reported.length)
|
||||
splits.push({ title: 'Last reported', parts: tallyBy(reported, word('status')) });
|
||||
const crowded = records.filter((record) => CODE_WORDS.occupancy[record.occupancy]);
|
||||
if (crowded.length)
|
||||
splits.push({ title: 'Crowding', parts: tallyBy(crowded, word('occupancy')) });
|
||||
} else if (kind === 'satellite') {
|
||||
splits.push({ title: 'Class', parts: tallyBy(records, (record) => plainWord(text(record.satelliteClass || record.group))) });
|
||||
} else {
|
||||
|
||||
@@ -50,6 +50,58 @@ test('a click identity finds its record by key, past the first 2000 records', ()
|
||||
assert.equal(record?.callsign, 'FLT2400');
|
||||
});
|
||||
|
||||
test('a transit click finds its vehicle by the layer key and reads its state', () => {
|
||||
const buses = manager({
|
||||
transit: {
|
||||
name: 'Transit',
|
||||
records: [
|
||||
{
|
||||
id: 'M634',
|
||||
key: 'capmetro-austin:M634',
|
||||
route: '801',
|
||||
operator: 'CapMetro',
|
||||
status: 'IN_TRANSIT_TO',
|
||||
lat: 30.2,
|
||||
lon: -97.7,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const card = describeEntity(buses, {
|
||||
layerId: 'transit',
|
||||
id: 'capmetro-austin:M634',
|
||||
lat: 30.21,
|
||||
lon: -97.71,
|
||||
});
|
||||
assert.equal(card?.title, 'M634');
|
||||
const facts = Object.fromEntries(card.facts.map((fact) => [fact.label, fact.value]));
|
||||
assert.equal(facts.Operator, 'CapMetro');
|
||||
assert.equal(facts.Status, 'Heading to next stop');
|
||||
assert.equal(facts.Key, undefined, 'the layer key is not shown');
|
||||
});
|
||||
|
||||
test('transit vehicles break down by motion, mode and reported state', () => {
|
||||
const at = { lat: 30.2, lon: -97.7 };
|
||||
const buses = manager({
|
||||
transit: {
|
||||
name: 'Transit',
|
||||
records: [
|
||||
{ id: '1', mode: 'bus', motion: 'moving', status: 'IN_TRANSIT_TO', ...at },
|
||||
{ id: '2', mode: 'bus', motion: 'stopped', status: 'STOPPED_AT', ...at },
|
||||
{ id: '3', mode: 'rail', motion: 'moving', occupancy: 'FULL', ...at },
|
||||
],
|
||||
},
|
||||
});
|
||||
const breakdown = layerBreakdown(buses, 'transit');
|
||||
assert.equal(breakdown.total, 3);
|
||||
const split = (title) =>
|
||||
Object.fromEntries(breakdown.splits.find((item) => item.title === title).parts.map((part) => [part.label, part.count]));
|
||||
assert.deepEqual(split('Motion'), { Moving: 2, Stopped: 1 });
|
||||
assert.deepEqual(split('Mode'), { Bus: 2, Rail: 1 });
|
||||
assert.deepEqual(split('Last reported'), { 'Heading to next stop': 1, 'Stopped at a stop': 1 });
|
||||
assert.deepEqual(split('Crowding'), { Full: 1 });
|
||||
});
|
||||
|
||||
test('a moving item never borrows a nearby craft when its key is unknown', () => {
|
||||
const record = findRecord(dm, { layerId: 'flights', id: 'zzzzzz', label: 'NOPE', lat: 34.0004, lon: -118.05 });
|
||||
assert.equal(record, null);
|
||||
|
||||
@@ -5,12 +5,23 @@ import {
|
||||
transitDetectionClass,
|
||||
transitDetectionId,
|
||||
transitDetectionMetric,
|
||||
vehicleReportTimeMs,
|
||||
} from './policy.js';
|
||||
import {
|
||||
TRANSIT_ENABLED_FEEDS,
|
||||
getRegisteredTransitFeed,
|
||||
transitRouteLabel,
|
||||
} from '../../data/transitFeeds.js';
|
||||
import { transitModeTier } from '../../data/transitPresetStyle.js';
|
||||
import { displayMotion } from './movement.js';
|
||||
|
||||
/** The display's motion word as a record field for the Context card. */
|
||||
const MOTION_FIELD = Object.freeze({
|
||||
'EN ROUTE': 'moving',
|
||||
STOPPED: 'stopped',
|
||||
WAITING: 'waiting',
|
||||
'NO FIX': 'no-fix',
|
||||
});
|
||||
|
||||
/** Regions, not feeds: one region can carry several feeds (Rio has two). */
|
||||
const TRANSIT_REGION_COUNT = new Set(
|
||||
@@ -211,10 +222,14 @@ export function createQueries({ state, parts }) {
|
||||
* query engine. On demand only (once per spoken query); [] while the
|
||||
* layer is off.
|
||||
* @param {number} [maxCount=Infinity] Most records to return.
|
||||
* @returns {Array<Object>} {id, label, routeId, mode, lat, lon, speedMps, courseDeg, status, occupancy}.
|
||||
* @returns {Array<Object>} {id, label, routeId, mode, lat, lon, speedMps, courseDeg, status, occupancy},
|
||||
* plus `key` (the layer's own vehicle key, which a map click carries),
|
||||
* `route`, `operator`, `place`, `observedMs` and `motion` (what the
|
||||
* display shows: moving, stopped, waiting or no-fix) for the Context card.
|
||||
*/
|
||||
getAnalystRecords(maxCount = Infinity) {
|
||||
if (!state._enabled) return [];
|
||||
const now = Date.now();
|
||||
const num = (v) => (Number.isFinite(v) ? v : null);
|
||||
const result = [];
|
||||
for (const entry of state._vehicles.values()) {
|
||||
@@ -222,6 +237,8 @@ export function createQueries({ state, parts }) {
|
||||
const record = entry.record || {};
|
||||
if (!Number.isFinite(record.lat) || !Number.isFinite(record.lon))
|
||||
continue;
|
||||
const feed = feedForEntry(state, entry);
|
||||
const reportedMs = vehicleReportTimeMs(record, entry.fetchedAt);
|
||||
result.push({
|
||||
id: record.label || record.id || entry.key,
|
||||
label: record.label || null,
|
||||
@@ -233,6 +250,15 @@ export function createQueries({ state, parts }) {
|
||||
courseDeg: num(entry.courseDeg ?? record.bearing),
|
||||
status: record.status || null,
|
||||
occupancy: record.occupancy || null,
|
||||
key: entry.key,
|
||||
route:
|
||||
record.routeId && feed
|
||||
? transitRouteLabel(feed, record.routeId)
|
||||
: record.routeId || null,
|
||||
operator: feed?.name || null,
|
||||
place: feed?.region || null,
|
||||
observedMs: Number.isFinite(reportedMs) ? reportedMs : null,
|
||||
motion: MOTION_FIELD[displayMotion(entry, now).word] || null,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -464,6 +464,23 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* A moving item's state on its row: green moving, amber stopped, grey
|
||||
while its feed has nothing new. */
|
||||
.view-context__row-motion {
|
||||
flex: none;
|
||||
margin-right: 6px;
|
||||
color: rgba(199, 214, 222, 0.5);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.view-context__row-motion[data-motion='moving'] {
|
||||
color: #5dff9f;
|
||||
}
|
||||
|
||||
.view-context__row-motion[data-motion='stopped'] {
|
||||
color: #ffb86b;
|
||||
}
|
||||
|
||||
.view-context__row-meta {
|
||||
flex: none;
|
||||
color: rgba(199, 214, 222, 0.55);
|
||||
@@ -1144,7 +1161,8 @@
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.cctv-preview__frame img {
|
||||
.cctv-preview__frame img,
|
||||
.cctv-preview__live {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
|
||||
@@ -19,6 +19,16 @@ import AltitudeGraph from './AltitudeGraph.vue';
|
||||
// that item's card. It reads again when the camera settles, and every few
|
||||
// seconds so moving things stay current.
|
||||
const store = useEntityCardStore();
|
||||
|
||||
// What a moving item is doing, as the layer's own display shows it (transit
|
||||
// vehicles report it): an icon on its row, its words on hover.
|
||||
const MOTION_STATES = {
|
||||
moving: { icon: 'play_arrow', label: () => t('Moving') },
|
||||
stopped: { icon: 'pause', label: () => t('Stopped', { context: 'vehicle motion' }) },
|
||||
waiting: { icon: 'schedule', label: () => t('Waiting for update') },
|
||||
'no-fix': { icon: 'location_off', label: () => t('No recent fix') },
|
||||
};
|
||||
const motionOf = (item) => MOTION_STATES[item.identity?.record?.motion] || null;
|
||||
const { view } = storeToRefs(store);
|
||||
const tick = ref(0);
|
||||
let timer = null;
|
||||
@@ -348,6 +358,14 @@ const distance = (km) =>
|
||||
<ul>
|
||||
<li v-for="item in group.items" :key="item.key">
|
||||
<button type="button" @click="store.select(item.identity, { fly: true })">
|
||||
<span
|
||||
v-if="motionOf(item)"
|
||||
class="material-symbols-outlined view-context__row-motion"
|
||||
:data-motion="item.identity.record.motion"
|
||||
:title="motionOf(item).label()"
|
||||
role="img"
|
||||
:aria-label="motionOf(item).label()"
|
||||
>{{ motionOf(item).icon }}</span>
|
||||
<span class="view-context__row-title">{{ item.title }}</span>
|
||||
<span class="view-context__row-meta">{{ distance(item.distanceKm) }}</span>
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user