|
@@ -1,84 +1,37 @@
|
|
|
app.controller('temperature', function($scope, temperatureService, $interval) {
|
|
|
- var graphAdjustment = 10;
|
|
|
-
|
|
|
- //google.load('visualization', '1.1', {packages: ['line'], callback:function(){
|
|
|
- google.load('visualization', '1', {packages: ['corechart'], callback: function() {
|
|
|
- google.setOnLoadCallback(initChart);
|
|
|
- }});
|
|
|
-
|
|
|
- var chart;
|
|
|
+ $scope.readings = [];
|
|
|
+ $scope.temperatureData = {};
|
|
|
|
|
|
- var chartOptions = {
|
|
|
- chart: {
|
|
|
- title: 'Temperature Logs',
|
|
|
- },
|
|
|
- height: 400,
|
|
|
- curveType: 'function',
|
|
|
- backgroundColor: 'transparent',
|
|
|
- legend:{
|
|
|
- position: 'top',
|
|
|
- alignment: 'start'
|
|
|
- },
|
|
|
- series: {
|
|
|
- 0:{axis:'Inside'},
|
|
|
- 1:{axis:'Outside'}
|
|
|
- },
|
|
|
- vAxis: {
|
|
|
- title: "Temperature"
|
|
|
+ $scope.$watch("readings", function() {
|
|
|
+ for (var i = 0; i < $scope.readings.length; i++) {
|
|
|
+ $scope.readings[i].Timestamp = new Date($scope.readings[i].Timestamp * 1000);
|
|
|
}
|
|
|
- };
|
|
|
-
|
|
|
- function initChart() {
|
|
|
- chart = new google.visualization.LineChart(document.getElementById('linechart'));
|
|
|
- startGettingData();
|
|
|
- }
|
|
|
-
|
|
|
- function getTooltipString(date, reading){
|
|
|
- var dateString=date.toLocaleTimeString(navigator.language, {hour: "2-digit", minute: "2-digit"});
|
|
|
- return 'Time: '+dateString+'\nReading: '+reading;
|
|
|
- }
|
|
|
-
|
|
|
- function drawChart(data) {
|
|
|
- var chartData = new google.visualization.DataTable();
|
|
|
- chartData.addColumn('date', 'Timestamp');
|
|
|
- chartData.addColumn('number', 'Inside');
|
|
|
- chartData.addColumn({type: 'string', role: 'tooltip'});
|
|
|
- chartData.addColumn('number', 'Outside');
|
|
|
- chartData.addColumn({type: 'string', role: 'tooltip'});
|
|
|
- angular.forEach(data, function(datum) {
|
|
|
- var date = new Date(datum.Timestamp * 1000);
|
|
|
- var inside = round(parseFloat(datum.Inside), 1);
|
|
|
- var outside = round(parseFloat(datum.Outside), 1);
|
|
|
- chartData.addRow([date, inside, getTooltipString(date,inside), outside, getTooltipString(date,outside)]);
|
|
|
- });
|
|
|
- chart.draw(chartData, chartOptions);
|
|
|
- }
|
|
|
-
|
|
|
- function startGettingData() {
|
|
|
- getData();
|
|
|
- $interval(getData, 60000);
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
function getData() {
|
|
|
- temperatureService.getReadings().then(drawChart);
|
|
|
+ temperatureService.getReadings().then(function(data) {
|
|
|
+ $scope.readings = data;
|
|
|
+ });
|
|
|
}
|
|
|
+ $interval(getData, 60000);
|
|
|
|
|
|
function updateCurrentTemperature() {
|
|
|
temperatureService.getCurrentTemperatureData().then(function(data) {
|
|
|
$scope.temperatureData = data;
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
$interval(updateCurrentTemperature, 5000);
|
|
|
|
|
|
+ var graphAdjustment = 10;
|
|
|
+
|
|
|
$scope.getGraphPercentage = function() {
|
|
|
- var graphTarget = ($scope.temperatureData.currentTarget * 1.2) - graphAdjustment;
|
|
|
- var graphTemperature = $scope.temperatureData.currentTemperature - graphAdjustment;
|
|
|
+ var graphTarget = ($scope.temperatureData.target * 1.2) - graphAdjustment;
|
|
|
+ var graphTemperature = $scope.temperatureData.temperature - graphAdjustment;
|
|
|
return Math.min((graphTemperature / graphTarget) * 100, 100);
|
|
|
};
|
|
|
|
|
|
function getPercentage() {
|
|
|
- return (($scope.temperatureData.currentTarget - graphAdjustment) / (($scope.temperatureData.currentTemperature * 1.5) - graphAdjustment)) * 100;
|
|
|
+ return (($scope.temperatureData.target - graphAdjustment) / (($scope.temperatureData.temperature * 1.5) - graphAdjustment)) * 100;
|
|
|
}
|
|
|
|
|
|
$scope.getRed = function() {
|
|
@@ -99,7 +52,5 @@ app.controller('temperature', function($scope, temperatureService, $interval) {
|
|
|
percentage /= 25;
|
|
|
return 255 * (1 - Math.max(percentage, 0));
|
|
|
};
|
|
|
-
|
|
|
- $scope.temperatureData = {};
|
|
|
});
|
|
|
|