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

🧹 📊 Metrics cleanup #1111

Merged
merged 15 commits into from
Feb 10, 2024
Merged

Conversation

Abby-Wheelis
Copy link
Member

Addressing code review from #1098 and codecov results from the same PR

Abby Wheelis added 2 commits December 4, 2023 10:48
from review, adding the calculations in comments with the tests helps to make the arithmetic more credible

e-mission#1098 (review)
adding specific numbers from fakeLabels.json for the footprints, but keeping the testing at just the keys for mets due to complexity

the keys in the fallback are different, so we can be sure here that the custom mets were accessed
Copy link

codecov bot commented Dec 4, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9ddcf31) 77.55% compared to head (6bfef79) 78.45%.
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1111      +/-   ##
==========================================
+ Coverage   77.55%   78.45%   +0.90%     
==========================================
  Files          28       28              
  Lines        1702     1699       -3     
  Branches      367      364       -3     
==========================================
+ Hits         1320     1333      +13     
+ Misses        382      366      -16     
Flag Coverage Δ
unit 78.45% <100.00%> (+0.90%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
www/js/metrics/customMetricsHelper.ts 95.91% <100.00%> (+17.91%) ⬆️
www/js/metrics/footprintHelper.ts 94.11% <ø> (+8.00%) ⬆️

... and 1 file with indirect coverage changes

checking the 'ON_FOOT' case
verifying negative speed returns 0, even if there is a fallback
@Abby-Wheelis
Copy link
Member Author

I made a discovery working through upping the codecov report - in both metHelper and footprintHelper we have some code that catches if the mode is 'ON_FOOT' and sets it to WALKING --
in metHelper this is great -- we have the met-equivalents and fallbacks, so it turns out the same as 'WALKING but in 'footprintHelper -- we are now always using custom modes, so we have things like walk and it does not recognize WALKING as a part of the list

For footprintHelper -- if the mode is ON_FOOT -- that means the energy value will always be 0, would it be bad to hardcode a return of 0 if the mode is ON_FOOT

Also, is there anywhere we still use ON_FOOT? I'm guessing this came from some previous iteration, as I don't think I've seen it in play as a base mode or label, is it still lurking somewhere? I suppose removing the code and allowing ON_FOOT to go to the default value is also an option.

@Abby-Wheelis
Copy link
Member Author

For footprintHelper -- if the mode is ON_FOOT -- that means the energy value will always be 0, would it be bad to hardcode a return of 0 if the mode is ON_FOOT

This is actually even more complicated when it comes to the IN_VEHICLE tests... since we don't know what all the vehicle modes are...
else if (mode == 'IN_VEHICLE') { const sum = footprint['CAR'] + footprint['BUS'] + footprint['LIGHT_RAIL'] + footprint['TRAIN'] + footprint['TRAM'] + footprint['SUBWAY']; result += (sum / 6) * mtokm(userMetrics[i].values); }

What do we want to do there? My first instinct would be to cache some sort of calculation of all the modes with IN_VEHCILE as a met-equivalent, but even that starts mixing the mets into the carbon calculations and could be overturned as we add user-custom labels, grid data, etc

Abby Wheelis added 2 commits December 4, 2023 15:33
added explicit throw of error and test to detect the thrown error, calculations now in try/catch block to account for errors

also now allowing "ON FOOT" to go to default

pending decision about "IN VEHICLE" for final coverage gap
also renamed the clearing function to ensure it was clear it was only for testing
@Abby-Wheelis
Copy link
Member Author

Something else I've found while looking into the code coverage: the range - limits for modes
I can see where this WAS used in the code, but I don't think it's used anymore. I believe this was something that might have influenced things like mode recommendations, but we don't currently have those, should I just take it out? I could also invent some labels just for the tests to test it, but I don't think any of the labels in production have this, and the code base doesn't have the feature.

test was failing because error was not thrown, it was handled, throwing error, which will be caught by the code that displays the metrics
@Abby-Wheelis
Copy link
Member Author

Screenshot 2023-12-04 at 4 02 53 PM
The few uncovered sections in the metrics files are now pending discussion of the above issues:

  • difference between default and fallback keys in the footprint calculations: how to handle ON_FOOT and IN_VEHICLE
  • range_limit_km - I believe this is a holdover from a previous feature (recommendations?) as we don't seem to use it, so the best course of action is probably to remove it for now, though I think I see a relatively easy path to get it covered by tests if we decide we want that.

Once we decide those two things, I think I can get the last few patches of lines tested.

Abby Wheelis added 3 commits December 5, 2023 14:15
After we talked about it in our meeting today, I'm going to go ahead and take this out, since we now have custom modes, really, either it's in the list or it is not, so we can't do this type of fallback anymore (at least not right now) it could be something to think about as we overhaul the metrics in upcoming months
This was old code, and no longer used

elected to take it out rather than test it, this concept is something we should keep in mind if we integrate suggestions back into the app (ie I can't e-bike from CO to GA, no matter how much emissions it would save)
this label has no co2 or met information, which hits some of the edge cases in the custom metrics code
@Abby-Wheelis
Copy link
Member Author

After discussion in our UI meeting today, I've gone ahead and removed the old code, which increased the code coverage, as that was most of what was not getting tested. I've tested in the emulator, and the dashboard is working well!

@Abby-Wheelis Abby-Wheelis marked this pull request as ready for review December 5, 2023 21:42
@Abby-Wheelis
Copy link
Member Author

After resolving merge conflicts and one issue the merge created this cleanup PR is ready again!

@Abby-Wheelis Abby-Wheelis changed the base branch from service_rewrite_2023 to master February 5, 2024 17:39
@Abby-Wheelis Abby-Wheelis changed the base branch from master to service_rewrite_2023 February 6, 2024 16:15
@Abby-Wheelis Abby-Wheelis changed the base branch from service_rewrite_2023 to master February 6, 2024 16:15
@shankari
Copy link
Contributor

shankari commented Feb 8, 2024

Also, is there anywhere we still use ON_FOOT? I'm guessing this came from some previous iteration, as I don't think I've seen it in play as a base mode or label, is it still lurking somewhere? I suppose removing the code and allowing ON_FOOT to go to the default value is also an option.

The android raw values include ON_FOOT. I believe that the server code converts to WALKING when we look at inferred sections, but the raw and cleaned values can still have ON_FOOT. If you look at the real examples in the server tests, you will see many examples of the expected result (aka "ground truth") having ON_FOOT

Something else I've found while looking into the code coverage: the range - limits for modes. I believe this was something that might have influenced things like mode recommendations, but we don't currently have those, should I just take it out?

Yes, take it out. We used to use it to compute the "optimal" footprint, but that is not relevant any more and will likely have to be redesigned when we work with recommendations.

Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there

www/__tests__/customMetricsHelper.test.ts Show resolved Hide resolved
www/js/metrics/customMetricsHelper.ts Show resolved Hide resolved
www/js/metrics/footprintHelper.ts Show resolved Hide resolved
@shankari shankari merged commit 3d06350 into e-mission:master Feb 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants