diff --git a/www/js/controllers.js b/www/js/controllers.js index 1f3e64312..17835f3f4 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -87,4 +87,4 @@ angular ); console.log('SplashCtrl invoke finished'); }, - ) + ); diff --git a/www/js/diary/LabelTab.tsx b/www/js/diary/LabelTab.tsx index f58277bea..bbd86d64a 100644 --- a/www/js/diary/LabelTab.tsx +++ b/www/js/diary/LabelTab.tsx @@ -241,11 +241,7 @@ const LabelTab = () => { [...timelineMap?.values()] .reverse() .find((trip) => trip.origin_key.includes('confirmed_trip')); - readUnprocessedPromise = readUnprocessedTrips( - pipelineRange.end_ts, - nowTs, - lastProcessedTrip, - ); + readUnprocessedPromise = readUnprocessedTrips(pipelineRange.end_ts, nowTs, lastProcessedTrip); readUnprocessedPromise = readUnprocessedTrips(pipelineRange.end_ts, nowTs, lastProcessedTrip); } else { readUnprocessedPromise = Promise.resolve([]); @@ -262,8 +258,7 @@ const LabelTab = () => { const timelineMapRef = useRef(timelineMap); async function repopulateTimelineEntry(oid: string) { - if (!timelineMap.has(oid)) - return console.error(`Item with oid: ${oid} not found in timeline`); + if (!timelineMap.has(oid)) return console.error(`Item with oid: ${oid} not found in timeline`); const [newLabels, newNotes] = await getLocalUnprocessedInputs( pipelineRange, labelPopulateFactory, diff --git a/www/js/services.js b/www/js/services.js index 891b47eae..aa2958d47 100644 --- a/www/js/services.js +++ b/www/js/services.js @@ -3,12 +3,10 @@ import angular from 'angular'; import { getRawEntries } from './commHelper'; -angular.module('emission.services', ['emission.plugin.logger']) -.service('ControlHelper', function($window, - $ionicPopup, - Logger) { - - this.writeFile = function(fileEntry, resultList) { +angular + .module('emission.services', ['emission.plugin.logger']) + .service('ControlHelper', function ($window, $ionicPopup, Logger) { + this.writeFile = function (fileEntry, resultList) { // Create a FileWriter object for our FileEntry (log.txt). }; @@ -126,5 +124,4 @@ angular.module('emission.services', ['emission.plugin.logger']) this.getSettings = function () { return window.cordova.plugins.BEMConnectionSettings.getSettings(); }; - -}); \ No newline at end of file + }); diff --git a/www/js/types/diaryTypes.ts b/www/js/types/diaryTypes.ts index b51725977..14d8acc07 100644 --- a/www/js/types/diaryTypes.ts +++ b/www/js/types/diaryTypes.ts @@ -1,75 +1,75 @@ -import { LocalDt, ServerData } from './serverData' +import { LocalDt, ServerData } from './serverData'; -export type UserInput = ServerData<UserInputData> +export type UserInput = ServerData<UserInputData>; export type UserInputData = { - end_ts: number, - start_ts: number - label: string, - start_local_dt?: LocalDt - end_local_dt?: LocalDt - status?: string, - match_id?: string, -} + end_ts: number; + start_ts: number; + label: string; + start_local_dt?: LocalDt; + end_local_dt?: LocalDt; + status?: string; + match_id?: string; +}; type ConfirmedPlace = any; // TODO 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: LocalDt, - 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: LocalDt, - start_place: {$oid: string}, - start_ts: number, - user_input: UserInput, -} + _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: LocalDt; + 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: LocalDt; + start_place: { $oid: string }; + start_ts: number; + user_input: UserInput; +}; export type PopulatedTrip = CompositeTrip & { - additionsList?: any[], // TODO - finalInference?: any, // TODO - geojson?: any, // TODO - getNextEntry?: () => PopulatedTrip | ConfirmedPlace, - userInput?: UserInput, - verifiability?: string, -} + additionsList?: any[]; // TODO + finalInference?: any; // TODO + geojson?: any; // TODO + getNextEntry?: () => PopulatedTrip | ConfirmedPlace; + userInput?: UserInput; + verifiability?: string; +}; export type Trip = { - end_ts: number, - start_ts: number, -} + end_ts: number; + start_ts: 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, -} \ No newline at end of file + key: string; + origin_key: string; + start_ts: number; + end_ts: number; + enter_ts: number; + exit_ts: number; + duration: number; + getNextEntry?: () => PopulatedTrip | ConfirmedPlace; +}; diff --git a/www/js/types/fileShareTypes.ts b/www/js/types/fileShareTypes.ts index 89481624d..03b41a161 100644 --- a/www/js/types/fileShareTypes.ts +++ b/www/js/types/fileShareTypes.ts @@ -1,11 +1,11 @@ -import { ServerData } from './serverData'; +import { ServerData } from './serverData'; export type TimeStampData = ServerData<RawTimelineData>; export type RawTimelineData = { - name: string, - ts: number, - reading: number, + name: string; + ts: number; + reading: number; }; export interface FsWindow extends Window { @@ -13,10 +13,10 @@ export interface FsWindow extends Window { type: number, size: number, successCallback: (fs: any) => void, - errorCallback?: (error: any) => void + errorCallback?: (error: any) => void, ) => void; LocalFileSystem: { TEMPORARY: number; PERSISTENT: number; }; -}; +} diff --git a/www/js/types/serverData.ts b/www/js/types/serverData.ts index 8b14b79df..9a15ff996 100644 --- a/www/js/types/serverData.ts +++ b/www/js/types/serverData.ts @@ -1,39 +1,39 @@ export type ServerResponse<Type> = { - phone_data: Array<ServerData<Type>>, -} + phone_data: Array<ServerData<Type>>; +}; export type ServerData<Type> = { - data: Type, - metadata: MetaData, - key?: string, - user_id?: { $uuid: string, }, - _id?: { $oid: string, }, + data: Type; + metadata: MetaData; + key?: string; + user_id?: { $uuid: string }; + _id?: { $oid: string }; }; export type MetaData = { - key: string, - platform: string, - write_ts: number, - time_zone: string, - write_fmt_time: string, - write_local_dt: LocalDt, - origin_key?: string, - read_ts?: number, + key: string; + platform: string; + write_ts: number; + time_zone: string; + write_fmt_time: string; + write_local_dt: LocalDt; + origin_key?: string; + read_ts?: number; }; - + export type LocalDt = { - minute: number, - hour: number, - second: number, - day: number, - weekday: number, - month: number, - year: number, - timezone: string, + minute: number; + hour: number; + second: number; + day: number; + weekday: number; + month: number; + year: number; + timezone: string; }; export type TimeQuery = { key: string; startTs: number; endTs: number; -} \ No newline at end of file +}; diff --git a/www/js/unifiedDataLoader.ts b/www/js/unifiedDataLoader.ts index 15bcd341d..dc0866be3 100644 --- a/www/js/unifiedDataLoader.ts +++ b/www/js/unifiedDataLoader.ts @@ -1,103 +1,124 @@ -import { logDebug } from './plugin/logger' +import { logDebug } from './plugin/logger'; import { getRawEntries } from './commHelper'; import { ServerResponse, ServerData, TimeQuery } from './types/serverData'; /** - * combineWithDedup is a helper function for combinedPromises + * combineWithDedup is a helper function for combinedPromises * @param list1 values evaluated from a BEMUserCache promise - * @param list2 same as list1 + * @param list2 same as list1 * @returns a dedup array generated from the input lists */ -export const combineWithDedup = function(list1: Array<ServerData<any>>, list2: Array<any>) { - const combinedList = list1.concat(list2); - return combinedList.filter(function(value, i, array) { - const firstIndexOfValue = array.findIndex(function(element) { - return element.metadata.write_ts == value.metadata.write_ts; - }); - return firstIndexOfValue == i; +export const combineWithDedup = function (list1: Array<ServerData<any>>, list2: Array<any>) { + const combinedList = list1.concat(list2); + return combinedList.filter(function (value, i, array) { + const firstIndexOfValue = array.findIndex(function (element) { + return element.metadata.write_ts == value.metadata.write_ts; }); + return firstIndexOfValue == i; + }); }; /** - * combinedPromises is a recursive function that joins multiple promises - * @param promiseList 1 or more promises + * combinedPromises is a recursive function that joins multiple promises + * @param promiseList 1 or more promises * @param combiner a function that takes two arrays and joins them * @returns A promise which evaluates to a combined list of values or errors */ -export const combinedPromises = function(promiseList: Array<Promise<any>>, - combiner: (list1: Array<any>, list2: Array<any>) => Array<any> ) { - if (promiseList.length === 0) { - throw new RangeError('combinedPromises needs input array.length >= 1'); - } - return new Promise(function(resolve, reject) { - var firstResult = []; - var firstError = null; +export const combinedPromises = function ( + promiseList: Array<Promise<any>>, + combiner: (list1: Array<any>, list2: Array<any>) => Array<any>, +) { + if (promiseList.length === 0) { + throw new RangeError('combinedPromises needs input array.length >= 1'); + } + return new Promise(function (resolve, reject) { + var firstResult = []; + var firstError = null; - var nextResult = []; - var nextError = null; + var nextResult = []; + var nextError = null; - var firstPromiseDone = false; - var nextPromiseDone = false; + var firstPromiseDone = false; + var nextPromiseDone = false; - const checkAndResolve = function() { - if (firstPromiseDone && nextPromiseDone) { - if (firstError && nextError) { - reject([firstError, nextError]); - } else { - logDebug(`About to dedup firstResult = ${firstResult.length}` + - ` nextResult = ${nextResult.length}`); - const dedupedList = combiner(firstResult, nextResult); - logDebug(`Deduped list = ${dedupedList.length}`); - resolve(dedupedList); - } + const checkAndResolve = function () { + if (firstPromiseDone && nextPromiseDone) { + if (firstError && nextError) { + reject([firstError, nextError]); + } else { + logDebug( + `About to dedup firstResult = ${firstResult.length}` + + ` nextResult = ${nextResult.length}`, + ); + const dedupedList = combiner(firstResult, nextResult); + logDebug(`Deduped list = ${dedupedList.length}`); + resolve(dedupedList); } - }; - - if (promiseList.length === 1) { - return promiseList[0].then(function(result: Array<any>) { + } + }; + + if (promiseList.length === 1) { + return promiseList[0].then( + function (result: Array<any>) { resolve(result); - }, function (err) { + }, + function (err) { reject([err]); - }); - } + }, + ); + } - const firstPromise = promiseList[0]; - const nextPromise = combinedPromises(promiseList.slice(1), combiner); - - firstPromise.then(function(currentFirstResult: Array<any>) { - firstResult = currentFirstResult; - firstPromiseDone = true; - }, function(error) { - firstResult = []; - firstError = error; - nextPromiseDone = true; - }).then(checkAndResolve); + const firstPromise = promiseList[0]; + const nextPromise = combinedPromises(promiseList.slice(1), combiner); - nextPromise.then(function(currentNextResult: Array<any>) { - nextResult = currentNextResult; - nextPromiseDone = true; - }, function(error) { - nextResult = []; - nextError = error; - }).then(checkAndResolve); - }); + firstPromise + .then( + function (currentFirstResult: Array<any>) { + firstResult = currentFirstResult; + firstPromiseDone = true; + }, + function (error) { + firstResult = []; + firstError = error; + nextPromiseDone = true; + }, + ) + .then(checkAndResolve); + + nextPromise + .then( + function (currentNextResult: Array<any>) { + nextResult = currentNextResult; + nextPromiseDone = true; + }, + function (error) { + nextResult = []; + nextError = error; + }, + ) + .then(checkAndResolve); + }); }; /** - * getUnifiedDataForInterval is a generalized method to fetch data by its timestamps + * getUnifiedDataForInterval is a generalized method to fetch data by its timestamps * @param key string corresponding to a data entry * @param tq an object that contains interval start and end times * @param getMethod a BEMUserCache method that fetches certain data via a promise * @returns A promise that evaluates to the all values found within the queried data */ -export const getUnifiedDataForInterval = function(key: string, tq: TimeQuery, - getMethod: (key: string, tq: TimeQuery, flag: boolean) => Promise<any>) { - const test = true; - const getPromise = getMethod(key, tq, test); - const remotePromise = getRawEntries([key], tq.startTs, tq.endTs) - .then(function(serverResponse: ServerResponse<any>) { - return serverResponse.phone_data; - }); - var promiseList = [getPromise, remotePromise] - return combinedPromises(promiseList, combineWithDedup); -}; \ No newline at end of file +export const getUnifiedDataForInterval = function ( + key: string, + tq: TimeQuery, + getMethod: (key: string, tq: TimeQuery, flag: boolean) => Promise<any>, +) { + const test = true; + const getPromise = getMethod(key, tq, test); + const remotePromise = getRawEntries([key], tq.startTs, tq.endTs).then(function ( + serverResponse: ServerResponse<any>, + ) { + return serverResponse.phone_data; + }); + var promiseList = [getPromise, remotePromise]; + return combinedPromises(promiseList, combineWithDedup); +};