Compare commits
2 Commits
dev-Pieter
...
5117df14db
| Author | SHA1 | Date | |
|---|---|---|---|
| 5117df14db | |||
| c70bed2b39 |
@@ -66,15 +66,6 @@
|
|||||||
"units": ["g/m³", "mol/m³"]
|
"units": ["g/m³", "mol/m³"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Quantity (TSS)",
|
|
||||||
"models": [
|
|
||||||
{
|
|
||||||
"name": "VegaSolidsProbe",
|
|
||||||
"units": ["g/m³"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -412,14 +412,6 @@
|
|||||||
],
|
],
|
||||||
"description": "The frequency at which calculations are performed."
|
"description": "The frequency at which calculations are performed."
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"flowNumber": {
|
|
||||||
"default": 1,
|
|
||||||
"rules": {
|
|
||||||
"type": "number",
|
|
||||||
"nullable": false,
|
|
||||||
"description": "Defines which effluent flow of the parent node to handle."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,12 +11,8 @@ class ChildRegistrationUtils {
|
|||||||
|
|
||||||
this.logger.debug(`Registering child: ${name} (${id}) as ${softwareType} at ${positionVsParent}`);
|
this.logger.debug(`Registering child: ${name} (${id}) as ${softwareType} at ${positionVsParent}`);
|
||||||
|
|
||||||
// Enhanced child setup - multiple parents
|
// Enhanced child setup
|
||||||
if (Array.isArray(child.parent)) {
|
child.parent = this.mainClass;
|
||||||
child.parent.push(this.mainClass);
|
|
||||||
} else {
|
|
||||||
child.parent = [this.mainClass];
|
|
||||||
}
|
|
||||||
child.positionVsParent = positionVsParent;
|
child.positionVsParent = positionVsParent;
|
||||||
|
|
||||||
// Enhanced measurement container with rich context
|
// Enhanced measurement container with rich context
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class MeasurementBuilder {
|
|||||||
if (!this.variant) {
|
if (!this.variant) {
|
||||||
throw new Error('Measurement variant is required');
|
throw new Error('Measurement variant is required');
|
||||||
}
|
}
|
||||||
if (!this.position) {
|
if (Number.isNaN(this.position)) {
|
||||||
throw new Error('Measurement position is required');
|
throw new Error('Measurement position is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,59 +105,60 @@ class MeasurementContainer {
|
|||||||
|
|
||||||
// ENHANCED: Update your existing value method
|
// ENHANCED: Update your existing value method
|
||||||
value(val, timestamp = Date.now(), sourceUnit = null) {
|
value(val, timestamp = Date.now(), sourceUnit = null) {
|
||||||
if (!this._ensureChainIsValid()) return this;
|
if (!this._ensureChainIsValid()) return this;
|
||||||
|
|
||||||
const measurement = this._getOrCreateMeasurement();
|
const measurement = this._getOrCreateMeasurement();
|
||||||
const targetUnit = this._getTargetUnit(this._currentType);
|
const targetUnit = this._getTargetUnit(this._currentType);
|
||||||
|
|
||||||
let convertedValue = val;
|
let convertedValue = val;
|
||||||
let finalUnit = sourceUnit || targetUnit;
|
let finalUnit = sourceUnit || targetUnit;
|
||||||
|
|
||||||
// Auto-convert if enabled and units are specified
|
// Auto-convert if enabled and units are specified
|
||||||
if (this.autoConvert && sourceUnit && targetUnit && sourceUnit !== targetUnit) {
|
if (this.autoConvert && sourceUnit && targetUnit && sourceUnit !== targetUnit) {
|
||||||
try {
|
try {
|
||||||
convertedValue = convertModule(val).from(sourceUnit).to(targetUnit);
|
convertedValue = convertModule(val).from(sourceUnit).to(targetUnit);
|
||||||
finalUnit = targetUnit;
|
finalUnit = targetUnit;
|
||||||
|
|
||||||
if (this.logger) {
|
if (this.logger) {
|
||||||
this.logger.debug(`Auto-converted ${val} ${sourceUnit} to ${convertedValue} ${targetUnit}`);
|
this.logger.debug(`Auto-converted ${val} ${sourceUnit} to ${convertedValue} ${targetUnit}`);
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (this.logger) {
|
|
||||||
this.logger.warn(`Auto-conversion failed from ${sourceUnit} to ${targetUnit}: ${error.message}`);
|
|
||||||
}
|
|
||||||
convertedValue = val;
|
|
||||||
finalUnit = sourceUnit;
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (this.logger) {
|
||||||
|
this.logger.warn(`Auto-conversion failed from ${sourceUnit} to ${targetUnit}: ${error.message}`);
|
||||||
|
}
|
||||||
|
convertedValue = val;
|
||||||
|
finalUnit = sourceUnit;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
measurement.setValue(convertedValue, timestamp);
|
measurement.setValue(convertedValue, timestamp);
|
||||||
|
|
||||||
if (finalUnit && !measurement.unit) {
|
if (finalUnit && !measurement.unit) {
|
||||||
measurement.setUnit(finalUnit);
|
measurement.setUnit(finalUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ENHANCED: Emit event with rich context
|
// ENHANCED: Emit event with rich context
|
||||||
const eventData = {
|
const eventData = {
|
||||||
value: convertedValue,
|
value: convertedValue,
|
||||||
originalValue: val,
|
originalValue: val,
|
||||||
unit: finalUnit,
|
unit: finalUnit,
|
||||||
sourceUnit: sourceUnit,
|
sourceUnit: sourceUnit,
|
||||||
timestamp,
|
timestamp,
|
||||||
position: this._currentPosition,
|
position: this._currentPosition,
|
||||||
variant: this._currentVariant,
|
variant: this._currentVariant,
|
||||||
type: this._currentType,
|
type: this._currentType,
|
||||||
// NEW: Enhanced context
|
// NEW: Enhanced context
|
||||||
childId: this.childId,
|
childId: this.childId,
|
||||||
childName: this.childName,
|
childName: this.childName,
|
||||||
parentRef: this.parentRef
|
parentRef: this.parentRef
|
||||||
};
|
};
|
||||||
|
|
||||||
// Emit the exact event your parent expects
|
// Emit the exact event your parent expects
|
||||||
this.emitter.emit(`${this._currentType}.${this._currentVariant}.${this._currentPosition}`, eventData);
|
this.emitter.emit(`${this._currentType}.${this._currentVariant}.${this._convertPositionNum2Str(this._currentPosition)}`, eventData);
|
||||||
//console.log(`Emitted event: ${this._currentType}.${this._currentVariant}.${this._currentPosition}`, eventData);
|
this.emitter.emit(`${this._currentType}.${this._currentVariant}.${this._currentPosition}`, eventData);
|
||||||
|
// console.log(`Emitted event: ${this._currentType}.${this._currentVariant}.${this._currentPosition}`, eventData);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -283,7 +284,7 @@ class MeasurementContainer {
|
|||||||
|
|
||||||
// Helper methods
|
// Helper methods
|
||||||
_ensureChainIsValid() {
|
_ensureChainIsValid() {
|
||||||
if (!this._currentType || !this._currentVariant || !this._currentPosition) {
|
if (!this._currentType || !this._currentVariant || Number.isNaN(this._currentPosition)) {
|
||||||
if (this.logger) {
|
if (this.logger) {
|
||||||
this.logger.error('Incomplete measurement chain, required: type, variant, and position');
|
this.logger.error('Incomplete measurement chain, required: type, variant, and position');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user