Skip to content

Commit

Permalink
Merge pull request #1 from JGreenlee/update_type_interfaces
Browse files Browse the repository at this point in the history
Update Type Definitions in diaryTypes.ts
  • Loading branch information
the-bay-kay authored Nov 9, 2023
2 parents 12e8029 + bc9dfaf commit 4d19a9d
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 141 deletions.
4 changes: 2 additions & 2 deletions www/js/diary/diaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type BaseMode = {
};

// parallels the server-side MotionTypes enum: https://github.com/e-mission/e-mission-server/blob/94e7478e627fa8c171323662f951c611c0993031/emission/core/wrapper/motionactivity.py#L12
type MotionTypeKey =
export type MotionTypeKey =
| 'IN_VEHICLE'
| 'BICYCLING'
| 'ON_FOOT'
Expand Down Expand Up @@ -64,7 +64,7 @@ const BaseModes: { [k: string]: BaseMode } = {
OTHER: { name: 'OTHER', icon: 'pencil-circle', color: modeColors.taupe },
};

type BaseModeKey = keyof typeof BaseModes;
export type BaseModeKey = keyof typeof BaseModes;
/**
* @param motionName A string like "WALKING" or "MotionTypes.WALKING"
* @returns A BaseMode object containing the name, icon, and color of the motion type
Expand Down
72 changes: 0 additions & 72 deletions www/js/diary/diaryTypes.ts

This file was deleted.

158 changes: 91 additions & 67 deletions www/js/types/diaryTypes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import { LocalDt, ServerData } from './serverData';
/* This file provides typings for use in '/diary', including timeline objects (trips and places)
and user input objects.
As much as possible, these types parallel the types used in the server code. */

export type UserInput = ServerData<UserInputData>;
import { BaseModeKey, MotionTypeKey } from '../diary/diaryHelper';
import { LocalDt } from './serverData';

