From 6dcf1abb6722931b69bf8cef807c42df4e62ede7 Mon Sep 17 00:00:00 2001 From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:46:39 -0800 Subject: [PATCH] Removed $ionicLoading - Behavior remains unchanged when removing this component - labelTab and other parent components handle loading, so the ionic service is not needed. --- www/js/diary/diaryTypes.ts | 72 ---------------------------------- www/js/diary/timelineHelper.ts | 29 +++----------- www/js/types/labelTypes.ts | 24 ++++++++++++ 3 files changed, 30 insertions(+), 95 deletions(-) delete mode 100644 www/js/diary/diaryTypes.ts create mode 100644 www/js/types/labelTypes.ts diff --git a/www/js/diary/diaryTypes.ts b/www/js/diary/diaryTypes.ts deleted file mode 100644 index 5755c91ab..000000000 --- a/www/js/diary/diaryTypes.ts +++ /dev/null @@ -1,72 +0,0 @@ -/* These type definitions are a work in progress. The goal is to have a single source of truth for - the types of the trip / place / untracked objects and all properties they contain. - Since we are using TypeScript now, we should strive to enforce type safety and also benefit from - IntelliSense and other IDE features. */ - -// Since it is WIP, these types are not used anywhere yet. - -type ConfirmedPlace = any; // 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: { $oid: string }; - additions: any[]; // TODO - cleaned_section_summary: any; // TODO - cleaned_trip: { $oid: string }; - confidence_threshold: number; - confirmed_trip: { $oid: string }; - distance: number; - duration: number; - end_confirmed_place: ConfirmedPlace; - end_fmt_time: string; - end_loc: { type: string; coordinates: number[] }; - end_local_dt: any; // TODO - end_place: { $oid: string }; - end_ts: number; - expectation: any; // TODO "{to_label: boolean}" - expected_trip: { $oid: string }; - inferred_labels: any[]; // TODO - inferred_section_summary: any; // TODO - inferred_trip: { $oid: string }; - key: string; - locations: any[]; // TODO - origin_key: string; - raw_trip: { $oid: string }; - sections: any[]; // TODO - source: string; - start_confirmed_place: ConfirmedPlace; - start_fmt_time: string; - start_loc: { type: string; coordinates: number[] }; - start_local_dt: any; // TODO - start_place: { $oid: string }; - start_ts: number; - user_input: any; // TODO -}; - -/* 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 }[]; -}; - -/* These are the properties that are still filled in by some kind of 'populate' mechanism. - It would simplify the codebase to just compute them where they're needed - (using memoization when apt so performance is not impacted). */ -export type PopulatedTrip = CompositeTrip & { - additionsList?: any[]; // TODO - finalInference?: any; // TODO - geojson?: any; // TODO - getNextEntry?: () => PopulatedTrip | ConfirmedPlace; - userInput?: any; // TODO - verifiability?: string; -}; diff --git a/www/js/diary/timelineHelper.ts b/www/js/diary/timelineHelper.ts index 72917f00b..07cdb6dc8 100644 --- a/www/js/diary/timelineHelper.ts +++ b/www/js/diary/timelineHelper.ts @@ -7,12 +7,15 @@ import { ServerResponse, ServerData } from '../types/serverData'; import L from 'leaflet'; import i18next from 'i18next'; import { DateTime } from 'luxon'; +import { CompositeTrip } from '../types/diaryTypes'; +import { LabelOptions } from '../types/labelTypes'; const cachedGeojsons = new Map(); + /** * @description Gets a formatted GeoJSON object for a trip, including the start and end places and the trajectory. */ -export function useGeojsonForTrip(trip, labelOptions, labeledMode?) { +export function useGeojsonForTrip(trip: CompositeTrip, labelOptions: LabelOptions, labeledMode?) { if (!trip) return; const gjKey = `trip-${trip._id.$oid}-${labeledMode || 'detected'}`; if (cachedGeojsons.has(gjKey)) { @@ -230,14 +233,9 @@ const unpackServerData = (obj: ServerData) => ({ }); export const readAllCompositeTrips = function (startTs: number, endTs: number) { - const $ionicLoading = getAngularService('$ionicLoading'); - $ionicLoading.show({ - template: i18next.t('service.reading-server'), - }); const readPromises = [getRawEntries(['analysis/composite_trip'], startTs, endTs, 'data.end_ts')]; return Promise.all(readPromises) .then(([ctList]: [ServerResponse]) => { - $ionicLoading.hide(); return ctList.phone_data.map((ct) => { const unpackedCt = unpackServerData(ct); return { @@ -251,7 +249,6 @@ export const readAllCompositeTrips = function (startTs: number, endTs: number) { }) .catch((err) => { displayError(err, 'while reading confirmed trips'); - $ionicLoading.hide(); return []; }); }; @@ -271,14 +268,7 @@ const dateTime2localdate = function (currtime: DateTime, tz: string) { second: currtime.get('second'), }; }; -/* locationPoints are of form: - * ServerData - * Point = { - * currentState: string, - * transition: string, - * ts: number, // 1698433683.712 - * } - */ + const points2TripProps = function (locationPoints) { const startPoint = locationPoints[0]; const endPoint = locationPoints[locationPoints.length - 1]; @@ -520,11 +510,6 @@ const linkTrips = function (trip1, trip2) { }; export const readUnprocessedTrips = function (startTs, endTs, lastProcessedTrip) { - const $ionicLoading = getAngularService('$ionicLoading'); - $ionicLoading.show({ - template: i18next.t('service.reading-unprocessed-data'), - }); - var tq = { key: 'write_ts', startTs, endTs }; logDebug( 'about to query for unprocessed trips from ' + @@ -538,14 +523,13 @@ export const readUnprocessedTrips = function (startTs, endTs, lastProcessedTrip) ) { if (transitionList.length == 0) { logDebug('No unprocessed trips. yay!'); - $ionicLoading.hide(); return []; } else { logDebug(`Found ${transitionList.length} transitions. yay!`); const tripsList = transitions2Trips(transitionList); logDebug(`Mapped into ${tripsList.length} trips. yay!`); tripsList.forEach(function (trip) { - console.log(JSON.stringify(trip)); + logDebug(JSON.stringify(trip)); }); var tripFillPromises = tripsList.map(transitionTrip2TripObj); return Promise.all(tripFillPromises).then(function (raw_trip_gj_list) { @@ -577,7 +561,6 @@ export const readUnprocessedTrips = function (startTs, endTs, lastProcessedTrip) logDebug('linking unprocessed and processed trip chains'); linkTrips(lastProcessedTrip, trip_gj_list[0]); } - $ionicLoading.hide(); logDebug(`Returning final list of size ${trip_gj_list.length}`); return trip_gj_list; }); diff --git a/www/js/types/labelTypes.ts b/www/js/types/labelTypes.ts new file mode 100644 index 000000000..9719531a8 --- /dev/null +++ b/www/js/types/labelTypes.ts @@ -0,0 +1,24 @@ +export type LabelOptions = { + MODE: Array; + PURPOSE: Array; + REPLACE_MODE: Array; +}; + +export type ModeLabel = { + value: string; + baseMode: string; + met_equivalent?: string; + met?: { + ALL: { + range: Array; + mets: number; + }; + }; + kgCo2PerKm: number; + test: string; +}; + +export type PurposeReplaceLabel = { + value: string; + test: string; +};