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

Update carbon calculations for GIS server (richer modes) #576

Merged
merged 28 commits into from
Jul 2, 2019

Conversation

tms-martins
Copy link
Contributor

Update the carbon calculations so that they use the richer modes in the GIS-based server (ground_truth_matching branch).

  • Aggregate (average) data won't work properly on local servers, due to an outstanding issue.
  • In fillFootprintAggVals it can happen that that the mode ON_FOOT has a NaN value; a workaround was provided for that, but the source of the problem should be investigated (perhaps it is due to different modes in app VS server?)

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@shankari
Copy link
Contributor

shankari commented Jun 3, 2019

Aggregate (average) data won't work properly on local servers, due to an outstanding issue.

e-mission/e-mission-docs#288 is resolved (you need to modify the CSP in index.html). I had left it open to track potential enhancements, but now I've opened e-mission/e-mission-docs#408 instead.

@shankari
Copy link
Contributor

shankari commented Jun 3, 2019

In fillFootprintAggVals it can happen that that the mode ON_FOOT has a NaN value; a workaround was provided for that, but the source of the problem should be investigated (perhaps it is due to different modes in app VS server?)

Yes, the server supports both ON_FOOT and WALKING for sensed modes (the ones read from the phone API and smoothed) (emission/core/wrapper/motionactivity.py).

When the mode inference step is run successfully, both ON_FOOT and WALKING are collapsed to WALKING (emission/core/wrapper/modeprediction.py). You should assume that the mode is almost always WALKING with a fallback to ON_FOOT if it turns out that the mode inference step has been turned off or is not working for some reason.

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.

First round of obvious changes. Will do a more careful review of the real functionality changes in a bit.

www/index.html Outdated
@@ -106,6 +106,8 @@
<script src="lib/angular-nvd3/dist/angular-nvd3.min.js"></script>
<script src="lib/nz-tour/dist/nz-tour.min.js"></script>
<link rel="stylesheet" href="lib/nvd3/build/nv.d3.css">
<!-- TIAGO: allow debug with weinre -->
<script src="http://192.168.1.238:8090/target/target-script-min.js#anonymous"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove? Seems to be hardcoded to your IP.

return result;
}
fh.getLowestFootprintForDistance = function(distance) {
var lowestFootprint = 9999;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 9999 instead of Number.MAX_VALUE?

www/js/metrics-factory.js Show resolved Hide resolved
@@ -410,6 +410,9 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
delete clonedData.metric;
clonedData.metric_list = [DURATION, MEDIAN_SPEED, COUNT, DISTANCE];
clonedData.is_return_aggregate = true;
// TIAGO we should use our own server here, but for now it will return empty metrics, see:
Copy link
Contributor

Choose a reason for hiding this comment

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

I responded to this.

lastWeekCarbonInt = FootprintHelper.getFootprintForMetrics(userCarbonData);
}
else {
// TIAGO: -------------
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove these and similar before the final PR (they have my name on them so I can find them quickly).

www/json/connectionConfig.json Outdated Show resolved Hide resolved
www/templates/metrics/metrics-control.html Outdated Show resolved Hide resolved
@shankari
Copy link
Contributor

shankari commented Jun 3, 2019

Yes, the server supports both ON_FOOT and WALKING for sensed modes (the ones read from the phone API and smoothed) (emission/core/wrapper/motionactivity.py).

So I realized that we would need to handle both ON_FOOT and WALKING correctly anyway for the calorie calculations, so I went looking for it, and I found https://github.com/e-mission/e-mission-phone/blob/master/www/js/metrics.js#L832

So it looks like we convert all WALKING to ON_FOOT anyway. Given that, I am not sure why this should be NaN. Since you are still connecting to https://e-mission.eecs.berkeley.edu for the aggregates, I can try to debug this if you file a new issue.

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.

Just a few more fit and finish issues but rest looks good.
Functionality is fine, and if you file an issue for the NaN with more details on how to reproduce, I am happy to take a look.

www/js/metrics-factory.js Show resolved Hide resolved
www/js/metrics-factory.js Show resolved Hide resolved
www/js/metrics-factory.js Show resolved Hide resolved
www/js/metrics.js Show resolved Hide resolved
www/js/metrics-factory.js Show resolved Hide resolved
}
}

