Skip to content

Commit

Permalink
flesh out more types
Browse files Browse the repository at this point in the history
Filled in more trip object types, and specifically some literal types that define unprocessed trips. (like "source" will always be 'unprocessed').

CompTripLocations changed from `number[]` for coordinates to geojson's `Position`, since that is more descriptive. Renamed CompTripLocations to CompositeTripLocation (this type represents only 1 location).

Used the CompositeTripLocation type in timelineHelper.
in locations2GeojsonTrajectory, the return type needed `properties` for it to be considered a Geojson `Feature`.

formattedSectionProperties types as the return type of the function
  • Loading branch information
JGreenlee committed Apr 3, 2024
1 parent 12db91a commit 826190a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
12 changes: 8 additions & 4 deletions www/js/diary/timelineHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
CompositeTrip,
UnprocessedTrip,
SectionData,
CompositeTripLocation,
} from '../types/diaryTypes';
import { getLabelInputDetails, getLabelInputs } from '../survey/multilabel/confirmHelper';
import { LabelOptions } from '../types/labelTypes';
Expand Down Expand Up @@ -216,10 +217,10 @@ const location2GeojsonPoint = (locationPoint: Point, featureType: string): Featu
*/
function locations2GeojsonTrajectory(
trip: CompositeTrip,
locationList: Array<Point>,
locationList: CompositeTripLocation[],
trajectoryColor?: string,
) {
let sectionsPoints;
): Feature[] {
let sectionsPoints: CompositeTripLocation[][];
if (!trip.sections) {
// this is a unimodal trip so we put all the locations in one section
sectionsPoints = [locationList];
Expand All @@ -243,6 +244,9 @@ function locations2GeojsonTrajectory(
color for the sensed mode of this section, and fall back to dark grey */
color: trajectoryColor || getBaseModeByKey(section?.sensed_mode_str)?.color || '#333',
},
properties: {
feature_type: 'section_trajectory',
},
};
});
}
Expand Down Expand Up @@ -341,7 +345,7 @@ function points2UnprocessedTrip(locationPoints: Array<BEMData<FilteredLocation>>
} as Point,
start_local_dt: dateTime2localdate(startTime, startPoint.metadata.time_zone),
start_ts: startPoint.data.ts,
};
} as const;

// section: baseProps + some properties that are unique to the section
const singleSection: SectionData = {
Expand Down
26 changes: 13 additions & 13 deletions www/js/types/diaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { BaseModeKey, MotionTypeKey } from '../diary/diaryHelper';
import { MultilabelKey } from './labelTypes';
import { BEMData, LocalDt } from './serverData';
import { FeatureCollection, Feature, Geometry, Point } from 'geojson';
import { FeatureCollection, Feature, Geometry, Point, Position } from 'geojson';

type ObjectId = { $oid: string };

Expand Down Expand Up @@ -45,9 +45,9 @@ export type TripTransition = {
ts: number;
};

type CompTripLocations = {
export type CompositeTripLocation = {
loc: {
coordinates: number[]; // e.g. [1, 2.3]
coordinates: Position; // [lon, lat]
};
speed: number;
ts: number;
Expand All @@ -56,27 +56,27 @@ type CompTripLocations = {
// Used for return type of readUnprocessedTrips
export type UnprocessedTrip = {
_id: ObjectId;
additions: UserInputEntry[];
additions: []; // unprocessed trips won't have any matched processed inputs, so this is always empty
confidence_threshold: number;
distance: number;
duration: number;
end_fmt_time: string;
end_loc: Point;
end_local_dt: LocalDt;
end_ts: number;
expectation: any; // TODO "{to_label: boolean}"
inferred_labels: any[]; // TODO
key: string;
locations?: CompTripLocations[];
origin_key: string; // e.x., UNPROCESSED_trip
expectation: { to_label: true }; // unprocessed trips are always expected to be labeled
inferred_labels: []; // unprocessed trips won't have inferred labels
key: 'UNPROCESSED_trip';
locations?: CompositeTripLocation[];
origin_key: 'UNPROCESSED_trip';
sections: SectionData[];
source: string;
source: 'unprocessed';
start_fmt_time: string;
start_local_dt: LocalDt;
start_ts: number;
start_loc: Point;
starting_trip?: any;
user_input: UserInput;
user_input: {}; // unprocessed trips won't have any matched processed inputs, so this is always empty
};

/* These are the properties received from the server (basically matches Python code)
Expand All @@ -96,13 +96,13 @@ export type CompositeTrip = {
end_local_dt: LocalDt;
end_place: ObjectId;
end_ts: number;
expectation: any; // TODO "{to_label: boolean}"
expectation: { to_label: boolean };
expected_trip: ObjectId;
inferred_labels: InferredLabels;
inferred_section_summary: SectionSummary;
inferred_trip: ObjectId;
key: string;
locations: any[]; // TODO
locations: CompositeTripLocation[];
origin_key: string;
raw_trip: ObjectId;
sections: SectionData[];
Expand Down

0 comments on commit 826190a

Please sign in to comment.