Complete general functions
This commit is contained in:
56
helper/measurements/MeasurementBuilder.js
Normal file
56
helper/measurements/MeasurementBuilder.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const Measurement = require('./Measurement');
|
||||
|
||||
class MeasurementBuilder {
|
||||
constructor() {
|
||||
this.type = null;
|
||||
this.variant = null;
|
||||
this.position = null;
|
||||
this.windowSize = 10; // Default window size
|
||||
}
|
||||
|
||||
// e.g. 'pressure', 'flow', etc.
|
||||
setType(type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
// e.g. 'predicted' or 'measured', etc..
|
||||
setVariant(variant) {
|
||||
this.variant = variant;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Downstream or upstream of parent object
|
||||
setPosition(position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
|
||||
// default size of the data that gets tracked
|
||||
setWindowSize(windowSize) {
|
||||
this.windowSize = windowSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
build() {
|
||||
// Validate required fields
|
||||
if (!this.type) {
|
||||
throw new Error('Measurement type is required');
|
||||
}
|
||||
if (!this.variant) {
|
||||
throw new Error('Measurement variant is required');
|
||||
}
|
||||
if (!this.position) {
|
||||
throw new Error('Measurement position is required');
|
||||
}
|
||||
|
||||
return new Measurement(
|
||||
this.type,
|
||||
this.variant,
|
||||
this.position,
|
||||
this.windowSize
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MeasurementBuilder;
|
||||
Reference in New Issue
Block a user