Skip to content

Commit

Permalink
(#2847) Fix Pro Oceanus spaced measurements
Browse files Browse the repository at this point in the history
Was not working when sensor was taking extended sleeps without zeroing
  • Loading branch information
squaregoldfish committed Jan 23, 2024
1 parent 68ce6e7 commit 165ff9a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import uk.ac.exeter.QuinCe.data.Dataset.QC.Flag;
import uk.ac.exeter.QuinCe.data.Instrument.Instrument;
Expand Down Expand Up @@ -93,7 +91,7 @@ public List<Measurement> locateMeasurements(Connection conn,

// Loop through all the rows, examining the zero/run type columns to
// locate flushing values.
Set<SensorValue> flaggedSensorValues = new HashSet<SensorValue>();
List<SensorValue> flaggedSensorValues = new ArrayList<SensorValue>();

SensorValuesList co2Values = sensorValues.getColumnValues(co2Column);

Expand All @@ -116,12 +114,6 @@ public List<Measurement> locateMeasurements(Connection conn,
flushingCO2.setUserQC(Flag.FLUSHING, "Flushing");
flaggedSensorValues.add(flushingCO2);
}

for (SensorValue flushingRunType : runTypes
.getRawValues(flushingStart, flushingEnd)) {
flushingRunType.setUserQC(Flag.FLUSHING, "Flushing");
flaggedSensorValues.add(flushingRunType);
}
}

lastZero = newZero;
Expand All @@ -146,10 +138,12 @@ public List<Measurement> locateMeasurements(Connection conn,
lastRunType = newRunType;
}

// Force the CO2 and Run Type output values to be recalculated now that
// Store the updated flags
DataSetDataDB.storeSensorValues(conn, flaggedSensorValues);

// Force the CO2 output values to be recalculated now that
// some values have had their flags changed.
co2Values.resetOutput();
runTypes.resetOutput();
}

// Now we construct measurements based on the remaining run types.
Expand All @@ -162,25 +156,31 @@ public List<Measurement> locateMeasurements(Connection conn,
* TSG data).
*/
if (null != runType) {
if (runType.getStringValue().equals(WATER_MODE)) {
if (instrument.hasVariable(waterVar)) {
measurements.add(new Measurement(dataset.getId(),
runType.getNominalTime(), waterRunTypes));
}
} else if (runType.getStringValue().equals(ATM_MODE)) {
if (instrument.hasVariable(atmVar)) {
measurements.add(new Measurement(dataset.getId(),
runType.getNominalTime(), atmRunTypes));

SensorValuesListValue co2Value = co2Values.getValue(runType.getTime(),
false);

// We only make measurements for non-flushing CO2 values
if (null != co2Value) {
if (runType.getStringValue().equals(WATER_MODE)) {
if (instrument.hasVariable(waterVar)) {
measurements.add(new Measurement(dataset.getId(),
runType.getNominalTime(), waterRunTypes));
}
} else if (runType.getStringValue().equals(ATM_MODE)) {
if (instrument.hasVariable(atmVar)) {
measurements.add(new Measurement(dataset.getId(),
runType.getNominalTime(), atmRunTypes));
}
} else {
throw new MeasurementLocatorException(
"Unrecognised ProOceanus mode '" + runType.getStringValue()
+ "'");
}
} else {
throw new MeasurementLocatorException(
"Unrecognised ProOceanus mode '" + runType.getStringValue()
+ "'");
}
}
}

DataSetDataDB.storeSensorValues(conn, flaggedSensorValues);
return measurements;
} catch (Exception e) {
if (e instanceof MeasurementLocatorException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Collection<MeasurementValue> collectMeasurementValues(
.getColumnValues(columnId);

SensorValuesListValue value = sensorValuesList
.getValue(referenceValue, false);
.getValue(referenceValue, true);

result.add(new MeasurementValue(sensorType, value));
} catch (SensorValuesListException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,10 @@ private SensorValuesListValue getValuePeriodic(LocalDateTime time,
? outputValues.get(searchIndex)
: null;

if (null != exactMatch || !allowInterpolation) {
if (null != exactMatch) {
result = new SensorValuesListValue(exactMatch, time);
} else if (!allowInterpolation) {
result = null;
} else {
// Get the previous and next groups
SensorValuesListValue prior = null;
Expand Down

0 comments on commit 165ff9a

Please sign in to comment.