Skip to content

Commit

Permalink
(#2982) Handle a dataset with no measurements of a run type
Browse files Browse the repository at this point in the history
  • Loading branch information
squaregoldfish committed Oct 18, 2024
1 parent ed6bb55 commit cb61b13
Showing 1 changed file with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,43 @@ public TreeSet<Measurement> getMeasurementsInSameRun(long variableId,
public TreeSet<Measurement> getRunBefore(long variableId, String runType,
LocalDateTime time) {

Optional<Measurement> lastBefore = getMeasurements(variableId, runType)
.stream().filter(m -> m.getTime().isBefore(time))
.reduce((first, second) -> second);
TreeSet<Measurement> result;

return lastBefore.isEmpty() ? new TreeSet<Measurement>()
: getMeasurementsInSameRun(variableId, lastBefore.get());
List<Measurement> measurements = getMeasurements(variableId, runType);

if (null == measurements) {
result = new TreeSet<Measurement>();
} else {

Optional<Measurement> lastBefore = getMeasurements(variableId, runType)
.stream().filter(m -> m.getTime().isBefore(time))
.reduce((first, second) -> second);

result = lastBefore.isEmpty() ? new TreeSet<Measurement>()
: getMeasurementsInSameRun(variableId, lastBefore.get());
}

return result;
}

public TreeSet<Measurement> getRunAfter(long variableId, String runType,
LocalDateTime time) {

Optional<Measurement> firstAfter = getMeasurements(variableId, runType)
.stream().filter(m -> m.getTime().isAfter(time)).findFirst();
TreeSet<Measurement> result;

return firstAfter.isEmpty() ? new TreeSet<Measurement>()
: getMeasurementsInSameRun(variableId, firstAfter.get());
List<Measurement> measurements = getMeasurements(variableId, runType);

if (null == measurements) {
result = new TreeSet<Measurement>();
} else {
Optional<Measurement> firstAfter = getMeasurements(variableId, runType)
.stream().filter(m -> m.getTime().isAfter(time)).findFirst();

result = firstAfter.isEmpty() ? new TreeSet<Measurement>()
: getMeasurementsInSameRun(variableId, firstAfter.get());
}

return result;

}

Expand Down

0 comments on commit cb61b13

Please sign in to comment.