[Frontend] [首頁]baja function 取得某日用電量、取每個小時用電量、取得每日用電量

This commit is contained in:
wanli 2022-12-02 01:22:20 +08:00
parent 1236eaac9c
commit ec3d977942

View File

@ -73,44 +73,44 @@ function getElectricMeterNoweDataByBaja(devicePath, callback) {
}); });
} }
/** ///**
* 取得電表每小時資料 by baja // * 取得電表每小時資料 by baja
* @param {any} devicePath // * @param {any} devicePath
* @param {any} startDate_millisecond // * @param {any} startDate_millisecond
* @param {any} endDate_millisecond // * @param {any} endDate_millisecond
* @param {any} callback // * @param {any} callback
*/ // */
function getElectricMeterHourDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, callback) { //function getElectricMeterHourDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, callback) {
var _result = ""; // var _result = "";
var _ss = ""; // var _ss = "";
var _index = 0; // var _index = 0;
require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 // 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); // 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() // 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) { // .then(function (table) {
return table.cursor({ // return table.cursor({
each: function (record) { // each: function (record) {
if (_index == 0) // if (_index == 0)
_ss += '{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; // _ss += '{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}';
else // else
_ss += ',{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; // _ss += ',{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}';
_index++; // _index++;
}, // },
after: function () { // after: function () {
_result += '{' + '"count": ' + _index + ', "data":['; // _result += '{' + '"count": ' + _index + ', "data":[';
_result += _ss; // _result += _ss;
_result += ']}'; // _result += ']}';
if (typeof callback === 'function') { // if (typeof callback === 'function') {
callback(_result); // callback(_result);
} // }
}, // },
limit: -1, // limit: -1,
offset: 0 // offset: 0
}); // });
}); // });
}); // });
} //}
/** /**
* 取得電表 單日kwh by baja * 取得電表 單日kwh by baja
@ -188,3 +188,123 @@ 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
});
});
});
}