Merge commit '12fce6c' into HEAD

# Conflicts:
#	index.js
#	src/configs/index.js
#	src/configs/machineGroupControl.json
#	src/helper/assetUtils.js
#	src/helper/childRegistrationUtils.js
#	src/helper/configUtils.js
#	src/helper/logger.js
#	src/helper/menuUtils.js
#	src/helper/menuUtils_DEPRECATED.js
#	src/helper/outputUtils.js
#	src/helper/validationUtils.js
#	src/measurements/Measurement.js
#	src/measurements/MeasurementContainer.js
#	src/measurements/examples.js
#	src/outliers/outlierDetection.js
This commit is contained in:
znetsixe
2026-03-31 18:07:57 +02:00
53 changed files with 3545 additions and 1978 deletions

View File

@@ -1,18 +1,19 @@
const { getFormatter } = require('./formatters');
//this class will handle the output events for the node red node
class OutputUtils {
constructor() {
this.output ={};
this.output['influxdb'] = {};
this.output['process'] = {};
this.output = {};
}
checkForChanges(output, format) {
if (!output || typeof output !== 'object') {
return {};
}
this.output[format] = this.output[format] || {};
const changedFields = {};
for (const key in output) {
if (output.hasOwnProperty(key) && output[key] !== this.output[format][key]) {
if (Object.prototype.hasOwnProperty.call(output, key) && output[key] !== this.output[format][key]) {
let value = output[key];
// For fields: if the value is an object (and not a Date), stringify it.
if (value !== null && typeof value === 'object' && !(value instanceof Date)) {
@@ -30,66 +31,56 @@ class OutputUtils {
}
formatMsg(output, config, format) {
//define emtpy message
let msg = {};
// Compare output with last output and only include changed values
const changedFields = this.checkForChanges(output,format);
if (Object.keys(changedFields).length > 0) {
switch (format) {
case 'influxdb':
// Extract the relevant config properties.
const relevantConfig = this.extractRelevantConfig(config);
// Flatten the tags so that no nested objects are passed on.
const flatTags = this.flattenTags(relevantConfig);
msg = this.influxDBFormat(changedFields, config, flatTags);
break;
case 'process':
// Compare output with last output and only include changed values
msg = this.processFormat(changedFields,config);
//console.log(msg);
break;
default:
return null;
}
const measurement = config.general.name;
const flatTags = this.flattenTags(this.extractRelevantConfig(config));
const formatterName = this.resolveFormatterName(config, format);
const formatter = getFormatter(formatterName);
const payload = formatter.format(measurement, {
fields: changedFields,
tags: flatTags,
config,
channel: format,
});
msg = this.wrapMessage(measurement, payload);
return msg;
}
return null;
}
influxDBFormat(changedFields, config , flatTags) {
// Create the measurement and topic using softwareType and name config.functionality.softwareType + .
const measurement = `${config.functionality?.softwareType}_${config.general?.id}`;
const payload = {
measurement: measurement,
fields: changedFields,
tags: flatTags,
timestamp: new Date(),
resolveFormatterName(config, channel) {
const outputConfig = config.output || {};
if (channel === 'process') {
return outputConfig.process || 'process';
}
if (channel === 'influxdb') {
return outputConfig.dbase || 'influxdb';
}
return outputConfig[channel] || channel;
}
wrapMessage(measurement, payload) {
return {
topic: measurement,
payload,
};
const topic = measurement;
const msg = { topic: topic, payload: payload };
return msg;
}
flattenTags(obj) {
const result = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
const value = obj[key];
if (value !== null && typeof value === 'object' && !(value instanceof Date)) {
// Recursively flatten the nested object.
const flatChild = this.flattenTags(value);
for (const childKey in flatChild) {
if (flatChild.hasOwnProperty(childKey)) {
if (Object.prototype.hasOwnProperty.call(flatChild, childKey)) {
result[`${key}_${childKey}`] = String(flatChild[childKey]);
}
}
@@ -103,7 +94,7 @@ class OutputUtils {
}
extractRelevantConfig(config) {
return {
// general properties
id: config.general?.id,
@@ -120,15 +111,6 @@ class OutputUtils {
unit: config.general?.unit,
};
}
processFormat(changedFields,config) {
// Create the measurement and topic using softwareType and name config.functionality.softwareType + .
const measurement = `${config.functionality?.softwareType}_${config.general?.id}`;
const payload = changedFields;
const topic = measurement;
const msg = { topic: topic, payload: payload };
return msg;
}
}
module.exports = OutputUtils;