Mercurial > dive4elements > river
changeset 8242:f8ea1a7ecde6
(issue1448) Fix info service for epoch / periods and off epoch
This also includes a bit cleanup to move the sqRelationTimeInterval check
to the creation of the load list in SedimentLoadData allLoads.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 09 Sep 2014 11:13:37 +0200 (2014-09-09) |
parents | a65afd85d516 |
children | 0a994bbe645e |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java |
diffstat | 2 files changed, 70 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Tue Sep 09 10:53:50 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Tue Sep 09 11:13:37 2014 +0200 @@ -230,6 +230,36 @@ } } + public void allOfficialLoads(Collection<Load> loads) { + for (List<Value> values: grainFractions) { + if (values != null) { + for (Value value: values) { + Load load = value.getLoad(); + if (load.getKind() == 1) { + loads.add(value.getLoad()); + } + } + } + } + } + + public void allLoads(Collection<Load> loads, Integer sqRelationTimeInterval) { + + for (List<Value> values: grainFractions) { + if (values == null) { + continue; + } + for (Value value: values) { + Load load = value.getLoad(); + Integer sqId = load.getSQRelationTimeIntervalId(); + if ((sqRelationTimeInterval == null) + || sqId != null && sqId.equals(sqRelationTimeInterval)) { + loads.add(load); + } + } + } + } + public double getStation() { return station; } @@ -435,6 +465,25 @@ } }; + public static final Comparator<Load> LOAD_TI_CMP = new Comparator<Load>() { + @Override + public int compare(Load a, Load b) { + Date a_start = a.getStartTime(); + Date a_stop = a.getStopTime(); + Date b_start = b.getStartTime(); + Date b_stop = b.getStopTime(); + if (a_start == null && b_start == null) { + return 0; + } else if (a_start != null) { + return a_start.compareTo(b_start); + } else if (a_stop != null) { + return a_stop.compareTo(b_stop); + } else { + return 1; + } + } + }; + public static final Comparator<Load> LOAD_SQ_TI_CMP = new Comparator<Load>() { @Override public int compare(Load a, Load b) { @@ -454,24 +503,29 @@ }; /** Find all loads in the range a/b with the according sq_time_interval */ - public Collection<Load> findLoads(double a, double b, Integer sqRelationTimeInterval) { + public Collection<Load> findLoads(double a, double b, final Integer sqRelationTimeInterval) { final TreeSet<Load> loads = new TreeSet<Load>(LOAD_ID_CMP); findStations(a, b, new Visitor() { @Override public void visit(Station station) { - station.allLoads(loads); + station.allLoads(loads, sqRelationTimeInterval); } }); - /* This may not be the most beautiful thing to do but well,.. */ - for (Iterator<Load> it = loads.iterator(); it.hasNext();) { - Integer obj = it.next().getSQRelationTimeIntervalId(); - if ((obj == null && sqRelationTimeInterval != null) || - (obj != null && !obj.equals(sqRelationTimeInterval))) { - it.remove(); + return loads; + } + + /** Find all official loads with a distinct time interval id */ + public Collection<Load> findUniqueTiOfficialLoads(double a, double b) { + final TreeSet<Load> loads = new TreeSet<Load>(LOAD_TI_CMP); + + findStations(a, b, new Visitor() { + @Override + public void visit(Station station) { + station.allOfficialLoads(loads); } - } + }); return loads; }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java Tue Sep 09 10:53:50 2014 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java Tue Sep 09 11:13:37 2014 +0200 @@ -85,8 +85,7 @@ log.debug("Requested type: " + type + " with sq_ti_id: " + sq_ti_id); Collection <Load> loads; if (type.equals("off_epoch")) { - /* TODO */ - loads = null; + loads = allLoadData.findUniqueTiOfficialLoads(fromD, toD); } else if (type.equals("sq_time_intervals")) { loads = allLoadData.findUniqueTimeIntervalLoads(fromD, toD); @@ -99,12 +98,16 @@ } else { if (!sq_ti_id.isEmpty()) { Integer id = Integer.parseInt(sq_ti_id); - log.debug("Finding only items for id"); loads = allLoadData.findLoads(fromD, toD, id); } else { - log.debug("Finding everything."); loads = allLoadData.findLoads(fromD, toD); } + for (Iterator<Load> it = loads.iterator(); it.hasNext();) { + /* Skip epochs . */ + if (it.next().isEpoch()) { + it.remove(); + } + } } return buildDocument(loads);