const fs = require('node:fs'); const path = require('node:path'); const { MeasurementContainer } = require('generalFunctions'); function makeMonsterConfig(overrides = {}) { return { general: { name: 'Monster Test', logging: { enabled: false, logLevel: 'error' }, }, asset: { emptyWeightBucket: 3, }, constraints: { samplingtime: 1, minVolume: 5, maxWeight: 23, nominalFlowMin: 1000, flowMax: 6000, maxRainRef: 10, minSampleIntervalSec: 60, }, ...overrides, }; } function withMockedDate(iso, fn) { const RealDate = Date; let now = new RealDate(iso).getTime(); class MockDate extends RealDate { constructor(...args) { if (args.length === 0) { super(now); } else { super(...args); } } static now() { return now; } } global.Date = MockDate; try { return fn({ advance(ms) { now += ms; }, }); } finally { global.Date = RealDate; } } function parseMonsternametijdenCsv(filePath) { const raw = fs.readFileSync(filePath, 'utf8').trim(); const lines = raw.split(/\r?\n/); const header = lines.shift(); const columns = header.split(','); return lines .filter((line) => line && !line.startsWith('-----------')) .map((line) => { const parts = []; let cur = ''; let inQ = false; for (let i = 0; i < line.length; i++) { const ch = line[i]; if (ch === '"') { inQ = !inQ; continue; } if (ch === ',' && !inQ) { parts.push(cur); cur = ''; } else { cur += ch; } } parts.push(cur); const obj = {}; columns.forEach((col, idx) => { obj[col] = parts[idx]; }); return obj; }); } function makeFlowMeasurementChild({ id = 'flow-child-1', name = 'FlowSensor', positionVsParent = 'downstream', unit = 'm3/h', } = {}) { const measurements = new MeasurementContainer({ autoConvert: true, defaultUnits: { flow: 'm3/h' }, }); return { config: { general: { id, name, unit }, functionality: { positionVsParent }, asset: { type: 'flow', unit }, }, measurements, }; } function loadRainSeed() { const rainPath = path.join(__dirname, '..', 'seed_data', 'raindataFormat.json'); return JSON.parse(fs.readFileSync(rainPath, 'utf8')); } function loadScheduleSeed() { const csvPath = path.join(__dirname, '..', 'seed_data', 'monsternametijden.csv'); return parseMonsternametijdenCsv(csvPath); } module.exports = { makeMonsterConfig, withMockedDate, makeFlowMeasurementChild, loadRainSeed, loadScheduleSeed, };