forked from RnD/measurement
license update and enhancements to measurement functionality + child parent relationship
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
*/
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const {logger,configUtils,configManager} = require('generalFunctions');
|
||||
const {logger,configUtils,configManager,MeasurementContainer} = require('generalFunctions');
|
||||
|
||||
class Measurement {
|
||||
constructor(config={}) {
|
||||
@@ -53,6 +53,12 @@ class Measurement {
|
||||
// Init after config is set
|
||||
this.logger = new logger(this.config.general.logging.enabled,this.config.general.logging.logLevel, this.config.general.name);
|
||||
|
||||
// General properties
|
||||
this.measurements = new MeasurementContainer({
|
||||
autoConvert: true,
|
||||
windowSize: this.config.smoothing.smoothWindow
|
||||
});
|
||||
|
||||
// Smoothing
|
||||
this.storedValues = [];
|
||||
|
||||
@@ -500,8 +506,11 @@ class Measurement {
|
||||
this.outputAbs = Math.round(val * 100) / 100;
|
||||
this.outputPercent = this.updateOutputPercent(val);
|
||||
|
||||
this.logger.debug(`[DEBUG] Emitting mAbs=${this.outputAbs}, Current listeners:`, this.emitter.eventNames());
|
||||
this.emitter.emit('mAbs', this.outputAbs);
|
||||
this.emitter.emit('mAbs', this.outputAbs);// DEPRECATED: Use measurements container instead
|
||||
|
||||
// In the new method just update the measurement container and let the parent subscribe to it
|
||||
this.logger.debug(`Updating type: ${this.config.asset.type}, variant: ${"measured"}, postition : ${this.config.functionality.positionVsParent} container with new value: ${this.outputAbs}`);
|
||||
this.measurements.type(this.config.asset.type).variant("measured").position(this.config.functionality.positionVsParent).value(this.outputAbs, Date.now(),this.config.asset.unit ); // New method
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,12 +569,24 @@ const configuration = {
|
||||
absMax: 4000,
|
||||
offset: 1000
|
||||
},
|
||||
asset: {
|
||||
type: "pressure",
|
||||
unit: "bar",
|
||||
category: "measurement",
|
||||
model: "PT1",
|
||||
uuid: "123e4567-e89b-12d3-a456-426614174000",
|
||||
tagCode: "PT1-001",
|
||||
supplier: "DeltaTech"
|
||||
},
|
||||
smoothing: {
|
||||
smoothWindow: 10,
|
||||
smoothMethod: 'mean',
|
||||
},
|
||||
simulation: {
|
||||
enabled: true,
|
||||
},
|
||||
functionality: {
|
||||
positionVsParent: "upstream"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -576,8 +597,9 @@ m.logger.info(`Measurement created with config : ${JSON.stringify(m.config)}`);
|
||||
|
||||
m.logger.setLogLevel("debug");
|
||||
|
||||
m.emitter.on('mAbs', (val) => {
|
||||
m.logger.info(`Received : ${val}`);
|
||||
//look for flow updates
|
||||
m.measurements.emitter.on('pressure.measured.upstream', (newVal) => {
|
||||
m.logger.info(`Received : ${newVal.value} ${newVal.unit}`);
|
||||
const repeatability = m.evaluateRepeatability();
|
||||
if (repeatability !== null) {
|
||||
m.logger.info(`Current repeatability (standard deviation): ${repeatability}`);
|
||||
|
||||
Reference in New Issue
Block a user