This commit is contained in:
znetsixe
2026-02-23 13:17:47 +01:00
parent 1cfb36f604
commit c60aa40666
17 changed files with 358 additions and 53 deletions

View File

@@ -4,6 +4,7 @@ const convertModule = require('../convert/index');
class MeasurementContainer {
constructor(options = {},logger) {
this.logger = logger || null;
this.emitter = new EventEmitter();
this.measurements = {};
this.windowSize = options.windowSize || 10; // Default window size
@@ -96,7 +97,10 @@ class MeasurementContainer {
variant(variantName) {
if (!this._currentType) {
throw new Error('Type must be specified before variant');
if (this.logger) {
this.logger.warn('variant() ignored: type must be specified before variant');
}
return this;
}
this._currentVariant = variantName;
this._currentPosition = null;
@@ -106,11 +110,13 @@ class MeasurementContainer {
position(positionValue) {
if (!this._currentVariant) {
throw new Error('Variant must be specified before position');
if (this.logger) {
this.logger.warn('position() ignored: variant must be specified before position');
}
return this;
}
this._currentPosition = positionValue.toString().toLowerCase();;
this._currentPosition = positionValue.toString().toLowerCase();
return this;
}
@@ -429,7 +435,10 @@ class MeasurementContainer {
// Difference calculations between positions
difference({ from = "downstream", to = "upstream", unit: requestedUnit } = {}) {
if (!this._currentType || !this._currentVariant) {
throw new Error("Type and variant must be specified for difference calculation");
if (this.logger) {
this.logger.warn('difference() ignored: type and variant must be specified');
}
return null;
}
const get = pos => {
@@ -510,7 +519,10 @@ class MeasurementContainer {
getVariants() {
if (!this._currentType) {
throw new Error('Type must be specified before listing variants');
if (this.logger) {
this.logger.warn('getVariants() ignored: type must be specified first');
}
return [];
}
return this.measurements[this._currentType] ?
Object.keys(this.measurements[this._currentType]) : [];
@@ -518,7 +530,10 @@ class MeasurementContainer {
getPositions() {
if (!this._currentType || !this._currentVariant) {
throw new Error('Type and variant must be specified before listing positions');
if (this.logger) {
this.logger.warn('getPositions() ignored: type and variant must be specified first');
}
return [];
}
if (!this.measurements[this._currentType] ||
@@ -628,7 +643,10 @@ class MeasurementContainer {
if (positionValue > 0) {
return "downstream";
}
console.log(`Invalid position provided: ${positionValue}`);
if (this.logger) {
this.logger.warn(`Invalid position provided: ${positionValue}`);
}
return null;
}
}