From ec3d9779429190736a96d4256fd05dd4f8a9d6e9 Mon Sep 17 00:00:00 2001 From: wanli Date: Fri, 2 Dec 2022 01:22:20 +0800 Subject: [PATCH] =?UTF-8?q?[Frontend]=20[=E9=A6=96=E9=A0=81]baja=20functio?= =?UTF-8?q?n=20=E5=8F=96=E5=BE=97=E6=9F=90=E6=97=A5=E7=94=A8=E9=9B=BB?= =?UTF-8?q?=E9=87=8F=E3=80=81=E5=8F=96=E6=AF=8F=E5=80=8B=E5=B0=8F=E6=99=82?= =?UTF-8?q?=E7=94=A8=E9=9B=BB=E9=87=8F=E3=80=81=E5=8F=96=E5=BE=97=E6=AF=8F?= =?UTF-8?q?=E6=97=A5=E7=94=A8=E9=9B=BB=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/js/n4js/electricmeterbaja.js | 194 +++++++++++++++++++++----- 1 file changed, 157 insertions(+), 37 deletions(-) diff --git a/Frontend/js/n4js/electricmeterbaja.js b/Frontend/js/n4js/electricmeterbaja.js index 92529a6..a3b12b7 100644 --- a/Frontend/js/n4js/electricmeterbaja.js +++ b/Frontend/js/n4js/electricmeterbaja.js @@ -73,44 +73,44 @@ function getElectricMeterNoweDataByBaja(devicePath, callback) { }); } -/** - * 取得電表每小時資料 by baja - * @param {any} devicePath - * @param {any} startDate_millisecond - * @param {any} endDate_millisecond - * @param {any} callback - */ -function getElectricMeterHourDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, callback) { - var _result = ""; - var _ss = ""; - var _index = 0; +///** +// * 取得電表每小時資料 by baja +// * @param {any} devicePath +// * @param {any} startDate_millisecond +// * @param {any} endDate_millisecond +// * @param {any} callback +// */ +//function getElectricMeterHourDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, callback) { +// var _result = ""; +// var _ss = ""; +// var _index = 0; - require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 - console.log('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond); - baja.Ord.make('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond).get() - .then(function (table) { - return table.cursor({ - each: function (record) { - if (_index == 0) - _ss += '{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; - else - _ss += ',{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; - _index++; - }, - after: function () { - _result += '{' + '"count": ' + _index + ', "data":['; - _result += _ss; - _result += ']}'; - if (typeof callback === 'function') { - callback(_result); - } - }, - limit: -1, - offset: 0 - }); - }); - }); -} +// require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 +// console.log('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond); +// baja.Ord.make('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond).get() +// .then(function (table) { +// return table.cursor({ +// each: function (record) { +// if (_index == 0) +// _ss += '{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; +// else +// _ss += ',{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; +// _index++; +// }, +// after: function () { +// _result += '{' + '"count": ' + _index + ', "data":['; +// _result += _ss; +// _result += ']}'; +// if (typeof callback === 'function') { +// callback(_result); +// } +// }, +// limit: -1, +// offset: 0 +// }); +// }); +// }); +//} /** * 取得電表 單日kwh by baja @@ -187,4 +187,124 @@ function getElectricMeterWeekDataByBaja(devicePath, startDate_millisecond, endDa }); }); }); +} + +/** + * 取得電表 期間內的平均用電量(kwh)資料 by baja + * @param {any} devicePath + * @param {any} company + * @param {any} startDate_millisecond + * @param {any} endDate_millisecond + * @param {any} callback + */ +function getElectricMeterKwhAvgDataByBaja(devicePath, company, startDate_millisecond, endDate_millisecond, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE_B1_EE_E4_R2F_NA_WHT_N1_KWH + console.log('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond); + baja.Ord.make('local:|foxs:|history:/' + company + '/' + devicePath + '|bql:select AVG(value) from control:ControlPoint where timestamp.millis >= ' + startDate_millisecond + ' and timestamp.millis <= ' + endDate_millisecond).get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"value":' + record.get('AVG$28value$29') + '"}'; + else + _ss += ',{"value":' + record.get('AVG$28value$29') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 取得點位 每小時資料 by baja + * @param {any} devicePath + * @param {any} company + * @param {any} startDateTime + * @param {any} endDateTime + * @param {any} callback + */ +function getElectricMeterHourDataByBaja(devicePath, company, startDateTime, endDateTime, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE_B1_EE_E4_R2F_NA_WHT_N1_KWH + console.log("local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;|bql:history:HistoryRollup.rollup(baja:RelTime '3600000')"); + baja.Ord.make("local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;|bql:history:HistoryRollup.rollup(baja:RelTime '3600000')").get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"timestamp":' + record.get('timestamp') + ', "endTimestamp":"' + record.get('endTimestamp') + ', "min":"' + record.get('min') + ', "max":"' + record.get('max') + ', "avg":"' + record.get('avg') + ', "sum":"' + record.get('sum') + '"}'; + else + _ss += ',{"timestamp":' + record.get('timestamp') + ', "endTimestamp":"' + record.get('endTimestamp') + ', "min":"' + record.get('min') + ', "max":"' + record.get('max') + ', "avg":"' + record.get('avg') + ', "sum":"' + record.get('sum') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 取得點位 每日資料 by baja + * @param {any} devicePath + * @param {any} company + * @param {any} startDateTime + * @param {any} endDateTime + * @param {any} callback + */ +function getElectricMeterDayDataByBaja(devicePath, company, startDateTime, endDateTime, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE_B1_EE_E4_R2F_NA_WHT_N1_KWH + console.log("local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;|bql:history:HistoryRollup.rollup(baja:RelTime '86400000')"); + baja.Ord.make("local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;|bql:history:HistoryRollup.rollup(baja:RelTime '86400000')").get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"timestamp":' + record.get('timestamp') + ', "endTimestamp":"' + record.get('endTimestamp') + ', "min":"' + record.get('min') + ', "max":"' + record.get('max') + ', "avg":"' + record.get('avg') + ', "sum":"' + record.get('sum') + '"}'; + else + _ss += ',{"timestamp":' + record.get('timestamp') + ', "endTimestamp":"' + record.get('endTimestamp') + ', "min":"' + record.get('min') + ', "max":"' + record.get('max') + ', "avg":"' + record.get('avg') + ', "sum":"' + record.get('sum') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); } \ No newline at end of file