angular.module("mystrom.graph.controllers",["ionic"]).controller("GraphController",["$scope","tile","graphData","$ionicHistory","loadingService","graphService","$localstorage",function(t,a,e,r,n,s,o){function c(t){switch(t){case"power":return"W";case"energy":return"kWh";case"cost":return"CHF";default:return"W"}}function i(t){for(var a=[],e=0,r=t.categories.length;r>e;e++)null!==t.data[e]&&a.push({value:t.data[e].y,name:t.data[e].name,date:t.categories[e]});return a}function l(t){var a=Math.round(10*t)/10;return"0"===a.toString().split(".")[1]&&(a=Math.round(a)),a}t.$on("$ionicView.afterEnter",function(){n.hideLoading()}),t.tile=a,t.isIPad=ionic.Platform.isIPad(),t.isAndroid=ionic.Platform.isAndroid(),t.type=o.get("graphType","power"),t.unit=c(t.type),t.chartData=i(e.chart),t.dayCost=e.chart.usages[0].cost.split(" ")[0],t.monthCost=e.chart.usages[1].cost.split(" ")[0],t.allCost=e.chart.usages[2].cost.split(" ")[0],t.dayEnergy=e.chart.usages[0].energy.split(" ")[0],t.monthEnergy=e.chart.usages[1].energy.split(" ")[0],t.allEnergy=e.chart.usages[2].energy.split(" ")[0],t.consumption=l(a.power);var g=_.reduce(t.chartData,function(t,a){return t+a.value},0);t.average=t.chartData.length>0?l(g/t.chartData.length):0,t.menuVisible=!1,t.goBack=function(){r.goBack()},t.setType=function(e){t.type!==e&&(t.type=e,t.unit=c(e),s.getReport({device:a.id,valueType:e}).then(function(a){o.set("graphType",e),s.data=a.data,t.chartData=i(a.data.chart),t.dayCost=a.data.chart.usages[0].cost.split(" ")[0],t.monthCost=a.data.chart.usages[1].cost.split(" ")[0],t.allCost=a.data.chart.usages[2].cost.split(" ")[0],t.dayEnergy=a.data.chart.usages[0].energy.split(" ")[0],t.monthEnergy=a.data.chart.usages[1].energy.split(" ")[0],t.allEnergy=a.data.chart.usages[2].energy.split(" ")[0],g=_.reduce(t.chartData,function(t,a){return t+a.value},0),t.average=t.chartData.length>0?l(g/t.chartData.length):0},function(){n.showError()}))}}]);