(()=>{function t(n,t,o,l,a,r){var i,u=t.deviceId,c={},t=!u,e=a("Availability percentage is based on the number of critical alarms raised and cleared."),d=a("Operability chart displays how many devices had their average availability on particular level in the last 30 days."),v=o.createEnum([{name:"DAY",value:1,label:a("Last 24 hours availability")},{name:"WEEK",value:7,label:a("Last 7 days availability")},{name:"MONTH",value:30,label:a("Last 30 days availability")}]),m=o.createEnum([{name:"DOWNTIME",value:"downtime",label:a("Downtime"),color:"#d9534f"},{name:"UPTIME",value:"uptime",label:a("Uptime"),color:"#5cb85c"}]);function s(r){t=r,a=moment(),t=moment().subtract(t.value,"days"),e=o.dateFullFormat;var t,a,e,i={dateFrom:t.format(e),dateTo:a.format(e),id:u};return(i.id?l.reports.downtimeDuration(i):l.reports.downtimeDurationAggregation(i)).then(function(t){var a,e,n;a=r,e=i,t=t.data,n=t.downtimeDuration,e=f(i,t)-n,c[a.name]={name:a.name,label:a.label,order:a.ordinal,data:[{key:m.DOWNTIME.value,val:n},{key:m.UPTIME.value,val:e}]}})}function f(t,a){var a=1<arguments.length&&void 0!==a?a:{},e=moment(t.dateFrom),t=moment(t.dateTo),n=1;return"number"==typeof a.deviceCount?n=a.deviceCount:Array.isArray(a.availabilityStats)&&(n=a.availabilityStats.length),t.diff(e,"seconds")*(n||1)}function y(t){var a=_.find(t,{key:m.UPTIME.value}).val;return a/(a+_.find(t,{key:m.DOWNTIME.value}).val)*100}_.assign(n,{intervalsData:c,showOverviewBreadcrumbs:t,availabilityTooltip:e,operabilityTooltip:d,x:function(){return function(t){return t.key}},y:function(){return function(t){return t.val}},xGraph:function(){return function(t){return t[0]}},yGraph:function(){return function(t){return t[1]}},xTickFormat:function(){return function(t){return"".concat(t,"%")}},color:function(){return function(t){return _.find(m,{value:t.data.key}).color}},colorGraph:function(){return function(){return m.UPTIME.color}},tooltip:function(){return function(t){return r.getString(_.find(m,{value:t}).label)}},tooltipGraph:function(){return function(t,a,e){e=Math.round(e);return r.getPlural(e,"1 device","{{$count}} devices",{})}},percentage:y,percentageClass:function(t){return 50<y(t)?"text-success":"text-danger"}}),v.values().forEach(s),u||(a=o.dateFullFormat,i={dateFrom:moment().subtract(30,"day").format(a),dateTo:moment().format(a)},l.reports.downtimeDuration(i).then(function(t){var a,e;a=i,t=(t=t.data).availabilityStats,e=f(a),a=t.map(function(t){var a=t.downtimeDuration;return t.percent=100*(e-a)/e,t}),n.graphData=[{key:"operability",values:(a=>{for(var n=10,r=[],t=function(){var e=i*n,t=a.filter(function(t){return a=e,(t=t).percent<=a&&t.percent>a-n;var a}).length;r.push([e,t])},i=0;i<=10;i++)t();return r})(a)}]}))}t.$inject=["$scope","$routeParams","c8yBase","c8yAlarms","gettext","gettextCatalog"],angular.module("c8y.parts.availability").controller("availabilityReportCtrl",t)})();