-
Notifications
You must be signed in to change notification settings - Fork 114
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
📊 🦶 Metrics Services Rewrites #1098
Merged
shankari
merged 46 commits into
e-mission:service_rewrite_2023
from
Abby-Wheelis:metrics-services-rewrite
Dec 4, 2023
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
de49924
convert metrics services
70f7238
display message instead of error
5108352
reduce naming confusion
9118133
write footprinthelper tests
2cdd212
fix formatting
1a734f7
remove unused import
1d7bf5b
remove country-specific
1eec588
remove stale references
6102d62
remove dataset setting
b075738
increase message readability
ec4abff
ensure initialization of footprints
7820646
remove old MET code
7ebcc94
add tests for highest footprint
3943053
write tests for metHelper
7436502
custom dataset helper tests
974ac3a
remove carbon fallback
8c28737
remove unused code
deb7104
add docstrings
9153a60
resolve merge conflicts
9340297
working to debug dashboard
47daa3e
Merge remote-tracking branch 'upstream/service_rewrite_2023' into met…
acc8022
lift dataset initialization
a587440
Merge remote-tracking branch 'upstream/service_rewrite_2023' into met…
fa22ee4
remove use of `rootScope` in getAggregateData
JGreenlee 14a4c0d
Merge branch 'service_rewrite_2023' of https://github.com/e-mission/e…
JGreenlee 6cf3a80
patch for WSOD on dashboard
1693409
tweak to account for same mode both weeks
1f495e2
clean up bugfix
ef3bd59
renamed file
df8ec72
input Params -> labelOptions
c160788
footprint will always be custom
4c1a4a6
rename the metDatasets file
b655f4a
name updates, just one dataset
dec322f
prettier in Chart.tsx
a299574
remove debugging log statements
6272fb0
logDebug statements
6233af5
logWarn instead of console.warn
5918b6b
Rename CustomMetricsHelper.ts to customMetricsHelper.ts
Abby-Wheelis 125faff
cleaning up customMetrics
e626f6e
clarify "in vehicle" calculations
b040691
all mets are custom
51f6ece
await instead of timeout
3dee26f
Use expect.any(Type) for stricter testing
9a5753b
code style cleanup
JGreenlee bc2543b
Merge branch 'service_rewrite_2023' into metrics-services-rewrite
shankari 1006165
Merge branch 'service_rewrite_2023' into metrics-services-rewrite
shankari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
{ | ||
"MODE": [ | ||
{ | ||
"value": "walk", | ||
"baseMode": "WALKING", | ||
"met_equivalent": "WALKING", | ||
"kgCo2PerKm": 0 | ||
}, | ||
{ | ||
"value": "e-bike", | ||
"baseMode": "E_BIKE", | ||
"met": { | ||
"ALL": { | ||
"range": [0, -1], | ||
"mets": 4.9 | ||
} | ||
}, | ||
"kgCo2PerKm": 0.00728 | ||
}, | ||
{ | ||
"value": "bike", | ||
"baseMode": "BICYCLING", | ||
"met_equivalent": "BICYCLING", | ||
"kgCo2PerKm": 0 | ||
}, | ||
{ | ||
"value": "bikeshare", | ||
"baseMode": "BICYCLING", | ||
"met_equivalent": "BICYCLING", | ||
"kgCo2PerKm": 0 | ||
}, | ||
{ | ||
"value": "scootershare", | ||
"baseMode": "E_SCOOTER", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.00894 | ||
}, | ||
{ | ||
"value": "drove_alone", | ||
"baseMode": "CAR", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.22031 | ||
}, | ||
{ | ||
"value": "shared_ride", | ||
"baseMode": "CAR", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.11015 | ||
}, | ||
{ | ||
"value": "hybrid_drove_alone", | ||
"baseMode": "CAR", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.127 | ||
}, | ||
{ | ||
"value": "hybrid_shared_ride", | ||
"baseMode": "CAR", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.0635 | ||
}, | ||
{ | ||
"value": "e_car_drove_alone", | ||
"baseMode": "E_CAR", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.08216 | ||
}, | ||
{ | ||
"value": "e_car_shared_ride", | ||
"baseMode": "E_CAR", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.04108 | ||
}, | ||
{ | ||
"value": "taxi", | ||
"baseMode": "TAXI", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.30741 | ||
}, | ||
{ | ||
"value": "bus", | ||
"baseMode": "BUS", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.20727 | ||
}, | ||
{ | ||
"value": "train", | ||
"baseMode": "TRAIN", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.12256 | ||
}, | ||
{ | ||
"value": "free_shuttle", | ||
"baseMode": "BUS", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.20727 | ||
}, | ||
{ | ||
"value": "air", | ||
"baseMode": "AIR", | ||
"met_equivalent": "IN_VEHICLE", | ||
"kgCo2PerKm": 0.09975 | ||
}, | ||
{ | ||
"value": "not_a_trip", | ||
"baseMode": "UNKNOWN", | ||
"met_equivalent": "UNKNOWN", | ||
"kgCo2PerKm": 0 | ||
}, | ||
{ | ||
"value": "other", | ||
"baseMode": "OTHER", | ||
"met_equivalent": "UNKNOWN", | ||
"kgCo2PerKm": 0 | ||
} | ||
], | ||
"PURPOSE": [ | ||
{ | ||
"value": "home" | ||
}, | ||
{ | ||
"value": "work" | ||
}, | ||
{ | ||
"value": "at_work" | ||
}, | ||
{ | ||
"value": "school" | ||
}, | ||
{ | ||
"value": "transit_transfer" | ||
}, | ||
{ | ||
"value": "shopping" | ||
}, | ||
{ | ||
"value": "meal" | ||
}, | ||
{ | ||
"value": "pick_drop_person" | ||
}, | ||
{ | ||
"value": "pick_drop_item" | ||
}, | ||
{ | ||
"value": "personal_med" | ||
}, | ||
{ | ||
"value": "access_recreation" | ||
}, | ||
{ | ||
"value": "exercise" | ||
}, | ||
{ | ||
"value": "entertainment" | ||
}, | ||
{ | ||
"value": "religious" | ||
}, | ||
{ | ||
"value": "other" | ||
} | ||
], | ||
"REPLACED_MODE": [ | ||
{ | ||
"value": "no_travel" | ||
}, | ||
{ | ||
"value": "walk" | ||
}, | ||
{ | ||
"value": "bike" | ||
}, | ||
{ | ||
"value": "bikeshare" | ||
}, | ||
{ | ||
"value": "scootershare" | ||
}, | ||
{ | ||
"value": "drove_alone" | ||
}, | ||
{ | ||
"value": "shared_ride" | ||
}, | ||
{ | ||
"value": "e_car_drove_alone" | ||
}, | ||
{ | ||
"value": "e_car_shared_ride" | ||
}, | ||
{ | ||
"value": "taxi" | ||
}, | ||
{ | ||
"value": "bus" | ||
}, | ||
{ | ||
"value": "train" | ||
}, | ||
{ | ||
"value": "free_shuttle" | ||
}, | ||
{ | ||
"value": "other" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { getConfig } from '../js/config/dynamicConfig'; | ||
import { | ||
getCustomFootprint, | ||
getCustomMETs, | ||
initCustomDatasetHelper, | ||
} from '../js/metrics/customMetricsHelper'; | ||
import { mockBEMUserCache } from '../__mocks__/cordovaMocks'; | ||
import { mockLogger } from '../__mocks__/globalMocks'; | ||
import fakeLabels from '../__mocks__/fakeLabels.json'; | ||
|
||
mockBEMUserCache(); | ||
mockLogger(); | ||
|
||
global.fetch = (url: string) => | ||
new Promise((rs, rj) => { | ||
setTimeout(() => | ||
rs({ | ||
text: () => | ||
new Promise((rs, rj) => { | ||
let myJSON = JSON.stringify(fakeLabels); | ||
setTimeout(() => rs(myJSON), 100); | ||
}), | ||
}), | ||
); | ||
}) as any; | ||
|
||
it('gets the custom mets', async () => { | ||
const appConfig = await getConfig(); | ||
await initCustomDatasetHelper(appConfig); | ||
expect(getCustomMETs()).toMatchObject({ | ||
walk: expect.any(Object), | ||
bike: expect.any(Object), | ||
bikeshare: expect.any(Object), | ||
'e-bike': expect.any(Object), | ||
scootershare: expect.any(Object), | ||
drove_alone: expect.any(Object), | ||
}); | ||
}); | ||
|
||
it('gets the custom footprint', async () => { | ||
const appConfig = await getConfig(); | ||
await initCustomDatasetHelper(appConfig); | ||
expect(getCustomFootprint()).toMatchObject({ | ||
walk: expect.any(Number), | ||
bike: expect.any(Number), | ||
bikeshare: expect.any(Number), | ||
'e-bike': expect.any(Number), | ||
scootershare: expect.any(Number), | ||
drove_alone: expect.any(Number), | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { initCustomDatasetHelper } from '../js/metrics/customMetricsHelper'; | ||
import { | ||
clearHighestFootprint, | ||
getFootprintForMetrics, | ||
getHighestFootprint, | ||
getHighestFootprintForDistance, | ||
} from '../js/metrics/footprintHelper'; | ||
import { getConfig } from '../js/config/dynamicConfig'; | ||
import { mockBEMUserCache } from '../__mocks__/cordovaMocks'; | ||
import { mockLogger } from '../__mocks__/globalMocks'; | ||
import fakeLabels from '../__mocks__/fakeLabels.json'; | ||
|
||
mockBEMUserCache(); | ||
mockLogger(); | ||
|
||
global.fetch = (url: string) => | ||
new Promise((rs, rj) => { | ||
setTimeout(() => | ||
rs({ | ||
text: () => | ||
new Promise((rs, rj) => { | ||
let myJSON = JSON.stringify(fakeLabels); | ||
setTimeout(() => rs(myJSON), 100); | ||
}), | ||
}), | ||
); | ||
}) as any; | ||
|
||
beforeEach(() => { | ||
clearHighestFootprint(); | ||
}); | ||
|
||
const custom_metrics = [ | ||
{ key: 'walk', values: 3000 }, | ||
{ key: 'bike', values: 6500 }, | ||
{ key: 'drove_alone', values: 10000 }, | ||
{ key: 'scootershare', values: 25000 }, | ||
{ key: 'unicycle', values: 5000 }, | ||
]; | ||
|
||
it('gets footprint for metrics (custom, fallback 0)', async () => { | ||
const appConfig = await getConfig(); | ||
await initCustomDatasetHelper(appConfig); | ||
expect(getFootprintForMetrics(custom_metrics, 0)).toBe(2.4266); | ||
}); | ||
|
||
it('gets footprint for metrics (custom, fallback 0.1)', async () => { | ||
const appConfig = await getConfig(); | ||
await initCustomDatasetHelper(appConfig); | ||
expect(getFootprintForMetrics(custom_metrics, 0.1)).toBe(2.4266 + 0.5); | ||
}); | ||
|
||
it('gets the highest footprint from the dataset, custom', async () => { | ||
const appConfig = await getConfig(); | ||
await initCustomDatasetHelper(appConfig); | ||
expect(getHighestFootprint()).toBe(0.30741); | ||
}); | ||
|
||
it('gets the highest footprint for distance, custom', async () => { | ||
const appConfig = await getConfig(); | ||
await initCustomDatasetHelper(appConfig); | ||
expect(getHighestFootprintForDistance(12345)).toBe(0.30741 * (12345 / 1000)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { getMet } from '../js/metrics/metHelper'; | ||
import { mockBEMUserCache } from '../__mocks__/cordovaMocks'; | ||
import { mockLogger } from '../__mocks__/globalMocks'; | ||
import fakeLabels from '../__mocks__/fakeLabels.json'; | ||
import { getConfig } from '../js/config/dynamicConfig'; | ||
import { initCustomDatasetHelper } from '../js/metrics/customMetricsHelper'; | ||
|
||
mockBEMUserCache(); | ||
mockLogger(); | ||
|
||
global.fetch = (url: string) => | ||
new Promise((rs, rj) => { | ||
setTimeout(() => | ||
rs({ | ||
text: () => | ||
new Promise((rs, rj) => { | ||
let myJSON = JSON.stringify(fakeLabels); | ||
setTimeout(() => rs(myJSON), 100); | ||
}), | ||
}), | ||
); | ||
}) as any; | ||
|
||
it('gets met for mode and speed', () => { | ||
expect(getMet('WALKING', 1.47523, 0)).toBe(4.3); | ||
expect(getMet('BICYCLING', 4.5, 0)).toBe(6.8); | ||
expect(getMet('UNICYCLE', 100, 0)).toBe(0); | ||
expect(getMet('CAR', 25, 1)).toBe(0); | ||
}); | ||
|
||
it('gets custom met for mode and speed', async () => { | ||
const appConfig = await getConfig(); | ||
await initCustomDatasetHelper(appConfig); | ||
expect(getMet('walk', 1.47523, 0)).toBe(4.3); | ||
expect(getMet('bike', 4.5, 0)).toBe(6.8); | ||
expect(getMet('unicycle', 100, 0)).toBe(0); | ||
expect(getMet('drove_alone', 25, 1)).toBe(0); | ||
expect(getMet('e-bike', 6, 1)).toBe(4.9); | ||
expect(getMet('e-bike', 12, 1)).toBe(4.9); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you are not checking against the actual numbers? These are going to be the same numbers as in
fakeLabels.json
, correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably did not do this originally, because I was mostly trying to test the keys. The default keys are
WALKING
,BICYCLING
, etc, while the custom keys arewalk
,bike
, etc.I updated the footprint test, since that is a single value, but I have not updated the MET testing, since those objects are complex (some are speed dependent, etc), and taking the time to copy them over from
fakeLabels.json
seems like it would do more to test the test than the code, but I'll add a note about checking the keys!