Skip to content

Commit

Permalink
Merge pull request #95 from shankari/release_v_13
Browse files Browse the repository at this point in the history
Minor fixes before pushing the final release
  • Loading branch information
shankari authored Jul 29, 2016
2 parents 08ff2f2 + a0836bd commit 2c98c4f
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 53 deletions.
6 changes: 3 additions & 3 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="edu.berkeley.eecs.emission"
version="0.0.12"
android-versionCode="12"
ios-CFBundleVersion="12"
version="1.0.0"
android-versionCode="13"
ios-CFBundleVersion="13"
xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>emission</name>
<description>
Expand Down
4 changes: 2 additions & 2 deletions www/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ html, body, #chart2, svg {
}
.metric-metric-button {
float: left;
width: 49%;
width: 33%;
border-radius: 5px;
background-color: white;
box-shadow: 0 1px 2px rgba(0,0,0,0.03), 0 1px 2px rgba(0,0,0,0.05);
Expand Down Expand Up @@ -960,7 +960,7 @@ html, body, #chart2, svg {
}
.heatmap-get-button {
float: right;
width: 49%;
width: 30%;
border-radius: 5px;
background-color: white;
box-shadow: 0 1px 2px rgba(0,0,0,0.03), 0 1px 2px rgba(0,0,0,0.05);
Expand Down
5 changes: 5 additions & 0 deletions www/js/diary/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ angular.module('emission.main.diary.detail',['ui-leaflet',
console.log("diary/detail received resize event, invalidating map size");
data.leafletObject.invalidateSize();
});

$scope.refreshTiles = function() {
$scope.$broadcast('invalidateSize');
};

$scope.getFormattedDate = DiaryHelper.getFormattedDate;
$scope.arrowColor = DiaryHelper.arrowColor;
$scope.parseEarlierOrLater = DiaryHelper.parseEarlierOrLater;
Expand Down
3 changes: 2 additions & 1 deletion www/js/diary/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ angular.module('emission.main.diary.list',['ui-leaflet',
}

$scope.datepickerObject = {

todayLabel: 'Today', //Optional
closeLabel: 'Close', //Optional
setLabel: 'Set', //Optional
Expand Down Expand Up @@ -208,6 +208,7 @@ angular.module('emission.main.diary.list',['ui-leaflet',
$scope.refresh = function() {
if ($ionicScrollDelegate.getScrollPosition().top < 5) {
readAndUpdateForDay(Timeline.data.currDay);
$scope.$broadcast('invalidateSize');
}
}

Expand Down
4 changes: 4 additions & 0 deletions www/js/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ angular.module('emission.main.heatmap',['ui-leaflet', 'emission.services'])
data.leafletObject.invalidateSize();
});

$scope.refreshTiles = function() {
$scope.$broadcast('invalidateSize');
};

$scope.getPopRoute = function() {
$ionicLoading.show({
template: 'Loading...'
Expand Down
3 changes: 2 additions & 1 deletion www/js/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ angular.module('emission.intro', ['emission.splash.startprefs',
})

.controller('IntroCtrl', function($scope, $state, $ionicSlideBoxDelegate,
$ionicPopup, ionicToast, $timeout, CommHelper, StartPrefs) {
$ionicPopup, $ionicHistory, ionicToast, $timeout, CommHelper, StartPrefs) {
$scope.getIntroBox = function() {
return $ionicSlideBoxDelegate.$getByHandle('intro-box');
};
Expand Down Expand Up @@ -50,6 +50,7 @@ angular.module('emission.intro', ['emission.splash.startprefs',

$scope.agree = function() {
StartPrefs.markConsented().then(function(response) {
$ionicHistory.clearHistory();
if ($state.is('root.intro')) {
$scope.next();
} else {
Expand Down
89 changes: 46 additions & 43 deletions www/js/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
return [footprint.train * mtokm(distance), footprint.car * mtokm(distance)];
} else {
return footprint[mode] * mtokm(distance);
}
}
}
fh.getFootprint = function(distance, mode) {
if (mode === "IN_VEHICLE") {
Expand All @@ -29,7 +29,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
return readable(footprint[mode] * mtokm(distance));
}
}
return fh;
return fh;
})
.factory('CalorieHelper', function(){
Number.prototype.between = function (min, max) {
Expand Down Expand Up @@ -155,7 +155,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
})
.controller('MetricsCtrl', function($scope, $ionicActionSheet, $ionicLoading,
CommHelper, $window, CalorieHelper, $ionicPopup,storage, FootprintHelper) {

$scope.uictrl = {
showRange: false,
showFilter: false,
Expand Down Expand Up @@ -278,7 +278,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
x: function(d){ return d[0]; },
y: function(d){ return d[1]; },
/*
average: function(d) {
average: function(d) {
var vals = d.values.map(function(item){
return item[1];
});
Expand Down Expand Up @@ -306,7 +306,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
},
}
};

var moment2Localdate = function(momentObj) {
return {
year: momentObj.year(),
Expand All @@ -331,7 +331,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
}
}
$scope.getMetrics = function(mode, metric) {

if (['local_date', 'timestamp'].indexOf(mode) == -1) {
console.log('Illegal time_type');
return;
Expand All @@ -341,7 +341,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
$scope.uictrl.showFilter = false;
$scope.uictrl.showVis = true;
$scope.uictrl.showResult = true;

var data = {};

$scope.caloriesData = {};
Expand Down Expand Up @@ -385,32 +385,35 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
template: 'Loading...'
});
var getDuration = new Promise(function(resolve, reject) {
data.metric = "duration";
var clonedData = angular.copy(data);
clonedData.metric = "duration";
CommHelper.getMetrics(mode, data, function(response) {
resolve(response);
}, function(error) { console.log(error); reject(error); });
}, function(error) { console.log(error); reject(error); });
})
var getSpeed = new Promise(function(resolve, reject) {
data.metric = "median_speed";
var clonedData = angular.copy(data);
clonedData.metric = "median_speed";
CommHelper.getMetrics(mode, data, function(response) {
resolve(response);
}, function(error) { console.log(error); reject(error); });
}, function(error) { console.log(error); reject(error); });
})
var getResponse = new Promise(function(resolve, reject) {
CommHelper.getMetrics(mode, data, function(response) {

resolve(response);
}, function(error) { console.log(error); reject(error); });
}, function(error) { console.log(error); reject(error); });
});

var getDistance = new Promise(function(resolve, reject) {
data.metric = "distance";
var clonedData = angular.copy(data);
clonedData.metric = "distance";
CommHelper.getMetrics(mode, data, function(response) {
resolve(response);
}, function(error) { console.log(error); reject(error); });
}, function(error) { console.log(error); reject(error); });
})
Promise.all([getDuration, getSpeed, getResponse, getDistance]).then(function(results) {
// cacheResults(response);
// cacheResults(response);
$ionicLoading.hide();
if (results[2].user_metrics) {
$scope.summaryData.userSummary = getSummaryData(results[2].user_metrics, $scope.selectCtrl.metric);
Expand All @@ -419,7 +422,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
$scope.summaryData.aggrSummary = getSummaryData(results[2].aggregate_metrics, $scope.selectCtrl.metric);
}
$scope.chartDataUser = results[2].user_metrics? results[2].user_metrics : [];
$scope.chartDataAggr = results[2].aggregate_metrics? results[2].aggregate_metrics : [];
$scope.chartDataAggr = results[2].aggregate_metrics? results[2].aggregate_metrics : [];

if (results[0].user_metrics) {
var durationData = getSummaryDataRaw(results[0].user_metrics, "duration");
Expand All @@ -429,7 +432,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
}
for (var i in durationData) {
if ($scope.userDataSaved()) {
var met = CalorieHelper.getMet(durationData[i].key, speedData[i].values);
var met = CalorieHelper.getMet(durationData[i].key, speedData[i].values);
var gender = storage.get('gender');
var heightUnit = storage.get('heightUnit');
var height = storage.get('height');
Expand All @@ -444,7 +447,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
key: durationData[i].key,
values: Math.round(CalorieHelper.getuserCalories(durationData[i].values / 3600, met)) + ' cal'
})
}
}

if (results[0].aggregate_metrics) {
var avgDurationData = getAvgSummaryDataRaw(results[0].aggregate_metrics, "duration");
Expand All @@ -460,12 +463,12 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
key: avgDurationData[i].key,
values: Math.round(CalorieHelper.getuserCalories(avgDurationData[i].values / 3600, met)) + ' cal'
})
}
}


var defaultCarFootprint = 278.0/1609; // kg CO2 per meter
var defaultTrainFootprint = 92.0/1609; // kg CO2 per meter

if (results[3].user_metrics) {
var userCarbonData = getSummaryDataRaw(results[3].user_metrics, 'distance');
$scope.carbonData.userCarbon = [];
Expand All @@ -483,7 +486,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
$scope.carbonData.aggrCarbon.push({key: aggrCarbonData[i].key, values: FootprintHelper.getFootprint(aggrCarbonData[i].values, aggrCarbonData[i].key)});
if (aggrCarbonData[i].key === "IN_VEHICLE") {
$scope.carbonData.aggrVehicleRange = FootprintHelper.getFootprintRaw(aggrCarbonData[i].values, aggrCarbonData[i].key);
}
}
}
}

Expand All @@ -504,7 +507,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
$scope.$apply(function() {
$scope.showCharts([]);
console.log("did not find aggregate result in response data "+JSON.stringify(results[2]));

$scope.summaryData.defaultSummary = $scope.uictrl.showMe? $scope.summaryData.userSummary : $scope.summaryData.aggrSummary;
$scope.caloriesData.defaultCalories = $scope.uictrl.showMe? $scope.caloriesData.userCalories : $scope.caloriesData.aggrCalories;
$scope.carbonData.defaultCarbon = $scope.uictrl.showMe? $scope.carbonData.userCarbon : $scope.carbonData.aggrCarbon;
Expand Down Expand Up @@ -558,7 +561,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
for (var field in metric) {
// TODO: Consider creating a prefix such as M_ to signal
// modes. Is that really less fragile than caps, though?
// Here, we check if the string is all upper case by
// Here, we check if the string is all upper case by
// converting it to upper case and seeing if it is changed
if (field == field.toUpperCase()) {
if (field === "WALKING" || field === "RUNNING") {
Expand All @@ -567,15 +570,15 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
if (field in mode_bins == false) {
mode_bins[field] = []
}
mode_bins[field].push([metric.ts, Math.round(metric[field] / metric.nUsers), metric.fmt_time]);
mode_bins[field].push([metric.ts, Math.round(metric[field] / metric.nUsers), metric.fmt_time]);
}
}
});
});
var rtn = [];
for (var mode in mode_bins) {
var val_arrays = rtn.push({key: mode, values: mode_bins[mode]});
}
return rtn;
return rtn;
}

var getDataFromMetrics = function(metrics) {
Expand All @@ -584,7 +587,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
for (var field in metric) {
// TODO: Consider creating a prefix such as M_ to signal
// modes. Is that really less fragile than caps, though?
// Here, we check if the string is all upper case by
// Here, we check if the string is all upper case by
// converting it to upper case and seeing if it is changed
if (field == field.toUpperCase()) {
if (field === "WALKING" || field === "RUNNING") {
Expand All @@ -596,7 +599,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
mode_bins[field].push([metric.ts, metric[field], metric.fmt_time]);
}
}
});
});
var rtn = [];
for (var mode in mode_bins) {
var val_arrays = rtn.push({key: mode, values: mode_bins[mode]});
Expand All @@ -615,9 +618,9 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
} else {
data[i].values = Math.round(temp);
}

}
return data;
return data;
}
var getAvgSummaryDataRaw = function(metrics, metric) {
var data = getAvgDataFromMetrics(metrics);
Expand All @@ -631,9 +634,9 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
} else {
data[i].values = Math.round(temp);
}

}
return data;
return data;
}
var getSummaryData = function(metrics, metric) {
var data = getDataFromMetrics(metrics);
Expand Down Expand Up @@ -662,7 +665,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
} else {
data[i].values = Math.round(temp) + ' ' + unit;
}

}
return data;
}
Expand All @@ -673,14 +676,14 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
},
'from');
}

$scope.changeToWeekday = function() {
return $scope.changeWeekday(function(newVal) {
$scope.selectCtrl.toDateWeekdayString = newVal;
},
'to');
}

// $scope.show fil

$scope.changeWeekday = function(stringSetFunction, target) {
Expand Down Expand Up @@ -756,9 +759,9 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
var date2 = $scope.selectCtrl.toDateTimestamp;
var duration = moment.duration(date2.diff(date1));
var days = duration.asDays();



var lower = $scope.carbonData.defaultVehicleRange[0];
var upper = $scope.carbonData.defaultVehicleRange[1];
var ca2020 = 43.771628 / 5 * days; // kg/day
Expand Down Expand Up @@ -825,7 +828,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date
// ts saved as moment
$scope.selectCtrl.fromDateTimestamp= monthago;
$scope.selectCtrl.toDateTimestamp = now;

$scope.selectCtrl.fromDateWeekdayString = "All"
$scope.selectCtrl.toDateWeekdayString = "All"

Expand Down Expand Up @@ -866,7 +869,7 @@ angular.module('emission.main.metrics',['nvd3', 'emission.services', 'ionic-date

};


$scope.data = {};

$scope.userData = {
Expand Down
2 changes: 1 addition & 1 deletion www/templates/common/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="full-toggle-left hvcenter"
ng-click="refreshMap()">Refresh</div>
<div class="full-toggle-right hvcenter"
ng-click="refreshTiles()">Reload Tiles</div>
ng-click="refreshTiles()">Fix Map</div>
</div>
<div style="height: 10px;"></div>
<leaflet geojson="mapCtrl.geojson"
Expand Down
Loading

0 comments on commit 2c98c4f

Please sign in to comment.