Skip to content

Commit

Permalink
fix footprint calculations using baseModes
Browse files Browse the repository at this point in the history
The footprint calculations were not using because we were looking up footprints by rich mode and we needed to be looking up by base mode.
  • Loading branch information
JGreenlee committed Sep 12, 2023
1 parent 7d2b9dc commit 5fcc5d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions www/js/diary/diaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export function getBaseModeOfLabeledTrip(trip, labelOptions) {
return getBaseModeByKey(modeOption?.baseMode || "OTHER");
}

export function getBaseModeByValue(value, labelOptions: LabelOptions) {
const modeOption = labelOptions?.MODE?.find(opt => opt.value == value);
return getBaseModeByKey(modeOption?.baseMode || "OTHER");
}

export function getBaseModeByText(text, labelOptions: LabelOptions) {
const modeOption = labelOptions?.MODE?.find(opt => opt.text == text);
return getBaseModeByKey(modeOption?.baseMode || "OTHER");
Expand Down
21 changes: 11 additions & 10 deletions www/js/metrics-factory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

import angular from 'angular';
import { getBaseModeByValue } from './diary/diaryHelper'
import { labelOptions } from './survey/multilabel/confirmHelper';

angular.module('emission.main.metrics.factory',
['emission.main.metrics.mappings',
Expand Down Expand Up @@ -34,18 +36,17 @@ angular.module('emission.main.metrics.factory',
var footprint = fh.getFootprint();
var result = 0;
for (var i in userMetrics) {
var mode = userMetrics[i].key;
if (mode == 'ON_FOOT') {
mode = 'WALKING';
const baseMode = getBaseModeByValue(userMetrics[i].key, labelOptions).name;
if (baseMode == 'ON_FOOT') {
baseMode = 'WALKING';
}
if (mode in footprint) {
result += footprint[mode] * mtokm(userMetrics[i].values);
}
else if (mode == 'IN_VEHICLE') {

if (baseMode in footprint) {
result += footprint[baseMode] * mtokm(userMetrics[i].values);
} else if (baseMode == 'IN_VEHICLE') {
result += ((footprint['CAR'] + footprint['BUS'] + footprint["LIGHT_RAIL"] + footprint['TRAIN'] + footprint['TRAM'] + footprint['SUBWAY']) / 6) * mtokm(userMetrics[i].values);
}
else {
console.warn('WARNING FootprintHelper.getFootprintFromMetrics() was requested for an unknown mode: ' + mode + " metrics JSON: " + JSON.stringify(userMetrics));
} else {
console.warn('WARNING FootprintHelper.getFootprintFromMetrics() was requested for an unknown mode: ' + baseMode + " metrics JSON: " + JSON.stringify(userMetrics));
result += defaultIfMissing * mtokm(userMetrics[i].values);
}
}
Expand Down

0 comments on commit 5fcc5d4

Please sign in to comment.