Skip to content

Commit

Permalink
fill in new BLE fields & update types
Browse files Browse the repository at this point in the history
`ble_sensed_mode` and `ble_sensed_summary` were added to sections and confirmed trips in e-mission/e-mission-server#965.

We are going to need `ble_sensed_mode` to determine vehicle info.

The section summaries (`ble_sensed_summary`, `cleaned_section_summary` and `inferred_section_summary`) are not used in unprocessed trips currently, but I am adding them so there is less of a gap between composite trips and unprocessed trips
  • Loading branch information
JGreenlee committed May 7, 2024
1 parent 4ec96df commit 1260e76
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"cordova-custom-config": "^5.1.1",
"cordova-plugin-ibeacon": "git+https://github.com/louisg1337/cordova-plugin-ibeacon.git",
"core-js": "^2.5.7",
"e-mission-common": "git+https://github.com/JGreenlee/e-mission-common.git",
"enketo-core": "^6.1.7",
"enketo-transformer": "^4.0.0",
"fast-xml-parser": "^4.2.2",
Expand Down
1 change: 1 addition & 0 deletions package.serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"chartjs-adapter-luxon": "^1.3.1",
"chartjs-plugin-annotation": "^3.0.1",
"core-js": "^2.5.7",
"e-mission-common": "git+https://github.com/JGreenlee/e-mission-common.git",
"enketo-core": "^6.1.7",
"enketo-transformer": "^4.0.0",
"fast-xml-parser": "^4.2.2",
Expand Down
3 changes: 2 additions & 1 deletion www/__tests__/timelineHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,15 @@ jest.mock('../js/services/unifiedDataLoader', () => ({
}));

it('works when there are no unprocessed trips...', async () => {
expect(readUnprocessedTrips(-1, -1, {} as any)).resolves.toEqual([]);
expect(readUnprocessedTrips(-1, -1, {} as any, {} as any)).resolves.toEqual([]);
});

