Mercurial > dive4elements > river
changeset 6891:8efef772a488
FixA: Remapped indices of analysis periods, too. Needs testing!
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 21 Aug 2013 15:41:58 +0200 |
parents | feaf76b70190 |
children | e97e710ecf3f |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisCalculation.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisResult.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixResult.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/RankRemapper.java |
diffstat | 4 files changed, 80 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisCalculation.java Wed Aug 21 15:00:40 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisCalculation.java Wed Aug 21 15:41:58 2013 +0200 @@ -106,7 +106,9 @@ far.remapReferenceIndicesToRank(); far.makeAnalysisEventsUnique(); - // TODO: remapping + for (int i = 0; i < this.analysisPeriods.length; ++i) { + far.remapAnalysisEventsIndicesToRank(i); + } return new CalculationResult(far, this); }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisResult.java Wed Aug 21 15:00:40 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisResult.java Wed Aug 21 15:41:58 2013 +0200 @@ -10,6 +10,7 @@ import java.util.Collection; import java.util.Date; +import java.util.TreeMap; import java.util.TreeSet; import org.apache.log4j.Logger; @@ -84,6 +85,34 @@ return dates; } + public Collection<Integer> getAnalysisEventsIndices(int analysisPeriod) { + TreeMap<Date, Integer> dates = new TreeMap<Date, Integer>(); + for (KMIndex.Entry<AnalysisPeriod []> entry: analysisPeriods) { + QWD [] qwds = entry.getValue()[analysisPeriod].getQWDs(); + if (qwds != null) { + for (QWD qwd: qwds) { + dates.put(qwd.date, qwd.index); + } + } + } + return dates.values(); + } + + public void remapAnalysisEventsIndicesToRank(int analysisPeriod) { + RankRemapper remapper = new RankRemapper(); + for (Integer index: getAnalysisEventsIndices(analysisPeriod)) { + remapper.toMap(index); + } + for (KMIndex.Entry<AnalysisPeriod []> entry: analysisPeriods) { + QWD [] qwds = entry.getValue()[analysisPeriod].getQWDs(); + if (qwds != null) { + for (QWD qwd: qwds) { + remapper.remap(qwd); + } + } + } + } + public KMIndex<AnalysisPeriod []> getAnalysisPeriods() { return analysisPeriods; }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixResult.java Wed Aug 21 15:00:40 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixResult.java Wed Aug 21 15:41:58 2013 +0200 @@ -13,8 +13,6 @@ import org.dive4elements.river.utils.KMIndex; -import gnu.trove.TIntIntHashMap; - import java.io.Serializable; import java.util.Collection; import java.util.Date; @@ -72,44 +70,13 @@ } public void remapReferenceIndicesToRank() { - Collection<Integer> referenceIndices = getReferenceEventsIndices(); - int index = 0; - TIntIntHashMap map = new TIntIntHashMap(); - boolean debug = log.isDebugEnabled(); - for (Integer refId: referenceIndices) { - if (debug) { - log.debug("map " + refId + " -> " + index); - } - map.put(refId, index); - ++index; + RankRemapper remapper = new RankRemapper(); + for (Integer idx: getReferenceEventsIndices()) { + remapper.toMap(idx); } - - // Two passes: If there are shared references do not - // remap them twice. In the first pass all indices are - // mapped to negative values (assuming the original data - // is all positive). If a negative value is found ignore - // it because it was remapped before. - for (KMIndex.Entry<QWD []> entry: referenced) { for (QWD value: entry.getValue()) { - if (value.index >= 0) { - if (map.containsKey(value.index)) { - value.index = -(map.get(value.index) + 1); - } - else { - log.warn("Could not remap index: " + value.index); - } - } - } - } - - // In the second pass all indices are turned to positive - // values again. - for (KMIndex.Entry<QWD []> entry: referenced) { - for (QWD value: entry.getValue()) { - if (value.index < 0) { - value.index = -(value.index + 1); - } + remapper.remap(value); } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/RankRemapper.java Wed Aug 21 15:41:58 2013 +0200 @@ -0,0 +1,44 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.artifacts.model.fixings; + +import java.util.IdentityHashMap; + +import org.apache.log4j.Logger; + +import gnu.trove.TIntIntHashMap; + +public class RankRemapper { + + private static Logger log = Logger.getLogger(RankRemapper.class); + + private TIntIntHashMap index2rank; + private IdentityHashMap<QWI, Boolean> visited; + + public RankRemapper() { + index2rank = new TIntIntHashMap(); + visited = new IdentityHashMap<QWI, Boolean>(); + } + + public void toMap(int index) { + index2rank.put(index, index2rank.size()); + } + + public <I extends QWI> void remap(I qwi) { + if (!visited.containsKey(qwi)) { + int idx = qwi.index; + if (index2rank.containsKey(idx)) { + qwi.index = index2rank.get(idx); + } else if (log.isDebugEnabled()) { + log.debug("Cannot remap " + idx); + } + visited.put(qwi, true); + } + } +}