Commit 144e3bf8cebfb8cfaeae72b5d2a4291a0e6d89c5
1 parent
b0151caa
added two additional parameters to post-processing function
Showing
3 changed files
with
30 additions
and
6 deletions
@@ -104,6 +104,7 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | @@ -104,6 +104,7 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | ||
104 | var listeners = []; | 104 | var listeners = []; |
105 | var datasourceType = datasourceSubscription.datasourceType; | 105 | var datasourceType = datasourceSubscription.datasourceType; |
106 | var datasourceData = {}; | 106 | var datasourceData = {}; |
107 | + var dataSourceOrigData = {}; | ||
107 | var dataKeys = {}; | 108 | var dataKeys = {}; |
108 | var subscribers = []; | 109 | var subscribers = []; |
109 | var history = datasourceSubscription.subscriptionTimewindow && | 110 | var history = datasourceSubscription.subscriptionTimewindow && |
@@ -140,7 +141,7 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | @@ -140,7 +141,7 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | ||
140 | } | 141 | } |
141 | } else { | 142 | } else { |
142 | if (dataKey.postFuncBody && !dataKey.postFunc) { | 143 | if (dataKey.postFuncBody && !dataKey.postFunc) { |
143 | - dataKey.postFunc = new Function("time", "value", "prevValue", dataKey.postFuncBody); | 144 | + dataKey.postFunc = new Function("time", "value", "prevValue", "timePrev", "prevOrigValue", dataKey.postFuncBody); |
144 | } | 145 | } |
145 | } | 146 | } |
146 | if (datasourceType === types.datasourceType.entity || datasourceSubscription.type === types.widgetType.timeseries.value) { | 147 | if (datasourceType === types.datasourceType.entity || datasourceSubscription.type === types.widgetType.timeseries.value) { |
@@ -165,6 +166,7 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | @@ -165,6 +166,7 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | ||
165 | }; | 166 | }; |
166 | dataKeys[key] = dataKey; | 167 | dataKeys[key] = dataKey; |
167 | } | 168 | } |
169 | + dataSourceOrigData = angular.copy(datasourceData); | ||
168 | dataKey.key = key; | 170 | dataKey.key = key; |
169 | } | 171 | } |
170 | if (datasourceType === types.datasourceType.function) { | 172 | if (datasourceType === types.datasourceType.function) { |
@@ -678,27 +680,36 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | @@ -678,27 +680,36 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | ||
678 | var dataKey = dataKeyList[keyIndex]; | 680 | var dataKey = dataKeyList[keyIndex]; |
679 | var data = []; | 681 | var data = []; |
680 | var prevSeries; | 682 | var prevSeries; |
683 | + var prevOrigSeries; | ||
681 | var datasourceKeyData; | 684 | var datasourceKeyData; |
685 | + var datasourceOrigKeyData; | ||
682 | var update = false; | 686 | var update = false; |
683 | if (realtime) { | 687 | if (realtime) { |
684 | datasourceKeyData = []; | 688 | datasourceKeyData = []; |
689 | + datasourceOrigKeyData = []; | ||
685 | } else { | 690 | } else { |
686 | datasourceKeyData = datasourceData[datasourceKey].data; | 691 | datasourceKeyData = datasourceData[datasourceKey].data; |
692 | + datasourceOrigKeyData = dataSourceOrigData[datasourceKey].data; | ||
687 | } | 693 | } |
688 | if (datasourceKeyData.length > 0) { | 694 | if (datasourceKeyData.length > 0) { |
689 | prevSeries = datasourceKeyData[datasourceKeyData.length - 1]; | 695 | prevSeries = datasourceKeyData[datasourceKeyData.length - 1]; |
696 | + prevOrigSeries = datasourceOrigKeyData[datasourceOrigKeyData.length -1]; | ||
690 | } else { | 697 | } else { |
691 | prevSeries = [0, 0]; | 698 | prevSeries = [0, 0]; |
699 | + prevOrigSeries = [0, 0]; | ||
692 | } | 700 | } |
701 | + dataSourceOrigData[datasourceKey].data = []; | ||
693 | if (datasourceSubscription.type === types.widgetType.timeseries.value) { | 702 | if (datasourceSubscription.type === types.widgetType.timeseries.value) { |
694 | var series, time, value; | 703 | var series, time, value; |
695 | for (var i = 0; i < keyData.length; i++) { | 704 | for (var i = 0; i < keyData.length; i++) { |
696 | series = keyData[i]; | 705 | series = keyData[i]; |
697 | time = series[0]; | 706 | time = series[0]; |
707 | + dataSourceOrigData[datasourceKey].data.push(series); | ||
698 | value = convertValue(series[1]); | 708 | value = convertValue(series[1]); |
699 | if (dataKey.postFunc) { | 709 | if (dataKey.postFunc) { |
700 | - value = dataKey.postFunc(time, value, prevSeries[1]); | 710 | + value = dataKey.postFunc(time, value, prevSeries[1], prevOrigSeries[0], prevOrigSeries[1]); |
701 | } | 711 | } |
712 | + prevOrigSeries = series; | ||
702 | series = [time, value]; | 713 | series = [time, value]; |
703 | data.push(series); | 714 | data.push(series); |
704 | prevSeries = series; | 715 | prevSeries = series; |
@@ -708,9 +719,10 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | @@ -708,9 +719,10 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic | ||
708 | if (keyData.length > 0) { | 719 | if (keyData.length > 0) { |
709 | series = keyData[0]; | 720 | series = keyData[0]; |
710 | time = series[0]; | 721 | time = series[0]; |
722 | + dataSourceOrigData[datasourceKey].data.push(series); | ||
711 | value = convertValue(series[1]); | 723 | value = convertValue(series[1]); |
712 | if (dataKey.postFunc) { | 724 | if (dataKey.postFunc) { |
713 | - value = dataKey.postFunc(time, value, prevSeries[1]); | 725 | + value = dataKey.postFunc(time, value, prevSeries[1], prevOrigSeries[0], prevOrigSeries[1]); |
714 | } | 726 | } |
715 | series = [time, value]; | 727 | series = [time, value]; |
716 | data.push(series); | 728 | data.push(series); |
@@ -75,9 +75,16 @@ | @@ -75,9 +75,16 @@ | ||
75 | </md-checkbox> | 75 | </md-checkbox> |
76 | <tb-js-func ng-if="model.usePostProcessing" | 76 | <tb-js-func ng-if="model.usePostProcessing" |
77 | ng-model="model.postFuncBody" | 77 | ng-model="model.postFuncBody" |
78 | - function-args="{{ ['time', 'value', 'prevValue'] }}" | ||
79 | - validation-args="{{ [[1, 1, 1],[1, '1', '1']] }}" | 78 | + function-args="{{ ['time', 'value', 'prevValue', 'timePrev', 'prevOrigValue'] }}" |
79 | + validation-args="{{ [[1, 1, 1, 1, 1],[1, '1', '1', 1, '1']] }}" | ||
80 | result-type="any"> | 80 | result-type="any"> |
81 | </tb-js-func> | 81 | </tb-js-func> |
82 | + <label ng-if="model.usePostProcessing" class="tb-title" style="margin-left: 15px;"> | ||
83 | + time - {{ 'datakey.time-description' | translate }}</br> | ||
84 | + value - {{ 'datakey.value-description' | translate }}</br> | ||
85 | + prevValue - {{ 'datakey.prev-value-description' | translate }}</br> | ||
86 | + timePrev - {{ 'datakey.time-prev-description' | translate }}</br> | ||
87 | + prevOrigValue - {{ 'datakey.prev-orig-value-description' | translate }} | ||
88 | + </label> | ||
82 | </section> | 89 | </section> |
83 | </md-content> | 90 | </md-content> |
@@ -555,7 +555,12 @@ | @@ -555,7 +555,12 @@ | ||
555 | "alarm-fields-required": "Alarm fields are required.", | 555 | "alarm-fields-required": "Alarm fields are required.", |
556 | "function-types": "Function types", | 556 | "function-types": "Function types", |
557 | "function-types-required": "Function types are required.", | 557 | "function-types-required": "Function types are required.", |
558 | - "maximum-function-types": "Maximum { count, plural, 1 {1 function type is allowed.} other {# function types are allowed} }" | 558 | + "maximum-function-types": "Maximum { count, plural, 1 {1 function type is allowed.} other {# function types are allowed} }", |
559 | + "time-description": "timestamp of the current value;", | ||
560 | + "value-description": "the current value;", | ||
561 | + "prev-value-description": "result of the previous function call;", | ||
562 | + "time-prev-description": "timestamp of the previous value;", | ||
563 | + "prev-orig-value-description": "original previous value;" | ||
559 | }, | 564 | }, |
560 | "datasource": { | 565 | "datasource": { |
561 | "type": "Datasource type", | 566 | "type": "Datasource type", |