Skip to content

Commit

Permalink
fix: compute missing variables min/max while loading measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Nov 29, 2022
1 parent 705effa commit 0304b17
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/app-data/loaders/loadMeasurements.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { FileCollection } from 'filelist-utils';
import { xMinMaxValues } from 'ml-spectra-processing';

import { Measurements, enhance, Enhancers } from '../index';
import { Measurements, enhance, Enhancers, MeasurementBase } from '../index';

import {
MeasurementsLoader,
Expand All @@ -23,8 +24,32 @@ export async function loadMeasurements(
const { loaders = [], enhancers = {}, logger = true } = options;
for (const loader of loaders) {
const loaderData = await loader(fileCollection, logger ? logs : undefined);
for (const { entries } of Object.values(loaderData)) {
for (const entry of entries) {
computeMinMax(entry);
}
}
enhance(loaderData, enhancers);
mergeMeasurements(measurements, loaderData);
}
return { measurements, logs };
}

function computeMinMax(measurement: MeasurementBase) {
for (const datum of measurement.data) {
for (const variable of Object.values(datum.variables)) {
if (variable.data.length === 0) {
// TODO: should we accept empty data?
return;
}
if (
typeof variable.min === 'undefined' ||
typeof variable.max === 'undefined'
) {
const { min, max } = xMinMaxValues(variable.data);
variable.min = min;
variable.max = max;
}
}
}
}

0 comments on commit 0304b17

Please sign in to comment.