it('works when there are one or more unprocessed trips...', async () => {
const testValueOne = await readUnprocessedTrips(
mockTLH.fakeStartTsOne,
mockTLH.fakeEndTsOne,
{} as any,
{} as any,
);
expect(testValueOne.length).toEqual(1);
expect(testValueOne[0]).toEqual(
Expand Down
40 changes: 36 additions & 4 deletions www/js/diary/timelineHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import {
BluetoothBleData,
SectionData,
CompositeTripLocation,
SectionSummary,
} from '../types/diaryTypes';
import { getLabelInputDetails, getLabelInputs } from '../survey/multilabel/confirmHelper';
import { LabelOptions } from '../types/labelTypes';
import { EnketoUserInputEntry, filterByNameAndVersion } from '../survey/enketo/enketoHelper';
import { AppConfig } from '../types/appConfigTypes';
import { Point, Feature } from 'geojson';
import { ble_matching } from 'e-mission-common';

const cachedGeojsons: Map<string, GeoJSONData> = new Map();

Expand Down Expand Up @@ -306,10 +308,25 @@ const dateTime2localdate = (currtime: DateTime, tz: string) => ({
second: currtime.second,
});

/* Compute a section summary, which is really simple for unprocessed trips because they are
always assumed to be unimodal.
/* maybe unify with eaum.get_section_summary on e-mission-server at some point */
const getSectionSummaryForUnprocessed = (section: SectionData, modeProp): SectionSummary => {
const baseMode = section[modeProp] || 'UNKNOWN';
return {
count: { [baseMode]: 1 },
distance: { [baseMode]: section.distance },
duration: { [baseMode]: section.duration },
};
};

/**
* @description Given an array of location points, creates an UnprocessedTrip object.
*/
function points2UnprocessedTrip(locationPoints: Array<BEMData<FilteredLocation>>): UnprocessedTrip {
function points2UnprocessedTrip(
locationPoints: Array<BEMData<FilteredLocation>>,
appConfig: AppConfig,
): UnprocessedTrip {
const startPoint = locationPoints[0];
const endPoint = locationPoints[locationPoints.length - 1];
const tripAndSectionId = `unprocessed_${startPoint.data.ts}_${endPoint.data.ts}`;
Expand Down Expand Up @@ -369,6 +386,12 @@ function points2UnprocessedTrip(locationPoints: Array<BEMData<FilteredLocation>>
origin_key: 'UNPROCESSED_section',
sensed_mode: 4, // MotionTypes.UNKNOWN (4)
sensed_mode_str: 'UNKNOWN',
ble_sensed_mode: ble_matching.get_ble_sensed_vehicle_for_section(
unprocessedBleScans,
baseProps.start_ts,
baseProps.end_ts,
appConfig,
),
trip_id: { $oid: tripAndSectionId },
};

Expand All @@ -377,6 +400,9 @@ function points2UnprocessedTrip(locationPoints: Array<BEMData<FilteredLocation>>
...baseProps,
_id: { $oid: tripAndSectionId },
additions: [],
ble_sensed_summary: getSectionSummaryForUnprocessed(singleSection, 'ble_sensed_mode'),
cleaned_section_summary: getSectionSummaryForUnprocessed(singleSection, 'sensed_mode_str'),
inferred_section_summary: getSectionSummaryForUnprocessed(singleSection, 'sensed_mode_str'),
confidence_threshold: 0,
expectation: { to_label: true },
inferred_labels: [],
Expand All @@ -395,7 +421,10 @@ const tsEntrySort = (e1: BEMData<FilteredLocation>, e2: BEMData<FilteredLocation
* @description Given an array of 2 transitions, queries the location data during that time and promises an UnprocessedTrip object.
* @param trip An array of transitions representing one trip; i.e. [start transition, end transition]
*/
function tripTransitions2UnprocessedTrip(trip: Array<any>): Promise<UnprocessedTrip | undefined> {
function tripTransitions2UnprocessedTrip(
trip: Array<any>,
appConfig: AppConfig,
): Promise<UnprocessedTrip | undefined> {
const tripStartTransition = trip[0];
const tripEndTransition = trip[1];
const tq = {
Expand Down Expand Up @@ -437,7 +466,7 @@ function tripTransitions2UnprocessedTrip(trip: Array<any>): Promise<UnprocessedT
logDebug(`transitions: start = ${JSON.stringify(tripStartTransition.data)};
end = ${JSON.stringify(tripEndTransition.data)}`);
}
return points2UnprocessedTrip(filteredLocationList);
return points2UnprocessedTrip(filteredLocationList, appConfig);
},
);
}
Expand Down Expand Up @@ -551,6 +580,7 @@ function linkTrips(trip1, trip2) {
export function readUnprocessedTrips(
startTs: number,
endTs: number,
appConfig: AppConfig,
lastProcessedTrip?: CompositeTrip,
) {
const tq = { key: 'write_ts', startTs, endTs };
Expand All @@ -568,7 +598,9 @@ export function readUnprocessedTrips(
tripsList.forEach((trip) => {
logDebug(JSON.stringify(trip, null, 2));
});
const tripFillPromises = tripsList.map(tripTransitions2UnprocessedTrip);
const tripFillPromises = tripsList.map((t) =>
tripTransitions2UnprocessedTrip(t, appConfig),
);
return Promise.all(tripFillPromises).then(
(rawTripObjs: (UnprocessedTrip | undefined)[]) => {
// Now we need to link up the trips. linking unprocessed trips
Expand Down
6 changes: 6 additions & 0 deletions www/js/types/diaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { BaseModeKey, MotionTypeKey } from '../diary/diaryHelper';
import useDerivedProperties from '../diary/useDerivedProperties';
import { VehicleIdentity } from './appConfigTypes';
import { MultilabelKey } from './labelTypes';
import { BEMData, LocalDt } from './serverData';
import { FeatureCollection, Feature, Geometry, Point, Position } from 'geojson';
Expand Down Expand Up @@ -58,6 +59,8 @@ export type CompositeTripLocation = {
export type UnprocessedTrip = {
_id: ObjectId;
additions: []; // unprocessed trips won't have any matched processed inputs, so this is always empty
ble_sensed_summary: SectionSummary;
cleaned_section_summary: SectionSummary;
confidence_threshold: number;
distance: number;
duration: number;
Expand All @@ -67,6 +70,7 @@ export type UnprocessedTrip = {
end_ts: number;
expectation: { to_label: true }; // unprocessed trips are always expected to be labeled
inferred_labels: []; // unprocessed trips won't have inferred labels
inferred_section_summary: SectionSummary;
key: 'UNPROCESSED_trip';
locations?: CompositeTripLocation[];
origin_key: 'UNPROCESSED_trip';
Expand All @@ -85,6 +89,7 @@ export type UnprocessedTrip = {
export type CompositeTrip = {
_id: ObjectId;
additions: UserInputEntry[];
ble_sensed_summary: SectionSummary;
cleaned_section_summary: SectionSummary;
cleaned_trip: ObjectId;
confidence_threshold: number;
Expand Down Expand Up @@ -202,6 +207,7 @@ export type SectionData = {
key: string;
origin_key: string;
trip_id: ObjectId;
ble_sensed_mode: VehicleIdentity;
sensed_mode: number;
source: string; // e.x., "SmoothedHighConfidenceMotion"
start_ts: number; // Unix
Expand Down

0 comments on commit 1260e76

Please sign in to comment.