diff --git a/www/js/diary/LabelTabContext.ts b/www/js/diary/LabelTabContext.ts index 24d7ade41..717a4980d 100644 --- a/www/js/diary/LabelTabContext.ts +++ b/www/js/diary/LabelTabContext.ts @@ -1,6 +1,6 @@ import { createContext } from 'react'; import { TimelineEntry, UserInputEntry } from '../types/diaryTypes'; -import { LabelOption } from '../survey/multilabel/confirmHelper'; +import { LabelOption } from '../types/labelTypes'; export type TimelineMap = Map; export type TimelineLabelMap = { diff --git a/www/js/diary/diaryHelper.ts b/www/js/diary/diaryHelper.ts index 616974b7b..2fee7eccd 100644 --- a/www/js/diary/diaryHelper.ts +++ b/www/js/diary/diaryHelper.ts @@ -3,8 +3,9 @@ import moment from 'moment'; import { DateTime } from 'luxon'; -import { LabelOptions, readableLabelToKey } from '../survey/multilabel/confirmHelper'; +import { readableLabelToKey } from '../survey/multilabel/confirmHelper'; import { CompositeTrip } from '../types/diaryTypes'; +import { LabelOptions } from '../types/labelTypes'; export const modeColors = { pink: '#c32e85', // oklch(56% 0.2 350) // e-car diff --git a/www/js/survey/multilabel/confirmHelper.ts b/www/js/survey/multilabel/confirmHelper.ts index 51674b0c3..4c2be1012 100644 --- a/www/js/survey/multilabel/confirmHelper.ts +++ b/www/js/survey/multilabel/confirmHelper.ts @@ -4,31 +4,7 @@ import { getAngularService } from '../../angular-react-helper'; import { fetchUrlCached } from '../../services/commHelper'; import i18next from 'i18next'; import { logDebug } from '../../plugin/logger'; - -type InputDetails = { - [k in T]?: { - name: string; - labeltext: string; - choosetext: string; - key: string; - }; -}; -export type LabelOption = { - value: string; - baseMode: string; - met?: { range: any[]; mets: number }; - met_equivalent?: string; - kgCo2PerKm: number; - text?: string; -}; -export type MultilabelKey = 'MODE' | 'PURPOSE' | 'REPLACED_MODE'; -export type LabelOptions = { - [k in T]: LabelOption[]; -} & { - translations: { - [lang: string]: { [translationKey: string]: string }; - }; -}; +import { LabelOption, LabelOptions, MultilabelKey, InputDetails } from '../../types/labelTypes'; let appConfig; export let labelOptions: LabelOptions; diff --git a/www/js/types/diaryTypes.ts b/www/js/types/diaryTypes.ts index 743d75b15..938b06851 100644 --- a/www/js/types/diaryTypes.ts +++ b/www/js/types/diaryTypes.ts @@ -3,6 +3,7 @@ As much as possible, these types parallel the types used in the server code. */ import { BaseModeKey, MotionTypeKey } from '../diary/diaryHelper'; +import { ServerData, LocalDt } from './serverData'; type ObjectId = { $oid: string }; type ConfirmedPlace = { @@ -28,6 +29,17 @@ type ConfirmedPlace = { }; }; +export type TripTransition = { + currstate: string; + transition: string; + ts: number; +}; + +export type LocationCoord = { + type: string; // e.x., "Point" + coordinates: [number, number]; +}; + /* 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 = { @@ -39,7 +51,7 @@ export type CompositeTrip = { confirmed_trip: ObjectId; distance: number; duration: number; - end_confirmed_place: ConfirmedPlace; + end_confirmed_place: ServerData; end_fmt_time: string; end_loc: { type: string; coordinates: number[] }; end_local_dt: LocalDt; @@ -56,7 +68,7 @@ export type CompositeTrip = { raw_trip: ObjectId; sections: any[]; // TODO source: string; - start_confirmed_place: ConfirmedPlace; + start_confirmed_place: ServerData; start_fmt_time: string; start_loc: { type: string; coordinates: number[] }; start_local_dt: LocalDt; @@ -118,13 +130,37 @@ export type UserInputEntry = { key?: string; }; -export type LocalDt = { - minute: number; - hour: number; - second: number; - day: number; - weekday: number; - month: number; - year: number; - timezone: string; +export type Location = { + speed: number; + heading: number; + local_dt: LocalDt; + idx: number; + section: ObjectId; + longitude: number; + latitude: number; + fmt_time: string; // ISO + mode: number; + loc: LocationCoord; + ts: number; // Unix + altitude: number; + distance: number; +}; + +// used in readAllCompositeTrips +export type SectionData = { + end_ts: number; // Unix time, e.x. 1696352498.804 + end_loc: LocationCoord; + start_fmt_time: string; // ISO time + end_fmt_time: string; + trip_id: ObjectId; + sensed_mode: number; + source: string; // e.x., "SmoothedHighConfidenceMotion" + start_ts: number; // Unix + start_loc: LocationCoord; + cleaned_section: ObjectId; + start_local_dt: LocalDt; + end_local_dt: LocalDt; + sensed_mode_str: string; //e.x., "CAR" + duration: number; + distance: number; }; diff --git a/www/js/types/labelTypes.ts b/www/js/types/labelTypes.ts new file mode 100644 index 000000000..8ac720adc --- /dev/null +++ b/www/js/types/labelTypes.ts @@ -0,0 +1,24 @@ +export type InputDetails = { + [k in T]?: { + name: string; + labeltext: string; + choosetext: string; + key: string; + }; +}; +export type LabelOption = { + value: string; + baseMode: string; + met?: { range: any[]; mets: number }; + met_equivalent?: string; + kgCo2PerKm: number; + text?: string; +}; +export type MultilabelKey = 'MODE' | 'PURPOSE' | 'REPLACED_MODE'; +export type LabelOptions = { + [k in T]: LabelOption[]; +} & { + translations: { + [lang: string]: { [translationKey: string]: string }; + }; +};