Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared Type & Interface Declarations #1073

Merged
merged 8 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion www/js/diary/LabelTabContext.ts
Original file line number Diff line number Diff line change
@@ -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<string, TimelineEntry>;
export type TimelineLabelMap = {
Expand Down
3 changes: 2 additions & 1 deletion www/js/diary/diaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 1 addition & 25 deletions www/js/survey/multilabel/confirmHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends string> = {
[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<T extends string = MultilabelKey> = {
[k in T]: LabelOption[];
} & {
translations: {
[lang: string]: { [translationKey: string]: string };
};
};
import { LabelOption, LabelOptions, MultilabelKey, InputDetails } from '../../types/labelTypes';

let appConfig;
export let labelOptions: LabelOptions<MultilabelKey>;
Expand Down
58 changes: 47 additions & 11 deletions www/js/types/diaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -39,7 +51,7 @@ export type CompositeTrip = {
confirmed_trip: ObjectId;
distance: number;
duration: number;
end_confirmed_place: ConfirmedPlace;
end_confirmed_place: ServerData<ConfirmedPlace>;
end_fmt_time: string;
end_loc: { type: string; coordinates: number[] };
end_local_dt: LocalDt;
Expand All @@ -56,7 +68,7 @@ export type CompositeTrip = {
raw_trip: ObjectId;
sections: any[]; // TODO
source: string;
start_confirmed_place: ConfirmedPlace;
start_confirmed_place: ServerData<ConfirmedPlace>;
start_fmt_time: string;
start_loc: { type: string; coordinates: number[] };
start_local_dt: LocalDt;
Expand Down Expand Up @@ -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;
};
24 changes: 24 additions & 0 deletions www/js/types/labelTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export type InputDetails<T extends string> = {
[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<T extends string = MultilabelKey> = {
[k in T]: LabelOption[];
} & {
translations: {
[lang: string]: { [translationKey: string]: string };
};
};
Loading