diff --git a/www/__mocks__/timelineHelperMocks.ts b/www/__mocks__/timelineHelperMocks.ts index 0c6c6c7c6..78a217ead 100644 --- a/www/__mocks__/timelineHelperMocks.ts +++ b/www/__mocks__/timelineHelperMocks.ts @@ -1,4 +1,4 @@ -import { MetaData, ServerData, ServerResponse } from '../js/types/serverData'; +import { MetaData, BEMData, ServerResponse } from '../js/types/serverData'; import { CompositeTrip, ConfirmedPlace, @@ -168,7 +168,7 @@ export const mockCompDataTwo = { phone_data: [mockCompData.phone_data[0], newPhoneData], }; -export const mockTransitions: Array> = [ +export const mockTransitions: Array> = [ { data: { // mock of a startTransition @@ -208,7 +208,7 @@ mockFilterLocationTwo.ts = 900; mockFilterLocationTwo.longitude = 200; mockFilterLocationTwo.longitude = -200; -export const mockFilterLocations: Array> = [ +export const mockFilterLocations: Array> = [ { data: mockFilterLocation, metadata: mockMetaData, diff --git a/www/__tests__/unifiedDataLoader.test.ts b/www/__tests__/unifiedDataLoader.test.ts index 57b1023da..b99f2a69e 100644 --- a/www/__tests__/unifiedDataLoader.test.ts +++ b/www/__tests__/unifiedDataLoader.test.ts @@ -1,10 +1,10 @@ import { mockLogger } from '../__mocks__/globalMocks'; import { removeDup, combinedPromises } from '../js/services/unifiedDataLoader'; -import { ServerData } from '../js/types/serverData'; +import { BEMData } from '../js/types/serverData'; mockLogger(); -const testOne: ServerData = { +const testOne: BEMData = { data: '', metadata: { key: '', @@ -42,7 +42,7 @@ describe('removeDup can', () => { }); // combinedPromises tests -const promiseGenerator = (values: Array>) => { +const promiseGenerator = (values: Array>) => { return Promise.resolve(values); }; const badPromiseGenerator = (input: string) => { diff --git a/www/js/diary/timelineHelper.ts b/www/js/diary/timelineHelper.ts index 853fc40b7..1d583cd73 100644 --- a/www/js/diary/timelineHelper.ts +++ b/www/js/diary/timelineHelper.ts @@ -2,7 +2,7 @@ import { displayError, logDebug } from '../plugin/logger'; import { getBaseModeByKey, getBaseModeByValue } from './diaryHelper'; import { getUnifiedDataForInterval } from '../services/unifiedDataLoader'; import { getRawEntries } from '../services/commHelper'; -import { ServerResponse, ServerData } from '../types/serverData'; +import { ServerResponse, BEMData } from '../types/serverData'; import L from 'leaflet'; import { DateTime } from 'luxon'; import { @@ -253,7 +253,7 @@ const locations2GeojsonTrajectory = ( // DB entries retrieved from the server have '_id', 'metadata', and 'data' fields. // This function returns a shallow copy of the obj, which flattens the // 'data' field into the top level, while also including '_id' and 'metadata.key' -const unpackServerData = (obj: ServerData) => ({ +const unpackServerData = (obj: BEMData) => ({ ...obj.data, _id: obj._id, key: obj.metadata.key, @@ -296,7 +296,7 @@ const dateTime2localdate = function (currtime: DateTime, tz: string) { }; }; -const points2TripProps = function (locationPoints: Array>) { +const points2TripProps = function (locationPoints: Array>) { const startPoint = locationPoints[0]; const endPoint = locationPoints[locationPoints.length - 1]; const tripAndSectionId = `unprocessed_${startPoint.data.ts}_${endPoint.data.ts}`; @@ -348,7 +348,7 @@ const points2TripProps = function (locationPoints: Array, e2: ServerData) { +const tsEntrySort = function (e1: BEMData, e2: BEMData) { // compare timestamps return e1.data.ts - e2.data.ts; }; @@ -369,7 +369,7 @@ const transitionTrip2TripObj = function (trip: Array) { ); const getSensorData = window['cordova'].plugins.BEMUserCache.getSensorDataForInterval; return getUnifiedDataForInterval('background/filtered_location', tq, getSensorData).then( - function (locationList: Array>) { + function (locationList: Array>) { if (locationList.length == 0) { return undefined; } @@ -426,7 +426,7 @@ const transitionTrip2TripObj = function (trip: Array) { }, ); }; -const isStartingTransition = function (transWrapper: ServerData) { +const isStartingTransition = function (transWrapper: BEMData) { if ( transWrapper.data.transition == 'local.transition.exited_geofence' || transWrapper.data.transition == 'T_EXITED_GEOFENCE' || @@ -437,7 +437,7 @@ const isStartingTransition = function (transWrapper: ServerData) return false; }; -const isEndingTransition = function (transWrapper: ServerData) { +const isEndingTransition = function (transWrapper: BEMData) { // Logger.log("isEndingTransition: transWrapper.data.transition = "+transWrapper.data.transition); if ( transWrapper.data.transition == 'T_TRIP_ENDED' || @@ -465,7 +465,7 @@ const isEndingTransition = function (transWrapper: ServerData) { * * Let's abstract this out into our own minor state machine. */ -const transitions2Trips = function (transitionList: Array>) { +const transitions2Trips = function (transitionList: Array>) { let inTrip = false; const tripList = []; let currStartTransitionIndex = -1; @@ -548,7 +548,7 @@ export function readUnprocessedTrips( ); const getMessageMethod = window['cordova'].plugins.BEMUserCache.getMessagesForInterval; return getUnifiedDataForInterval('statemachine/transition', tq, getMessageMethod).then(function ( - transitionList: Array>, + transitionList: Array>, ) { if (transitionList.length == 0) { logDebug('No unprocessed trips. yay!'); diff --git a/www/js/services/unifiedDataLoader.ts b/www/js/services/unifiedDataLoader.ts index 00f6e3027..5c06d33a5 100644 --- a/www/js/services/unifiedDataLoader.ts +++ b/www/js/services/unifiedDataLoader.ts @@ -1,12 +1,12 @@ import { getRawEntries } from './commHelper'; -import { ServerResponse, ServerData, TimeQuery } from '../types/serverData'; +import { ServerResponse, BEMData, TimeQuery } from '../types/serverData'; /** * removeDup is a helper function for combinedPromises * @param list An array of values from a BEMUserCache promise * @returns an array with duplicate values removed */ -export const removeDup = function (list: Array>) { +export const removeDup = function (list: Array>) { return list.filter(function (value, i, array) { const firstIndexOfValue = array.findIndex(function (element) { return element.metadata.write_ts == value.metadata.write_ts; diff --git a/www/js/types/diaryTypes.ts b/www/js/types/diaryTypes.ts index 87c4b1653..bfaee2a14 100644 --- a/www/js/types/diaryTypes.ts +++ b/www/js/types/diaryTypes.ts @@ -3,7 +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'; +import { BEMData, LocalDt } from './serverData'; import { FeatureCollection, Feature, Geometry } from 'geojson'; type ObjectId = { $oid: string }; @@ -86,7 +86,7 @@ export type CompositeTrip = { confirmed_trip: ObjectId; distance: number; duration: number; - end_confirmed_place: ServerData; + end_confirmed_place: BEMData; end_fmt_time: string; end_loc: { type: string; coordinates: number[] }; end_local_dt: LocalDt; @@ -103,7 +103,7 @@ export type CompositeTrip = { raw_trip: ObjectId; sections: any[]; // TODO source: string; - start_confirmed_place: ServerData; + start_confirmed_place: BEMData; start_fmt_time: string; start_loc: { type: string; coordinates: number[] }; start_local_dt: LocalDt; @@ -154,7 +154,7 @@ type UserInputData = { match_id?: string; }; -export type UserInputEntry = ServerData; +export type UserInputEntry = BEMData; export type Location = { speed: number; diff --git a/www/js/types/fileShareTypes.ts b/www/js/types/fileShareTypes.ts index 03b41a161..ee8d9a14e 100644 --- a/www/js/types/fileShareTypes.ts +++ b/www/js/types/fileShareTypes.ts @@ -1,6 +1,6 @@ -import { ServerData } from './serverData'; +import { BEMData } from './serverData'; -export type TimeStampData = ServerData; +export type TimeStampData = BEMData; export type RawTimelineData = { name: string; diff --git a/www/js/types/serverData.ts b/www/js/types/serverData.ts index 5c7aa38bf..b68078552 100644 --- a/www/js/types/serverData.ts +++ b/www/js/types/serverData.ts @@ -1,8 +1,8 @@ export type ServerResponse = { - phone_data: Array>; + phone_data: Array>; }; -export type ServerData = { +export type BEMData = { data: Type; metadata: MetaData; key?: string;