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

✏️📖 Diary Services Rewrite #1085

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
6c23b2d
Updated `diaryHelper.ts`, now uses luxon
the-bay-kay Oct 26, 2023
062828e
Removed moment from timelineHelper
the-bay-kay Oct 26, 2023
5ade8b7
Updated readAllCompositeTrips function
the-bay-kay Oct 26, 2023
dd05c89
Merge branch 'unifiedDataLoader-rewrite' into diaryServices-rewrite
the-bay-kay Oct 26, 2023
545d407
Merge branch 'service_rewrite_2023' of https://github.com/e-mission/e…
the-bay-kay Oct 30, 2023
7a4b6fb
Rewrote readUnprocessedTrips, helper functions
the-bay-kay Nov 2, 2023
b5736a1
Fully removed angular service
the-bay-kay Nov 2, 2023
dd238e6
Merge branch 'type_interfaces' into diaryServices-rewrite
the-bay-kay Nov 2, 2023
8e2022f
Merge branch 'service_rewrite_2023' into diaryServices-rewrite
the-bay-kay Nov 2, 2023
7c7f4d8
Fixed error in prettier merge
the-bay-kay Nov 2, 2023
356dfcf
Ran prettier on remaining files
the-bay-kay Nov 3, 2023
6dcf1ab
Removed $ionicLoading
the-bay-kay Nov 6, 2023
651876b
Merge branch 'type_interfaces' into diaryServices-rewrite
the-bay-kay Nov 7, 2023
2bcdac8
Added basic timelineHelper tests
the-bay-kay Nov 8, 2023
ae5ae95
Updated issue with index.html
the-bay-kay Nov 8, 2023
1326940
Merge branch 'type_interfaces' into diaryServices-rewrite
the-bay-kay Nov 9, 2023
efa96e0
Improved mocks, added unit tests
the-bay-kay Nov 9, 2023
13206e9
Updated mocks, added tests
the-bay-kay Nov 9, 2023
f031d33
Moved mockData to separate file for legibility
the-bay-kay Nov 9, 2023
2e1a402
Deepcopy wasn't necessary, removed Parse/stringify
the-bay-kay Nov 9, 2023
adab677
Added clarifying comment, adjusted DateTime format
the-bay-kay Nov 9, 2023
2d0d321
Expanded mocks, sured up tests
the-bay-kay Nov 9, 2023
bf91301
Minor adjustment to tests
the-bay-kay Nov 9, 2023
7e1790e
Merge branch 'service_rewrite_2023' into diaryServices-rewrite
the-bay-kay Nov 9, 2023
f4b0e2d
Ran prettier on LabelTab merge
the-bay-kay Nov 9, 2023
db8c7ad
Merge branch 'service_rewrite_2023' into diaryServices-rewrite
the-bay-kay Nov 15, 2023
a2426c4
Fixed service imports, removed Angular import
the-bay-kay Nov 15, 2023
08c10f2
Rewrote first tests, mocks, ran prettier
the-bay-kay Nov 15, 2023
e6a21ca
Updated second diaryServices test
the-bay-kay Nov 15, 2023
2e2e2a3
Merge branch 'service_rewrite_2023' into type_interfaces
the-bay-kay Nov 15, 2023
361cc28
Separated `labelTypes` into separate file
the-bay-kay Nov 15, 2023
570d7a7
Merge branch 'type_interfaces' into diaryServices-rewrite
the-bay-kay Nov 15, 2023
691aeb5
Added test for useGeojsonForTrip
the-bay-kay Nov 15, 2023
84d675a
Added test for compositeTrips2TimelineMap
the-bay-kay Nov 16, 2023
163dbb2
Merge branch 'service_rewrite_2023' into diaryServices-rewrite
the-bay-kay Nov 16, 2023
a2b5da5
Added tests for keysForNotesInputs
the-bay-kay Nov 16, 2023
20f5441
Minor review changes, updated GeoJSON Typing
the-bay-kay Nov 18, 2023
25a064d
Fixes missing timezone conversions
the-bay-kay Nov 20, 2023
fd0c1ab
Added npm package, fixed HTML formatting
the-bay-kay Nov 20, 2023
9a20378
Added localization for trip duration
the-bay-kay Nov 21, 2023
d27cefe
Fixed trip start/end formatting error
the-bay-kay Nov 21, 2023
fe3d417
Filled out typing for timelineHelper functions
the-bay-kay Nov 22, 2023
667fec8
Expanded diaryTypes
the-bay-kay Nov 22, 2023
07c5f80
Added test for readUnprocessedTrips
the-bay-kay Nov 23, 2023
0d1717d
Added tests for updateUnprocessedInputs
the-bay-kay Nov 30, 2023
d93da07
Bug fix for Enekto Survey
the-bay-kay Dec 1, 2023
b59c65f
Update www/js/diary/diaryHelper.ts
the-bay-kay Dec 4, 2023
92f4a64
Updated tests for luxon time conversion
the-bay-kay Dec 4, 2023
e3dc66f
Cleaned up code
the-bay-kay Dec 4, 2023
d844466
add TimestampRange type
JGreenlee Dec 4, 2023
c42665f
add getMessagesForInterval to BEMUserCache mock
JGreenlee Dec 4, 2023
650564a
add tests for updateLocalUnprocessedInputs
JGreenlee Dec 4, 2023
1cb28c6
Merge branch 'diaryServices-rewrite' of https://github.com/the-bay-ka…
JGreenlee Dec 4, 2023
b6b7c94
Merge branch 'service_rewrite_2023' of https://github.com/e-mission/e…
JGreenlee Dec 4, 2023
356336c
fix diaryTypes
JGreenlee Dec 4, 2023
f80deb9
fix timelineHelper test
JGreenlee Dec 4, 2023
4d664ad
fix up timelineHelper tests
JGreenlee Dec 6, 2023
aa8cbe4
fix broken start time on draft trips
JGreenlee Dec 6, 2023
dfbee1f
Merge branch 'service_rewrite_2023' into diaryServices-rewrite
shankari Jan 20, 2024
1fb7c95
Fix formatting error introduced by merge code
shankari Jan 20, 2024
e69138b
Merge branch 'service_rewrite_2023' into diaryServices-rewrite
the-bay-kay Jan 23, 2024
a89f356
Update func param types, fix func formatting
the-bay-kay Jan 24, 2024
d54ce29
Renamed `ServerData` to BEMData
the-bay-kay Jan 24, 2024
cdb7138
Imporved test in `timelineHelper.test.ts`
the-bay-kay Jan 25, 2024
95d6255
Ran prettier from `www/`
the-bay-kay Jan 25, 2024
9f73f74
Updated diaryTypes to use GeoJSON `Point`
the-bay-kay Jan 25, 2024
f54257b
Prettier after `Point` change
the-bay-kay Jan 25, 2024
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: 2 additions & 0 deletions package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"@react-navigation/native": "^6.1.7",
"@react-navigation/stack": "^6.3.17",
"@shopify/flash-list": "^1.3.1",
"@types/leaflet": "1.9.4",
"angular": "1.6.7",
"angular-animate": "1.6.7",
"angular-local-storage": "^0.7.1",
Expand Down Expand Up @@ -145,6 +146,7 @@
"enketo-transformer": "^4.0.0",
"fast-xml-parser": "^4.2.2",
"fs-extra": "^9.0.1",
"humanize-duration": "3.31.0",
"i18next": "^22.5.0",
"install": "^0.13.0",
"ionic-datepicker": "1.2.1",
Expand Down
2 changes: 2 additions & 0 deletions package.serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@react-navigation/stack": "^6.3.17",
"@shopify/flash-list": "^1.3.1",
"@types/jest": "^29.5.5",
"@types/leaflet": "1.9.4",
"angular": "1.6.7",
"angular-animate": "1.6.7",
"angular-local-storage": "^0.7.1",
Expand All @@ -76,6 +77,7 @@
"enketo-transformer": "^4.0.0",
"fast-xml-parser": "^4.2.2",
"fs-extra": "^9.0.1",
"humanize-duration": "3.31.0",
"i18next": "^22.5.0",
"install": "^0.13.0",
"ionic-datepicker": "1.2.1",
Expand Down
27 changes: 23 additions & 4 deletions www/__mocks__/cordovaMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ export const mockFile = () => {
//for consent document
const _storage = {};

type MessageData = any;
type Message = { key: string; data: MessageData; metadata: { write_ts: number; [k: string]: any } };
export const mockBEMUserCache = (config?) => {
const _cache = {};
const messages = [];
const messages: Message[] = [];
const mockBEMUserCache = {
getLocalStorage: (key: string, isSecure: boolean) => {
return new Promise((rs, rj) =>
Expand Down Expand Up @@ -98,18 +100,35 @@ export const mockBEMUserCache = (config?) => {
putMessage: (key: string, value: any) => {
return new Promise<void>((rs, rj) =>
setTimeout(() => {
messages.push({ key, value });
messages.push({
key,
data: value,
// write_ts is epoch time in seconds
metadata: { write_ts: Math.floor(Date.now() / 1000) },
});
rs();
}, 100),
);
},
getAllMessages: (key: string, withMetadata?: boolean) => {
return new Promise<any[]>((rs, rj) =>
return new Promise<Message[] | MessageData[]>((rs, rj) =>
setTimeout(() => {
rs(messages.filter((m) => m.key == key).map((m) => m.value));
rs(messages.filter((m) => m.key == key).map((m) => (withMetadata ? m : m.data)));
}, 100),
);
},
getMessagesForInterval: (key: string, tq, withMetadata?: boolean) => {
return new Promise<Message[] | MessageData[]>((rs, rj) =>
setTimeout(() => {
rs(
messages
.filter((m) => m.key == key)
.filter((m) => m.metadata[tq.key] >= tq.startTs && m.metadata.write_ts <= tq.endTs)
.map((m) => (withMetadata ? m : m.data)),
);
}, 100),
);
}, // Used for getUnifiedDataForInterval
putRWDocument: (key: string, value: any) => {
if (key == 'config/app_ui_config') {
return new Promise<void>((rs, rj) =>
Expand Down
256 changes: 256 additions & 0 deletions www/__mocks__/timelineHelperMocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
import { MetaData, BEMData, ServerResponse } from '../js/types/serverData';
import {
CompositeTrip,
ConfirmedPlace,
FilteredLocation,
TripTransition,
UnprocessedTrip,
} from '../js/types/diaryTypes';
import { LabelOptions } from '../js/types/labelTypes';
import { AppConfig } from '../js/types/appConfigTypes';

const mockMetaData: MetaData = {
write_ts: 1,
key: 'test/value/one',
platform: 'test',
time_zone: 'America/Los_Angeles',
write_fmt_time: '1969-07-16T07:01:49.000Z',
write_local_dt: null,
origin_key: '1',
};

export const mockLabelOptions: LabelOptions = {
MODE: null,
PURPOSE: null,
REPLACED_MODE: null,
translations: null,
};

const mockConfirmedPlaceData: ConfirmedPlace = {
source: 'DwellSegmentationTimeFilter',
key: null,
origin_key: null,
location: {
type: 'Point',
coordinates: [-122.0876886, 37.3887767],
},
cleaned_place: null,
additions: [],
user_input: {},
enter_fmt_time: '2015-07-22T08:14:53.881000-07:00',
exit_fmt_time: '2015-07-22T08:14:53.881000-07:00',
starting_trip: null,
ending_trip: null,
enter_local_dt: null,
exit_local_dt: null,
raw_places: [null, null],
enter_ts: 1437578093.881,
exit_ts: 1437578093.881,
};
// using parse/stringify to deep copy & populate data
let tempMetaData = JSON.parse(JSON.stringify(mockMetaData));
tempMetaData.write_ts = 2;
tempMetaData.origin_key = '2';
export const mockMetaDataTwo = tempMetaData;

export const mockUnprocessedTrip: UnprocessedTrip = {
_id: { $oid: 'mockUnprocessedTrip' },
additions: [],
confidence_threshold: 0.0,
distance: 1.0,
duration: 3.0,
end_fmt_time: '',
end_loc: { type: 'Point', coordinates: [] },
end_local_dt: null,
expectation: null,
inferred_labels: [],
key: 'mockUnprocessedTrip',
locations: [],
origin_key: '',
source: '',
start_local_dt: null,
start_ts: 0.1,
start_loc: { type: 'Point', coordinates: [] },
starting_trip: null,
user_input: null,
};

export const mockCompData: ServerResponse<CompositeTrip> = {
phone_data: [
{
data: {
_id: { $oid: 'mockDataOne' },
additions: [],
cleaned_section_summary: null,
cleaned_trip: null,
confidence_threshold: -1,
confirmed_trip: null,
distance: 777,
duration: 777,
end_confirmed_place: {
data: mockConfirmedPlaceData,
metadata: mockMetaData,
_id: { $oid: 'endConfirmedPlace' },
},
end_fmt_time: '2023-11-01T17:55:20.999397-07:00',
end_loc: {
type: 'Point',
coordinates: [-1, -1],
},
end_local_dt: null,
end_place: null,
end_ts: -1,
expectation: null,
expected_trip: null,
inferred_labels: [],
inferred_section_summary: {
count: {
CAR: 1,
WALKING: 1,
},
distance: {
CAR: 222,
WALKING: 222,
},
duration: {
CAR: 333,
WALKING: 333,
},
},
inferred_trip: null,
key: '12345',
locations: [
{
metadata: mockMetaData,
data: null,
},
],
origin_key: '',
raw_trip: null,
sections: [
{
metadata: mockMetaData,
data: null,
},
],
source: 'DwellSegmentationDistFilter',
start_confirmed_place: {
data: mockConfirmedPlaceData,
metadata: mockMetaData,
_id: { $oid: 'startConfirmedPlace' },
},
start_fmt_time: '2023-11-01T17:55:20.999397-07:00',
start_loc: {
type: 'Point',
coordinates: [-1, -1],
},
start_local_dt: null,
start_place: null,
start_ts: 1,
user_input: null,
},
metadata: mockMetaData,
},
],
};
// Setup for second mockData
let newPhoneData = JSON.parse(JSON.stringify(mockCompData.phone_data[0]));
newPhoneData.data._id.$oid = 'mockDataTwo';
newPhoneData.metadata = mockMetaDataTwo;
newPhoneData.data.start_confirmed_place.metadata = mockMetaDataTwo;
newPhoneData.data.start_confirmed_place._id.$oid = 'startConfirmedPlaceTwo';
newPhoneData.data.end_confirmed_place.metadata = mockMetaDataTwo;
newPhoneData.data.end_confirmed_place._id.$oid = 'endConfirmedPlaceTwo';
export const mockCompDataTwo = {
phone_data: [mockCompData.phone_data[0], newPhoneData],
};

export const mockTransitions: Array<BEMData<TripTransition>> = [
{
data: {
// mock of a startTransition
currstate: '',
transition: 'T_EXITED_GEOFENCE',
ts: 1,
},
metadata: mockMetaData,
},
{
data: {
// mock of an endTransition
currstate: '',
transition: 'T_TRIP_ENDED',
ts: 9999,
},
metadata: mockMetaData,
},
];

const mockFilterLocation: FilteredLocation = {
accuracy: 0.1,
altitude: 100,
elapsedRealtimeNanos: 10000,
filter: 'time',
fmt_time: '',
heading: 1.0,
latitude: 1.0,
loc: null,
local_dt: null,
longitude: -1.0,
sensed_speed: 0,
ts: 100,
};
let mockFilterLocationTwo = JSON.parse(JSON.stringify(mockFilterLocation));
mockFilterLocationTwo.ts = 900;
mockFilterLocationTwo.longitude = 200;
mockFilterLocationTwo.longitude = -200;

export const mockFilterLocations: Array<BEMData<FilteredLocation>> = [
{
data: mockFilterLocation,
metadata: mockMetaData,
},
{
data: mockFilterLocationTwo,
metadata: mockMetaDataTwo,
},
];

export const mockConfigModeOfStudy: AppConfig = {
server: null,
survey_info: {
'trip-labels': 'MULTILABEL',
surveys: null,
},
intro: {
mode_studied: 'sample_study',
},
};
export const mockConfigNoModeOfStudy: AppConfig = {
server: null,
survey_info: {
'trip-labels': 'MULTILABEL',
surveys: null,
},
intro: {},
};
export const mockConfigEnketo: AppConfig = {
server: null,
survey_info: {
'trip-labels': 'ENKETO',
surveys: {
TripConfirmSurvey: {
compatibleWith: 1.2,
formPath: null,
labelTemplate: null,
version: null,
},
},
},
};

// Used by jest.mocks() to return a various mocked objects.
export const fakeStartTsOne = -14576291;
export const fakeEndTsOne = -13885091;
export const fakeStartTsTwo = 1092844665;
export const fakeEndTsTwo = 1277049465;
7 changes: 5 additions & 2 deletions www/__tests__/diaryHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import {
modeColors,
} from '../js/diary/diaryHelper';

import initializedI18next from '../js/i18nextInit';
window['i18next'] = initializedI18next;

it('returns a formatted date', () => {
expect(getFormattedDate('2023-09-18T00:00:00-07:00')).toBe('Mon September 18, 2023');
expect(getFormattedDate('2023-09-18T00:00:00-07:00')).toBe('Mon, September 18, 2023');
expect(getFormattedDate('')).toBeUndefined();
expect(getFormattedDate('2023-09-18T00:00:00-07:00', '2023-09-21T00:00:00-07:00')).toBe(
'Mon September 18, 2023 - Thu September 21, 2023',
'Mon, September 18, 2023 - Thu, September 21, 2023',
);
});

Expand Down
6 changes: 3 additions & 3 deletions www/__tests__/enketoHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ it('loads the previous response to a given survey', () => {
*/
it('filters the survey responses by their name and version', () => {
//no response -> no filtered responses
expect(filterByNameAndVersion('TimeUseSurvey', [])).resolves.toStrictEqual([]);
expect(filterByNameAndVersion('TimeUseSurvey', [], fakeConfig)).toStrictEqual([]);

const response = [
{
Expand All @@ -294,7 +294,7 @@ it('filters the survey responses by their name and version', () => {
];

//one response -> that response
expect(filterByNameAndVersion('TimeUseSurvey', response)).resolves.toStrictEqual(response);
expect(filterByNameAndVersion('TimeUseSurvey', response, fakeConfig)).toStrictEqual(response);

const responses = [
{
Expand Down Expand Up @@ -336,5 +336,5 @@ it('filters the survey responses by their name and version', () => {
];

//several responses -> only the one that has a name match
expect(filterByNameAndVersion('TimeUseSurvey', responses)).resolves.toStrictEqual(response);
expect(filterByNameAndVersion('TimeUseSurvey', responses, fakeConfig)).toStrictEqual(response);
});
Loading
Loading