export type UserInputData = {
end_ts: number;
start_ts: number;
label: string;
start_local_dt?: LocalDt;
end_local_dt?: LocalDt;
status?: string;
match_id?: string;
type ObjectId = { $oid: string };
type ConfirmedPlace = {
_id: ObjectId;
additions: UserInputEntry[];
cleaned_place: ObjectId;
ending_trip: ObjectId;
enter_fmt_time: string; // ISO string 2023-10-31T12:00:00.000-04:00
enter_local_dt: LocalDt;
enter_ts: number; // Unix timestamp
key: string;
location: { type: string; coordinates: number[] };
origin_key: string;
raw_places: ObjectId[];
source: string;
user_input: {
/* for keys ending in 'user_input' (e.g. 'trip_user_input'), the server gives us the raw user
input object with 'data' and 'metadata' */
[k: `${string}user_input`]: UserInputEntry;
/* for keys ending in 'confirm' (e.g. 'mode_confirm'), the server just gives us the user input value
as a string (e.g. 'walk', 'drove_alone') */
[k: `${string}confirm`]: string;
};
};

export type TripTransition = {
Expand All @@ -18,100 +35,107 @@ export type TripTransition = {
ts: number;
};

export type ObjId = {
$oid: string; // objIds have len 24
};

export type LocationCoord = {
type: string; // e.x., "Point"
coordinates: [number, number];
};

type ConfirmedPlace = {
cleaned_place: {
string;
};
additions: Array<any>; // Todo
ender_local_dt: LocalDt;
starting_trip: ObjId;
exit_fmt_time: string; // ISO
exit_local_dt: LocalDt;
enter_ts: number;
source: string;
enter_fmt_time: string;
raw_places: Array<ObjId>;
location: LocationCoord;
exit_ts: number;
ending_trip: ObjId;
user_input: {}; //todo
};

/* These are the properties received from the server (basically matches Python code)
This should match what Timeline.readAllCompositeTrips returns (an array of these objects) */
export type CompositeTrip = {
_id: ObjId;
additions: any[]; // TODO
cleaned_section_summary: any; // TODO
cleaned_trip: ObjId;
_id: ObjectId;
additions: UserInputEntry[];
cleaned_section_summary: SectionSummary;
cleaned_trip: ObjectId;
confidence_threshold: number;
confirmed_trip: ObjId;
confirmed_trip: ObjectId;
distance: number;
duration: number;
end_confirmed_place: ConfirmedPlace;
end_fmt_time: string;
end_loc: { type: string; coordinates: number[] };
end_local_dt: LocalDt;
end_place: ObjId;
end_place: ObjectId;
end_ts: number;
expectation: any; // TODO "{to_label: boolean}"
expected_trip: ObjId;
expected_trip: ObjectId;
inferred_labels: any[]; // TODO
inferred_section_summary: any; // TODO
inferred_trip: ObjId;
inferred_section_summary: SectionSummary;
inferred_trip: ObjectId;
key: string;
locations: any[]; // TODO
origin_key: string;
raw_trip: ObjId;
raw_trip: ObjectId;
sections: any[]; // TODO
source: string;
start_confirmed_place: ConfirmedPlace;
start_fmt_time: string;
start_loc: { type: string; coordinates: number[] };
start_local_dt: LocalDt;
start_place: ObjId;
start_place: ObjectId;
start_ts: number;
user_input: UserInput;
user_input: {
/* for keys ending in 'user_input' (e.g. 'trip_user_input'), the server gives us the raw user
input object with 'data' and 'metadata' */
[k: `${string}user_input`]: UserInputEntry;
/* for keys ending in 'confirm' (e.g. 'mode_confirm'), the server just gives us the user input value
as a string (e.g. 'walk', 'drove_alone') */
[k: `${string}confirm`]: string;
};
};

export type PopulatedTrip = CompositeTrip & {
additionsList?: any[]; // TODO
finalInference?: any; // TODO
geojson?: any; // TODO
getNextEntry?: () => PopulatedTrip | ConfirmedPlace;
userInput?: UserInput;
verifiability?: string;
/* The 'timeline' for a user is a list of their trips and places,
so a 'timeline entry' is either a trip or a place. */
export type TimelineEntry = ConfirmedPlace | CompositeTrip;

/* These properties aren't received from the server, but are derived from the above properties.
They are used in the UI to display trip/place details and are computed by the useDerivedProperties hook. */
export type DerivedProperties = {
displayDate: string;
displayStartTime: string;
displayEndTime: string;
displayTime: string;
displayStartDateAbbr: string;
displayEndDateAbbr: string;
formattedDistance: string;
formattedSectionProperties: any[]; // TODO
distanceSuffix: string;
detectedModes: { mode: string; icon: string; color: string; pct: number | string }[];
};

export type Trip = {
end_ts: number;
start_ts: number;
export type SectionSummary = {
count: { [k: MotionTypeKey | BaseModeKey]: number };
distance: { [k: MotionTypeKey | BaseModeKey]: number };
duration: { [k: MotionTypeKey | BaseModeKey]: number };
};

export type TlEntry = {
key: string;
origin_key: string;
start_ts: number;
end_ts: number;
enter_ts: number;
exit_ts: number;
duration: number;
getNextEntry?: () => PopulatedTrip | ConfirmedPlace;
export type UserInputEntry = {
data: {
end_ts: number;
start_ts: number;
label: string;
start_local_dt?: LocalDt;
end_local_dt?: LocalDt;
status?: string;
match_id?: string;
};
metadata: {
time_zone: string;
plugin: string;
write_ts: number;
platform: string;
read_ts: number;
key: string;
};
key?: string;
};

export type Location = {
speed: number;
heading: number;
local_dt: LocalDt;
idx: number;
section: ObjId;
section: ObjectId;
longitude: number;
latitude: number;
fmt_time: string; // ISO
Expand All @@ -128,12 +152,12 @@ export type SectionData = {
end_loc: LocationCoord;
start_fmt_time: string; // ISO time
end_fmt_time: string;
trip_id: ObjId;
trip_id: ObjectId;
sensed_mode: number;
source: string; // e.x., "SmoothedHighConfidenceMotion"
start_ts: number; // Unix
start_loc: LocationCoord;
cleaned_section: ObjId;
cleaned_section: ObjectId;
start_local_dt: LocalDt;
end_local_dt: LocalDt;
sensed_mode_str: string; //e.x., "CAR"
Expand Down

0 comments on commit 4d19a9d

Please sign in to comment.