Skip to content

Commit

Permalink
Renamed ServerData to BEMData
Browse files Browse the repository at this point in the history
This better reflects the origin of this type: both BEMServerComm
and BEMUserCache return data of this structure.
  • Loading branch information
the-bay-kay committed Jan 24, 2024
1 parent a89f356 commit d54ce29
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions www/__mocks__/timelineHelperMocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MetaData, ServerData, ServerResponse } from '../js/types/serverData';
import { MetaData, BEMData, ServerResponse } from '../js/types/serverData';
import {
CompositeTrip,
ConfirmedPlace,
Expand Down Expand Up @@ -168,7 +168,7 @@ export const mockCompDataTwo = {
phone_data: [mockCompData.phone_data[0], newPhoneData],
};

export const mockTransitions: Array<ServerData<TripTransition>> = [
export const mockTransitions: Array<BEMData<TripTransition>> = [
{
data: {
// mock of a startTransition
Expand Down Expand Up @@ -208,7 +208,7 @@ mockFilterLocationTwo.ts = 900;
mockFilterLocationTwo.longitude = 200;
mockFilterLocationTwo.longitude = -200;

export const mockFilterLocations: Array<ServerData<FilteredLocation>> = [
export const mockFilterLocations: Array<BEMData<FilteredLocation>> = [
{
data: mockFilterLocation,
metadata: mockMetaData,
Expand Down
6 changes: 3 additions & 3 deletions www/__tests__/unifiedDataLoader.test.ts
Original file line number Diff line number Diff line change
@@ -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<any> = {
const testOne: BEMData<any> = {
data: '',
metadata: {
key: '',
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('removeDup can', () => {
});

// combinedPromises tests
const promiseGenerator = (values: Array<ServerData<any>>) => {
const promiseGenerator = (values: Array<BEMData<any>>) => {
return Promise.resolve(values);
};
const badPromiseGenerator = (input: string) => {
Expand Down
18 changes: 9 additions & 9 deletions www/js/diary/timelineHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<any>) => ({
const unpackServerData = (obj: BEMData<any>) => ({
...obj.data,
_id: obj._id,
key: obj.metadata.key,
Expand Down Expand Up @@ -296,7 +296,7 @@ const dateTime2localdate = function (currtime: DateTime, tz: string) {
};
};

const points2TripProps = function (locationPoints: Array<ServerData<FilteredLocation>>) {
const points2TripProps = function (locationPoints: Array<BEMData<FilteredLocation>>) {
const startPoint = locationPoints[0];
const endPoint = locationPoints[locationPoints.length - 1];
const tripAndSectionId = `unprocessed_${startPoint.data.ts}_${endPoint.data.ts}`;
Expand Down Expand Up @@ -348,7 +348,7 @@ const points2TripProps = function (locationPoints: Array<ServerData<FilteredLoca
};
};

const tsEntrySort = function (e1: ServerData<FilteredLocation>, e2: ServerData<FilteredLocation>) {
const tsEntrySort = function (e1: BEMData<FilteredLocation>, e2: BEMData<FilteredLocation>) {
// compare timestamps
return e1.data.ts - e2.data.ts;
};
Expand All @@ -369,7 +369,7 @@ const transitionTrip2TripObj = function (trip: Array<any>) {
);
const getSensorData = window['cordova'].plugins.BEMUserCache.getSensorDataForInterval;
return getUnifiedDataForInterval('background/filtered_location', tq, getSensorData).then(
function (locationList: Array<ServerData<FilteredLocation>>) {
function (locationList: Array<BEMData<FilteredLocation>>) {
if (locationList.length == 0) {
return undefined;

Check warning on line 374 in www/js/diary/timelineHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/diary/timelineHelper.ts#L374

Added line #L374 was not covered by tests
}
Expand Down Expand Up @@ -426,7 +426,7 @@ const transitionTrip2TripObj = function (trip: Array<any>) {
},
);
};
const isStartingTransition = function (transWrapper: ServerData<TripTransition>) {
const isStartingTransition = function (transWrapper: BEMData<TripTransition>) {
if (
transWrapper.data.transition == 'local.transition.exited_geofence' ||
transWrapper.data.transition == 'T_EXITED_GEOFENCE' ||
Expand All @@ -437,7 +437,7 @@ const isStartingTransition = function (transWrapper: ServerData<TripTransition>)
return false;
};

const isEndingTransition = function (transWrapper: ServerData<TripTransition>) {
const isEndingTransition = function (transWrapper: BEMData<TripTransition>) {
// Logger.log("isEndingTransition: transWrapper.data.transition = "+transWrapper.data.transition);
if (
transWrapper.data.transition == 'T_TRIP_ENDED' ||
Expand Down Expand Up @@ -465,7 +465,7 @@ const isEndingTransition = function (transWrapper: ServerData<TripTransition>) {
*
* Let's abstract this out into our own minor state machine.
*/
const transitions2Trips = function (transitionList: Array<ServerData<TripTransition>>) {
const transitions2Trips = function (transitionList: Array<BEMData<TripTransition>>) {
let inTrip = false;
const tripList = [];
let currStartTransitionIndex = -1;
Expand Down Expand Up @@ -548,7 +548,7 @@ export function readUnprocessedTrips(
);
const getMessageMethod = window['cordova'].plugins.BEMUserCache.getMessagesForInterval;
return getUnifiedDataForInterval('statemachine/transition', tq, getMessageMethod).then(function (
transitionList: Array<ServerData<TripTransition>>,
transitionList: Array<BEMData<TripTransition>>,
) {
if (transitionList.length == 0) {
logDebug('No unprocessed trips. yay!');
Expand Down
4 changes: 2 additions & 2 deletions www/js/services/unifiedDataLoader.ts
Original file line number Diff line number Diff line change
@@ -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<ServerData<any>>) {
export const removeDup = function (list: Array<BEMData<any>>) {
return list.filter(function (value, i, array) {
const firstIndexOfValue = array.findIndex(function (element) {
return element.metadata.write_ts == value.metadata.write_ts;
Expand Down
8 changes: 4 additions & 4 deletions www/js/types/diaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -86,7 +86,7 @@ export type CompositeTrip = {
confirmed_trip: ObjectId;
distance: number;
duration: number;
end_confirmed_place: ServerData<ConfirmedPlace>;
end_confirmed_place: BEMData<ConfirmedPlace>;
end_fmt_time: string;
end_loc: { type: string; coordinates: number[] };
end_local_dt: LocalDt;
Expand All @@ -103,7 +103,7 @@ export type CompositeTrip = {
raw_trip: ObjectId;
sections: any[]; // TODO
source: string;
start_confirmed_place: ServerData<ConfirmedPlace>;
start_confirmed_place: BEMData<ConfirmedPlace>;
start_fmt_time: string;
start_loc: { type: string; coordinates: number[] };
start_local_dt: LocalDt;
Expand Down Expand Up @@ -154,7 +154,7 @@ type UserInputData = {
match_id?: string;
};

export type UserInputEntry = ServerData<UserInputData>;
export type UserInputEntry = BEMData<UserInputData>;

export type Location = {
speed: number;
Expand Down
4 changes: 2 additions & 2 deletions www/js/types/fileShareTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ServerData } from './serverData';
import { BEMData } from './serverData';

export type TimeStampData = ServerData<RawTimelineData>;
export type TimeStampData = BEMData<RawTimelineData>;

export type RawTimelineData = {
name: string;
Expand Down
4 changes: 2 additions & 2 deletions www/js/types/serverData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export type ServerResponse<Type> = {
phone_data: Array<ServerData<Type>>;
phone_data: Array<BEMData<Type>>;
};

export type ServerData<Type> = {
export type BEMData<Type> = {
data: Type;
metadata: MetaData;
key?: string;
Expand Down

0 comments on commit d54ce29

Please sign in to comment.