Commit f8b3619ce5eaa61c0966656a2233b30834005f82

Authored by Igor Kulikov
Committed by GitHub
2 parents b773ee0c 144e3bf8

Merge pull request #1165 from Terny22/enhancement/post-proc-func

Added two additional parameters to post-processing function
... ... @@ -104,6 +104,7 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic
104 104 var listeners = [];
105 105 var datasourceType = datasourceSubscription.datasourceType;
106 106 var datasourceData = {};
  107 + var dataSourceOrigData = {};
107 108 var dataKeys = {};
108 109 var subscribers = [];
109 110 var history = datasourceSubscription.subscriptionTimewindow &&
... ... @@ -140,7 +141,7 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic
140 141 }
141 142 } else {
142 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 147 if (datasourceType === types.datasourceType.entity || datasourceSubscription.type === types.widgetType.timeseries.value) {
... ... @@ -165,6 +166,7 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic
165 166 };
166 167 dataKeys[key] = dataKey;
167 168 }
  169 + dataSourceOrigData = angular.copy(datasourceData);
168 170 dataKey.key = key;
169 171 }
170 172 if (datasourceType === types.datasourceType.function) {
... ... @@ -678,27 +680,36 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic
678 680 var dataKey = dataKeyList[keyIndex];
679 681 var data = [];
680 682 var prevSeries;
  683 + var prevOrigSeries;
681 684 var datasourceKeyData;
  685 + var datasourceOrigKeyData;
682 686 var update = false;
683 687 if (realtime) {
684 688 datasourceKeyData = [];
  689 + datasourceOrigKeyData = [];
685 690 } else {
686 691 datasourceKeyData = datasourceData[datasourceKey].data;
  692 + datasourceOrigKeyData = dataSourceOrigData[datasourceKey].data;
687 693 }
688 694 if (datasourceKeyData.length > 0) {
689 695 prevSeries = datasourceKeyData[datasourceKeyData.length - 1];
  696 + prevOrigSeries = datasourceOrigKeyData[datasourceOrigKeyData.length -1];
690 697 } else {
691 698 prevSeries = [0, 0];
  699 + prevOrigSeries = [0, 0];
692 700 }
  701 + dataSourceOrigData[datasourceKey].data = [];
693 702 if (datasourceSubscription.type === types.widgetType.timeseries.value) {
694 703 var series, time, value;
695 704 for (var i = 0; i < keyData.length; i++) {
696 705 series = keyData[i];
697 706 time = series[0];
  707 + dataSourceOrigData[datasourceKey].data.push(series);
698 708 value = convertValue(series[1]);
699 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 713 series = [time, value];
703 714 data.push(series);
704 715 prevSeries = series;
... ... @@ -708,9 +719,10 @@ function DatasourceSubscription(datasourceSubscription, telemetryWebsocketServic
708 719 if (keyData.length > 0) {
709 720 series = keyData[0];
710 721 time = series[0];
  722 + dataSourceOrigData[datasourceKey].data.push(series);
711 723 value = convertValue(series[1]);
712 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 727 series = [time, value];
716 728 data.push(series);
... ...
... ... @@ -75,9 +75,16 @@
75 75 </md-checkbox>
76 76 <tb-js-func ng-if="model.usePostProcessing"
77 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 80 result-type="any">
81 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 89 </section>
83 90 </md-content>
\ No newline at end of file
... ...
... ... @@ -555,7 +555,12 @@
555 555 "alarm-fields-required": "Alarm fields are required.",
556 556 "function-types": "Function types",
557 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 565 "datasource": {
561 566 "type": "Datasource type",
... ...