$scope.carbonData.aggrVehicleRange = FootprintHelper.getFootprintForMetrics(aggrCarbonData);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not your change, but I don't see this variable being used anywhere.
So you could remove it, since aggrCarbon seems to represent the same value anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

If not should probably rename to indicate that it is not a range any more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed :)

@tms-martins
Copy link
Contributor Author

tms-martins commented Jun 11, 2019

When the mode inference step is run successfully, both ON_FOOT and WALKING are collapsed to WALKING (emission/core/wrapper/modeprediction.py). You should assume that the mode is almost always WALKING with a fallback to ON_FOOT if it turns out that the mode inference step has been turned off or is not working for some reason.

Does this mean that in the app I will always use WALKING, including in the var footprint in metrics-factory.js; and that any label ON_FOOT should be treated as WALKING or even converted (in app) to 'WALKING'?

@tms-martins
Copy link
Contributor Author

When the mode inference step is run successfully, both ON_FOOT and WALKING are collapsed to WALKING (emission/core/wrapper/modeprediction.py). You should assume that the mode is almost always WALKING with a fallback to ON_FOOT if it turns out that the mode inference step has been turned off or is not working for some reason.

Does this mean that in the app I will always use WALKING, including in the var footprint in metrics-factory.js; and that any label ON_FOOT should be treated as WALKING or even converted (in app) to 'WALKING'?

@shankari need your input on this, I think it's the only outstanding issue in the PR - besides removing all my test code (e.g. console.debug()'s) of course 😉

www/js/metrics-factory.js Show resolved Hide resolved
www/js/metrics-factory.js Outdated Show resolved Hide resolved
www/js/metrics-factory.js Show resolved Hide resolved
www/index.html Outdated
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com http://nominatim.openstreetmap.org https://e-mission.eecs.berkeley.edu https://api.ionic.io/push/tokens emission: 'unsafe-eval'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: http://*.tile.openstreetmap.org http://tile.stamen.com https://*.tile.stamen.com http://*.tile.stamen.com 'unsafe-inline'">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com http://nominatim.openstreetmap.org http://192.168.1.238 https://api.ionic.io/push/tokens emission: 'unsafe-eval'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: http://*.tile.openstreetmap.org http://tile.stamen.com https://*.tile.stamen.com http://*.tile.stamen.com 'unsafe-inline'">
Copy link
Contributor

Choose a reason for hiding this comment

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

also remove from PR :)

@shankari
Copy link
Contributor

shankari commented Jun 17, 2019

@tms-martins
Sorry for the late review; had to turn in zeroth draft of thesis last night :)

Does this mean that in the app I will always use WALKING, including in the var footprint in metrics-factory.js; and that any label ON_FOOT should be treated as WALKING or even converted (in app) to 'WALKING'?

We already do this conversion in the app, but in the reverse direction.
https://github.com/e-mission/e-mission-phone/blob/master/www/js/metrics.js#L832

