2022-11-28 23:35:14 +08:00
/ * *
* 取得電表總計資料 by baja
* @ param { any } devicePath
* @ param { any } timeType
* @ param { any } callback
* /
function getElectricMeterTotalByBaja ( devicePath , timeType , callback ) {
var _result = "" ;
var _ss = "" ;
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) {
console . log ( 'transform:slot:/' + devicePath + '/History/' + timeType ) ;
baja . Ord . make ( 'transform:slot:/' + devicePath + '/History/' + timeType ) . get ( )
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
if ( _index == 0 )
_ss += '{"timestamp":"' + record . get ( 'timestamp' ) + '", "MP1":' + record . get ( 'MP1' ) + '"}' ;
else
_ss += ',{"timestamp":"' + record . get ( 'timestamp' ) + '", "MP1":' + record . get ( 'MP1' ) + '"}' ;
_index ++ ;
} ,
after : function ( ) {
_result += '{' + '"count": ' + _index + ', "data":[' ;
_result += _ss ;
_result += ']}' ;
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
2022-12-01 01:41:00 +08:00
}
/ * *
* 取得電表即時資料 by baja
* @ param { any } devicePath
* @ param { any } callback
* /
function getElectricMeterNoweDataByBaja ( devicePath , callback ) {
2022-12-03 16:45:20 +08:00
var _result = { count : 0 , data : [ ] } ;
2022-12-01 01:41:00 +08:00
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) { //TPE/B1/EE/E4/R2F/NA/WHT/N1
console . log ( 'local:|foxs:|station:|slot:/' + devicePath + '|bql:select name, out, out.value from control:ControlPoint' ) ;
baja . Ord . make ( 'local:|foxs:|station:|slot:/' + devicePath + '|bql:select name, out, out.value from control:ControlPoint' ) . get ( )
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
2022-12-03 16:45:20 +08:00
let main = { }
main . name = record . get ( 'name' ) ;
main . value = record . get ( 'out' ) . get ( 'value' ) ;
_result . data . push ( main ) ;
2022-12-01 01:41:00 +08:00
_index ++ ;
} ,
after : function ( ) {
2022-12-03 16:45:20 +08:00
_result . count = _index ;
2022-12-01 01:41:00 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
2022-12-02 01:22:20 +08:00
///**
// * 取得電表每小時資料 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
// });
// });
// });
//}
/ * *
* 取得電表 單日kwh by baja
* @ param { any } devicePath
* @ param { any } date _millisecond
* @ param { any } callback
* /
function getElectricMeterOneDayKwhByBaja ( devicePath , date _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_Month|bql: select * where timestamp.millis = ' + date _millisecond ) ;
baja . Ord . make ( 'transform:slot:/' + devicePath + '/History/TR_Month|bql: select * where timestamp.millis = ' + date _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
} ) ;
} ) ;
} ) ;
}
2022-12-01 01:41:00 +08:00
/ * *
2022-12-02 01:22:20 +08:00
* 取得電表每周資料 by baja
2022-12-01 01:41:00 +08:00
* @ param { any } devicePath
* @ param { any } startDate _millisecond
* @ param { any } endDate _millisecond
* @ param { any } callback
* /
2022-12-02 01:22:20 +08:00
function getElectricMeterWeekDataByBaja ( devicePath , startDate _millisecond , endDate _millisecond , callback ) {
2022-12-05 18:45:24 +08:00
var _result = { count : 0 , data : [ ] } ;
2022-12-01 01:41:00 +08:00
var _index = 0 ;
require ( [ 'baja!' ] , function ( baja ) { //TPE/B1/EE/E4/R2F/NA/WHT/N1
2022-12-02 01:22:20 +08:00
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_Month|bql: select * where timestamp.millis >= ' + startDate _millisecond + ' and timestamp.millis <= ' + endDate _millisecond ) . get ( )
2022-12-01 01:41:00 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
2022-12-05 18:45:24 +08:00
let main = { } ;
main . timestamp = record . get ( 'timestamp' ) ;
main . value = record . get ( 'kwh1' ) ;
_result . data . push ( main ) ;
2022-12-01 01:41:00 +08:00
_index ++ ;
} ,
after : function ( ) {
2022-12-05 18:45:24 +08:00
_result . count = _index ;
2022-12-01 01:41:00 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
/ * *
2022-12-02 01:22:20 +08:00
* 取得電表 期間內的平均用電量 ( kwh ) 資料 by baja
2022-12-01 01:41:00 +08:00
* @ param { any } devicePath
2022-12-02 01:22:20 +08:00
* @ param { any } company
* @ param { any } startDate _millisecond
* @ param { any } endDate _millisecond
2022-12-01 01:41:00 +08:00
* @ param { any } callback
* /
2022-12-02 01:22:20 +08:00
function getElectricMeterKwhAvgDataByBaja ( devicePath , company , startDate _millisecond , endDate _millisecond , callback ) {
2022-12-01 01:41:00 +08:00
var _result = "" ;
var _ss = "" ;
var _index = 0 ;
2022-12-02 01:22:20 +08:00
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 ( )
2022-12-01 01:41:00 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
if ( _index == 0 )
2022-12-02 01:22:20 +08:00
_ss += '{"value":' + record . get ( 'AVG$28value$29' ) + '"}' ;
2022-12-01 01:41:00 +08:00
else
2022-12-02 01:22:20 +08:00
_ss += ',{"value":' + record . get ( 'AVG$28value$29' ) + '"}' ;
2022-12-01 01:41:00 +08:00
_index ++ ;
} ,
after : function ( ) {
_result += '{' + '"count": ' + _index + ', "data":[' ;
_result += _ss ;
_result += ']}' ;
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
}
/ * *
2022-12-02 01:22:20 +08:00
* 取得點位 每小時資料 by baja
2022-12-01 01:41:00 +08:00
* @ param { any } devicePath
2022-12-02 01:22:20 +08:00
* @ param { any } company
* @ param { any } startDateTime
* @ param { any } endDateTime
2022-12-01 01:41:00 +08:00
* @ param { any } callback
* /
2022-12-02 01:22:20 +08:00
function getElectricMeterHourDataByBaja ( devicePath , company , startDateTime , endDateTime , callback ) {
2022-12-05 18:45:24 +08:00
var _result = { count : 0 , data : [ ] } ;
2022-12-01 01:41:00 +08:00
var _index = 0 ;
2022-12-02 01:22:20 +08:00
require ( [ 'baja!' ] , function ( baja ) { //TPE_B1_EE_E4_R2F_NA_WHT_N1_KWH
2022-12-08 13:38:53 +08:00
console . log ( "local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;delta=true|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;delta=true|bql:history:HistoryRollup.rollup(baja:RelTime '3600000')" ) . get ( )
2022-12-01 01:41:00 +08:00
. then ( function ( table ) {
return table . cursor ( {
each : function ( record ) {
2022-12-05 18:45:24 +08:00
let main = { } ;
2023-01-18 17:49:25 +08:00
2022-12-05 18:45:24 +08:00
main . timestamp = record . get ( 'timestamp' ) ;
main . endTimestamp = record . get ( 'endTimestamp' ) ;
main . min = record . get ( 'min' ) ;
main . max = record . get ( 'max' ) ;
main . avg = record . get ( 'avg' ) ;
main . sum = record . get ( 'sum' ) ;
_result . data . push ( main ) ;
2022-12-02 01:22:20 +08:00
_index ++ ;
} ,
after : function ( ) {
2022-12-05 18:45:24 +08:00
_result . count = _index ;
2022-12-02 01:22:20 +08:00
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 ) {
2022-12-05 18:45:24 +08:00
var _result = { count : 0 , data : [ ] } ;
2022-12-02 01:22:20 +08:00
var _index = 0 ;
2022-12-06 14:34:04 +08:00
2022-12-02 01:22:20 +08:00
require ( [ 'baja!' ] , function ( baja ) { //TPE_B1_EE_E4_R2F_NA_WHT_N1_KWH
2022-12-08 13:38:53 +08:00
console . log ( "local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;delta=true|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;delta=true|bql:history:HistoryRollup.rollup(baja:RelTime '86400000')" ) . get ( )
2022-12-02 01:22:20 +08:00
. then ( function ( table ) {
2022-12-06 14:34:04 +08:00
table . cursor ( {
2022-12-02 01:22:20 +08:00
each : function ( record ) {
2022-12-05 18:45:24 +08:00
let main = { } ;
main . timestamp = record . get ( 'timestamp' ) ;
main . endTimestamp = record . get ( 'endTimestamp' ) ;
main . min = record . get ( 'min' ) ;
main . max = record . get ( 'max' ) ;
main . avg = record . get ( 'avg' ) ;
main . sum = record . get ( 'sum' ) ;
_result . data . push ( main ) ;
2022-12-01 01:41:00 +08:00
_index ++ ;
} ,
after : function ( ) {
2022-12-05 18:45:24 +08:00
_result . count = _index ;
2022-12-01 01:41:00 +08:00
if ( typeof callback === 'function' ) {
callback ( _result ) ;
}
} ,
limit : - 1 ,
offset : 0
} ) ;
} ) ;
} ) ;
2022-11-28 23:35:14 +08:00
}