"use strict";(function(){var e=0;"use strict";var t=require("util");var i=require("events");function a(e){i.EventEmitter.call(this);if(false===this instanceof a){return new a}this.setupDb(e)}t.inherits(a,i.EventEmitter);a.prototype.setupDb=function(e){var t=this;var i="CREATE TABLE IF NOT EXISTS device_exp_table(deviceName VARCHAR(32),seriaNo VARCHAR(32), startTime DATETIME, endTime DATETIME, eventType VARCHAR(12), duration INTEGER, PRIMARY KEY(deviceName, startTime, eventType));";this.db=e;this.db.serialize(function(){t.db.run(i)})};a.prototype.replaceExpItemIntoDb=function(e,t){var i=this;i.db.run("REPLACE INTO device_uptime_table(startTime, endTime, deviceName, seriaNo, eventType, duaration) "+"VALUES (?, ?, ?, ?, ?, ?);",[e.startTime,e.endTime,e.deviceName,e.seriaNo,e.eventType,e.duratation],function(e){if(e){t(e)}else{t(null)}})};a.prototype.queryUsability=function(e,t){var i=this;var a=Date.parse(e.endTime)-Date.parse(e.startTime);this.db.all("SELECT deviceName, 1-SUM(duration)/? as usabilityRate FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[a,e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryHealing=function(e,t){var i=this;var a=Date.parse(e.endTime)-Date.parse(e.startTime);this.db.all("SELECT deviceName, 1-SUM(duration)/? as healingRate FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[a,e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryConvergence=function(e,t){var i=this;var a=Date.parse(e.endTime)-Date.parse(e.startTime);this.db.all("SELECT deviceName, 1-SUM(duration)/? as converRate FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[a,e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryUsabilityDetail=function(e,t){var i=this;this.db.all("SELECT deviceName,startTime, duaration FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryHealingDetail=function(e,t){var i=this;this.db.all("SELECT deviceName,startTime, duaration FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryConvDetail=function(e,t){var i=this;this.db.all("SELECT deviceName,startTime, duaration FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryTotalRecovery=function(e,t){var i=this;this.db.all("SELECT deviceName, SUM(duration) as totalTime FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryTotalRecoveryTime=function(e,t){var i=this;this.db.all("SELECT deviceName, SUM(duration) as totalTime FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryTotalHealingTime=function(e,t){var i=this;this.db.all("SELECT deviceName, SUM(duration) as totalTime FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryTotalConvTime=function(e,t){var i=this;this.db.all("SELECT deviceName, SUM(duration) as totalTime FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.queryTotalErrorTimes=function(e,t){var i=this;this.db.all("SELECT deviceName, COUNT(eventType) as totalTimes FROM device_exp_table WHERE deviceName = ? AND startTime BETWEEN ? AND ? ;",[e.deviceName,e.startTime,e.endTime],function(e,i){t(e,i)})};a.prototype.querySwitchoverTimes=function(e,t){var i=this;this.db.all("SELECT deviceName, COUNT(eventType) as totalTimes FROM device_exp_table WHERE deviceName = ? AND eventType='switchover';",[e.deviceName],function(e,i){t(e,i)})};a.prototype.querySwitchoverDetails=function(e,t){var i=this;this.db.all("SELECT deviceName, startTime as time,duration FROM device_exp_table WHERE deviceName = ? AND eventType='switchover';",[e.deviceName],function(e,i){t(e,i)})};a.prototype.queryErrorAvoidTime=function(e,t){var i=this;this.db.all("SELECT deviceName, sum(duration) as totalTime FROM device_exp_table WHERE deviceName = ? ;",[e.deviceName],function(e,i){t(e,i)})};a.prototype.queryErrorAvoids=function(e,t){var i=this;this.db.all("SELECT deviceName, startTime as time , duration FROM device_exp_table WHERE deviceName = ? ;",[e.deviceName],function(e,i){t(e,i)})};module.exports=a})();