Sorry about the lack of consistency :(

I can fix that or you can fix it as part of the PR.
At the end, we should use WALKING everywhere, and the app should convert any ON_FOOT to WALKING

LMK what you prefer.

@tms-martins
Copy link
Contributor Author

We already do this conversion in the app, but in the reverse direction.
https://github.com/e-mission/e-mission-phone/blob/master/www/js/metrics.js#L832

At the end, we should use WALKING everywhere, and the app should convert any ON_FOOT to WALKING

LMK what you prefer.

When using the GIS-based server, it seems that ON_FOOT is only introduced there in getDataFromMetrics() since all the data I get from the server uses WALKING. So I would simply remove this conversion, if it doesn't break anything else (?).

It also begs the question: should I ever expect the mode RUNNING? If so, I have to either provide a carbon metric for this, or treat it as WALKING when calculating carbon footprints.

Nevertheless, should I always check server data for old modes (i.e. ON_FOOT) and replace with new ones (i.e. WALKING) before proceeding?

if (aggrCarbonData[i].key === "IN_VEHICLE") {
$scope.carbonData.aggrVehicleRange = FootprintHelper.getFootprintRaw(aggrCarbonData[i].values, aggrCarbonData[i].key);
$scope.carbonData.aggrCarbon = FootprintHelper.getFootprint(aggrCarbonData[i].values, aggrCarbonData[i].key);
if (isNaN(aggrCarbonData[i].values)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been investigated a bit more using the master phone branch and turned into an issue.
e-mission/e-mission-docs#422

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.

Although both master and your branch now have the changes in #584, the github file changes list still shows the changes in that PR mixed with your changes.

So I'm using a new compare
master...tms-martins:update_carbon_calc_for_GIS for this review.

Looks good barring the hardcoded IP addresses and TIAGO messages. Happy to merge once you have resolved those. Can you also add some testing screenshots or a testing video?

I am now investigating e-mission/e-mission-docs#422

www/json/connectionConfig.json Outdated Show resolved Hide resolved
fieldPhone = "ON_FOOT";
} else {
// if (field === "WALKING" || field === "RUNNING") {
// fieldPhone = "ON_FOOT";
Copy link
Contributor

Choose a reason for hiding this comment

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

if you are using WALKING everywhere, you should probably have the reverse of this, right? e.g. if returned as ON_FOOT, convert to WALKING.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or I guess you are handing this in the footprint calculations (e.g. getFootprintForMetrics). Any reason for the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I knew I didn't want to convert WALKINg to ON_FOOT; but removing/commenting that code was also lazy, because then I can have RUNNING labels which aren't handled in getFootprintForMetrics. I think a separate branch should address the mode consistency (i.e. check for and convert certain modes) at some point.
I will restore this line and avoid addressing the issue piecemeal before I break something :)

@tms-martins
Copy link
Contributor Author

I'm tidying up now, including removing the connectionConfig.json.
It may come as a surprise at this point, but I'm not using the complete toolchain. I've been developing and testing using the DevApp on an Android device, and using Weinre to view the console and inspect UI elements. If you feel that this may open up the possibility of inconsistent behavior once the app is actually built for Android/iOS please let me know.

@tms-martins
Copy link
Contributor Author

the github file changes list still shows the changes in that PR mixed with your changes.

Yes. I rebased my branch, and when I looked at the GitHub diff last time all looked well. I don't know exactly why this happens, although I've seen it before. I'm afraid that if I try to fix it now I end up making matters worse.

@tms-martins
Copy link
Contributor Author

Tidied up. @shankari what is the best way to add testing videos? Something like G Drive or is there a Git Repo for those?

@tms-martins
Copy link
Contributor Author

the github file changes list still shows the changes in that PR mixed with your changes.

Yes. I rebased my branch, and when I looked at the GitHub diff last time all looked well. I don't know exactly why this happens, although I've seen it before. I'm afraid that if I try to fix it now I end up making matters worse.

I've read up that the PR-diff is made "against the common ancestor of the source branch and the target branch". Also that a quick fix is to use the edit button to temporarily change the base to something other than master and then back again, which forces Git to update the PR.

@shankari
Copy link
Contributor

shankari commented Jul 1, 2019

I'm afraid that if I try to fix it now I end up making matters worse.

No worries. I can just review off the compare since I don't expect to have a lot of review comments.

@shankari
Copy link
Contributor

shankari commented Jul 1, 2019

Tidied up. @shankari what is the best way to add testing videos? Something like G Drive or is there a Git Repo for those?

G Drive is fine. I typically make the video short and gzip it so that I can upload it to github directly (.gz extensions are supported).

@shankari
Copy link
Contributor

shankari commented Jul 1, 2019

I've been developing and testing using the DevApp on an Android device, and using Weinre to view the console and inspect UI elements. If you feel that this may open up the possibility of inconsistent behavior once the app is actually built for Android/iOS please let me know.

This should not be an issue. I also use the devapp for my development and it has been pretty reliable in translating to real devices.

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.

Otherwise all looks good. Will merge as soon as I see testing video.

www/index.html Show resolved Hide resolved
www/js/metrics.js Outdated Show resolved Hide resolved
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.

I don't see anything else obviously wrong. Will merge as soon as I see testing video :)

@tms-martins
Copy link
Contributor Author

@shankari Testing video is here. I'm not sure if there were specific guidelines to follow; in case I'm missing something please let me know.

@shankari
Copy link
Contributor

shankari commented Jul 2, 2019

Video looks good.

@shankari shankari merged commit e0b6169 into e-mission:master Jul 2, 2019
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.

4 participants