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

Tidy excessive logs #1165

Merged
merged 7 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions www/__tests__/customMetricsHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ it('has no footprint or mets before initialized', () => {

it('gets the custom mets', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
await initCustomDatasetHelper(appConfig!);
//expecting the keys from fakeLabels.json NOT metrics/metDataset.ts
expect(getCustomMETs()).toMatchObject({
walk: expect.any(Object),
Expand All @@ -51,7 +51,7 @@ it('gets the custom mets', async () => {

it('gets the custom footprint', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
await initCustomDatasetHelper(appConfig!);
//numbers from fakeLabels.json
expect(getCustomFootprint()).toMatchObject({
walk: 0,
Expand Down
8 changes: 4 additions & 4 deletions www/__tests__/dynamicConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ describe('dynamicConfig', () => {
const validToken = `nrelop_${validStudyNrelCommute}_user1`;
await initByUser({ token: validToken });
const config = await getConfig();
expect(config.server.connectUrl).toBe('https://nrel-commute-openpath.nrel.gov/api/');
expect(config.joined).toEqual({
expect(config!.server.connectUrl).toBe('https://nrel-commute-openpath.nrel.gov/api/');
expect(config!.joined).toEqual({
opcode: validToken,
study_name: validStudyNrelCommute,
subgroup: undefined,
Expand All @@ -87,8 +87,8 @@ describe('dynamicConfig', () => {
const validToken = `nrelop_${validStudyDenverCasr}_test_user1`;
await initByUser({ token: validToken });
const config = await getConfig();
expect(config.server.connectUrl).toBe('https://denver-casr-openpath.nrel.gov/api/');
expect(config.joined).toEqual({
expect(config!.server.connectUrl).toBe('https://denver-casr-openpath.nrel.gov/api/');
expect(config!.joined).toEqual({
opcode: validToken,
study_name: validStudyDenverCasr,
subgroup: 'test',
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 @@ -9,7 +9,7 @@ import {
} from '../js/survey/enketo/enketoHelper';
import { mockBEMUserCache } from '../__mocks__/cordovaMocks';
import { mockLogger } from '../__mocks__/globalMocks';
import { getConfig, _test_resetStoredConfig } from '../../www/js/config/dynamicConfig';
import { getConfig, _test_resetPromisedConfig } from '../../www/js/config/dynamicConfig';
import fakeConfig from '../__mocks__/fakeConfig.json';

import initializedI18next from '../js/i18nextInit';
Expand All @@ -24,7 +24,7 @@ global.URL = require('url').URL;
global.Blob = require('node:buffer').Blob;

beforeEach(() => {
_test_resetStoredConfig();
_test_resetPromisedConfig();
});

it('gets the survey config', async () => {
Expand All @@ -47,7 +47,7 @@ it('gets the survey config', async () => {
version: 9,
},
};
expect(config.survey_info.surveys).toMatchObject(mockSurveys);
expect(config!.survey_info.surveys).toMatchObject(mockSurveys);
});

it('gets the model response, if avaliable, or returns null', () => {
Expand Down
8 changes: 4 additions & 4 deletions www/__tests__/footprintHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const custom_metrics = [
*/
it('gets footprint for metrics (custom, fallback 0)', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
await initCustomDatasetHelper(appConfig!);
expect(getFootprintForMetrics(custom_metrics, 0)).toBe(2.4266);
});

Expand All @@ -61,14 +61,14 @@ it('gets footprint for metrics (custom, fallback 0)', async () => {
*/
it('gets footprint for metrics (custom, fallback 0.1)', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
await initCustomDatasetHelper(appConfig!);
expect(getFootprintForMetrics(custom_metrics, 0.1)).toBe(3.2266);
});

//expects TAXI from the fake labels
it('gets the highest footprint from the dataset, custom', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
await initCustomDatasetHelper(appConfig!);
expect(getHighestFootprint()).toBe(0.30741);
});

Expand All @@ -77,7 +77,7 @@ it('gets the highest footprint from the dataset, custom', async () => {
*/
it('gets the highest footprint for distance, custom', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
await initCustomDatasetHelper(appConfig!);
expect(getHighestFootprintForDistance(12345)).toBe(0.30741 * (12345 / 1000));
});

Expand Down
2 changes: 1 addition & 1 deletion www/__tests__/metHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ it('gets met for mode and speed', () => {

it('gets custom met for mode and speed', async () => {
const appConfig = await getConfig();
await initCustomDatasetHelper(appConfig);
await initCustomDatasetHelper(appConfig!);
expect(getMet('walk', 1.47523, 0)).toBe(4.3); //1.47523 mps = 3.299 mph -> 4.3 METs
expect(getMet('bike', 4.5, 0)).toBe(6.8); //4.5 mps = 10.07 mph = 6.8 METs
expect(getMet('unicycle', 100, 0)).toBe(0); //unkown mode, 0 METs
Expand Down
6 changes: 0 additions & 6 deletions www/js/components/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ const Chart = ({
? {}
: {
callback: (value, i) => {
logDebug(`Horizontal axis callback: i = ${i};
chartDatasets = ${JSON.stringify(chartDatasets)};
chartDatasets[0].data = ${JSON.stringify(chartDatasets[0].data)}`);
//account for different data possiblities
const label =
chartDatasets[0].data[i]?.y || chartDatasets[i].data[0]?.y;
Expand Down Expand Up @@ -185,9 +182,6 @@ const Chart = ({
? {}
: {
callback: (value, i) => {
logDebug(`Vertical axis callback: i = ${i};
chartDatasets = ${JSON.stringify(chartDatasets)};
chartDatasets[0].data = ${JSON.stringify(chartDatasets[0].data)}`);
//account for different data possiblities - one mode per week, one mode both weeks, mixed weeks
const label =
chartDatasets[0].data[i]?.x || chartDatasets[i].data[0]?.x;
Expand Down
24 changes: 12 additions & 12 deletions www/js/config/dynamicConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
export const CONFIG_PHONE_UI = 'config/app_ui_config';
export const CONFIG_PHONE_UI_KVSTORE = 'CONFIG_PHONE_UI';

export let storedConfig: AppConfig | null = null;
export let _promisedConfig: Promise<AppConfig | null> | undefined;
export let configChanged = false;
export const setConfigChanged = (b) => (configChanged = b);

// used to test multiple configs, not used outside of test
export const _test_resetStoredConfig = () => {
storedConfig = null;
export const _test_resetPromisedConfig = () => {
_promisedConfig = undefined;
};

/**
Expand Down Expand Up @@ -261,7 +261,7 @@
.then(([result, kvStoreResult]) => {
logDebug(`UI_CONFIG: Stored dynamic config in KVStore successfully,
result = ${JSON.stringify(kvStoreResult)}`);
storedConfig = toSaveConfig;
_promisedConfig = Promise.resolve(toSaveConfig);
configChanged = true;
return true;
})
Expand Down Expand Up @@ -298,25 +298,25 @@
* @returns The app config, either from a cached copy, retrieved from local storage, or retrieved
* from user cache with getDocument()
*/
export function getConfig(): Promise<AppConfig> {
if (storedConfig) return Promise.resolve(storedConfig);
return storageGet(CONFIG_PHONE_UI_KVSTORE).then((config) => {
export function getConfig(): Promise<AppConfig | null> {
if (_promisedConfig) return _promisedConfig;
let promise = storageGet(CONFIG_PHONE_UI_KVSTORE).then((config) => {
if (config && Object.keys(config).length) {
logDebug('Got config from KVStore: ' + JSON.stringify(config));
storedConfig = _backwardsCompatFill(config);
return storedConfig;
logDebug('Got config from KVStore: ');
return _backwardsCompatFill(config);

Check warning on line 306 in www/js/config/dynamicConfig.ts

View check run for this annotation

Codecov / codecov/patch

www/js/config/dynamicConfig.ts#L305-L306

Added lines #L305 - L306 were not covered by tests
}
logDebug('No config found in KVStore, fetching from native storage');
return window['cordova'].plugins.BEMUserCache.getDocument(CONFIG_PHONE_UI, false).then(
(config) => {
if (config && Object.keys(config).length) {
logDebug('Got config from native storage: ' + JSON.stringify(config));
storedConfig = _backwardsCompatFill(config);
return storedConfig;
return _backwardsCompatFill(config);
}
logWarn('No config found in native storage either. Returning null');
return null;
},
);
});
_promisedConfig = promise;
return promise;
}
3 changes: 2 additions & 1 deletion www/js/diary/LabelTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
// if either the trip before or after is displayed, then keep the untracked time
return prevTripDisplayed || nextTripDisplayed;
});
logDebug('After filtering, entriesToDisplay = ' + JSON.stringify(entriesToDisplay));
logDebug(`After filtering, displaying ${entriesToDisplay.length}

Check warning on line 102 in www/js/diary/LabelTab.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/diary/LabelTab.tsx#L102

Added line #L102 was not covered by tests
out of ${allEntries.length} entries`);
} else {
logDebug('No active filter, displaying all entries');
}
Expand Down
3 changes: 1 addition & 2 deletions www/js/diary/addressNamesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@
const coordsStr = loc_geojson.coordinates.toString();
const cachedResponse = localStorage.getItem(coordsStr);
if (cachedResponse) {
logDebug(`fetchNominatimLocName: found cached response for ${coordsStr} =
${cachedResponse}, skipping fetch`);
logDebug(`fetchNominatimLocName: found cached response for ${coordsStr}`);

Check warning on line 114 in www/js/diary/addressNamesHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/diary/addressNamesHelper.ts#L114

Added line #L114 was not covered by tests
return;
}
logDebug('Getting location name for ' + JSON.stringify(coordsStr));
Expand Down
8 changes: 1 addition & 7 deletions www/js/diary/timelineHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,7 @@ function tripTransitions2UnprocessedTrip(
startTs: tripStartTransition.data.ts,
endTs: tripEndTransition.data.ts,
};
logDebug(`About to pull location data for range:
${DateTime.fromSeconds(tripStartTransition.data.ts).toLocaleString(DateTime.DATETIME_MED)}
to
${DateTime.fromSeconds(tripEndTransition.data.ts).toLocaleString(DateTime.DATETIME_MED)}`);
logDebug(`About to pull location data for range: ${tq.startTs} to ${tq.endTs}`);
const getSensorData = window['cordova'].plugins.BEMUserCache.getSensorDataForInterval;
return getUnifiedDataForInterval('background/filtered_location', tq, getSensorData).then(
(locationList: Array<BEMData<FilteredLocation>>) => {
Expand Down Expand Up @@ -608,9 +605,6 @@ export function readUnprocessedTrips(
logDebug(`Found ${transitionList.length} transitions. yay!`);
const tripsList = transitions2TripTransitions(transitionList);
logDebug(`Mapped into ${tripsList.length} trips. yay!`);
tripsList.forEach((trip) => {
logDebug(JSON.stringify(trip, null, 2));
});
const tripFillPromises = tripsList.map((t) =>
tripTransitions2UnprocessedTrip(t, appConfig),
);
Expand Down
1 change: 0 additions & 1 deletion www/js/metrics/MetricsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ async function fetchAggMetrics(
};
return getAggregateData('result/metrics/yyyy_mm_dd', query, appConfig.server)
.then((response) => {
logDebug('MetricsTab: received aggMetrics');
console.debug('MetricsTab: received aggMetrics', response);
return response as MetricsData;
})
Expand Down
3 changes: 1 addition & 2 deletions www/js/metrics/customMetricsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ function populateCustomFootprints() {
*/
export async function initCustomDatasetHelper(newConfig: AppConfig) {
try {
logDebug('initializing custom datasets with config' + newConfig);
logDebug('initializing custom datasets');
const labelOptions = await getLabelOptions(newConfig);
logDebug('In custom metrics, label options = ' + JSON.stringify(labelOptions));
_labelOptions = labelOptions;
populateCustomMETs();
populateCustomFootprints();
Expand Down
Loading
Loading