[PATCH] Fix for flys/issue1479: The indices of the dates of the analysis periods where re-mapped wrong
Wald Commits
scm-commit at wald.intevation.org
Thu Sep 12 16:35:17 CEST 2013
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1378996507 -7200
# Node ID 3e93f29281bcf0b580d718855afca2ec72bf4739
# Parent e96d3f6c7c4221d1159053f033f5397fe9a45c95
Fix for flys/issue1479: The indices of the dates of the analysis periods where re-mapped wrong.
diff -r e96d3f6c7c42 -r 3e93f29281bc artifacts/src/main/java/org/dive4elements/river/artifacts/model/FixingsOverview.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FixingsOverview.java Thu Sep 12 11:50:39 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FixingsOverview.java Thu Sep 12 16:35:07 2013 +0200
@@ -770,14 +770,21 @@
protected Date end;
public DateRangeFilter(Date start, Date end) {
- this.start = start;
- this.end = end;
+ if (start.before(end)) {
+ this.start = start;
+ this.end = end;
+ }
+ else {
+ this.start = end;
+ this.end = start;
+ }
}
@Override
public boolean accept(Fixing.Column column) {
Date date = column.getStartTime();
- return start.compareTo(date) <= 0 && end.compareTo(date) >= 0;
+ // start <= date <= end
+ return !(date.before(start) || date.after(end));
}
} // class DateRangeFilter
diff -r e96d3f6c7c42 -r 3e93f29281bc artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisCalculation.java Thu Sep 12 11:50:39 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisCalculation.java Thu Sep 12 16:35:07 2013 +0200
@@ -126,7 +126,7 @@
Function function,
Parameters parameters,
FixingsOverview overview,
- ColumnCache cc
+ ColumnCache cc
) {
Range range = new Range(from, to);
@@ -150,15 +150,28 @@
TIntIntHashMap [] col2indices =
new TIntIntHashMap[analysisPeriods.length];
+ DateRangeFilter [] drfs = new DateRangeFilter[analysisPeriods.length];
+
+ boolean debug = log.isDebugEnabled();
+
for (int i = 0; i < analysisPeriods.length; ++i) {
col2indices[i] = new TIntIntHashMap();
+ drfs[i] = new DateRangeFilter(
+ analysisPeriods[i].getFrom(),
+ analysisPeriods[i].getTo());
+
+ if (debug) {
+ log.debug("Analysis period " + (i+1) + " date range: " +
+ analysisPeriods[i].getFrom() + " - " +
+ analysisPeriods[i].getTo());
+ }
}
for (int row = 0, R = parameters.size(); row < R; ++row) {
double km = parameters.get(row, kmIndex);
parameters.get(row, parameterIndices, parameterValues);
- // This is the paraterized function for a given km.
+ // This is the parameterized function for a given km.
org.dive4elements.river.artifacts.math.Function instance =
function.instantiate(parameterValues);
@@ -171,9 +184,7 @@
DateRange analysisPeriod = analysisPeriods[ap];
TIntIntHashMap col2index = col2indices[ap];
- DateRangeFilter drf = new DateRangeFilter(
- analysisPeriod.getFrom(),
- analysisPeriod.getTo());
+ DateRangeFilter drf = drfs[ap];
QWD [] qSectorAverages = new QWD[4];
double [] qSectorStdDevs = new double[4];
@@ -291,8 +302,9 @@
parameters.set(row, maxQIndex, maxQ);
}
- results.add(km, periodResults.toArray(
- new AnalysisPeriod[periodResults.size()]));
+ AnalysisPeriod [] rap = new AnalysisPeriod[periodResults.size()];
+ periodResults.toArray(rap);
+ results.add(km, rap);
}
return results;
diff -r e96d3f6c7c42 -r 3e93f29281bc artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisResult.java Thu Sep 12 11:50:39 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixAnalysisResult.java Thu Sep 12 16:35:07 2013 +0200
@@ -8,6 +8,8 @@
package org.dive4elements.river.artifacts.model.fixings;
+import gnu.trove.TIntObjectHashMap;
+
import java.util.Collection;
import java.util.Date;
import java.util.TreeMap;
@@ -56,17 +58,22 @@
public void makeAnalysisEventsUnique() {
- // Actually it would be enough to make dates
- // unique in one analysis period but to simplify things
- // we make them unique in all periods.
- DateUniqueMaker dum = new DateUniqueMaker();
+ TIntObjectHashMap dums = new TIntObjectHashMap();
+
for (KMIndex.Entry<AnalysisPeriod []> entry: analysisPeriods) {
- for (AnalysisPeriod ap: entry.getValue()) {
+ AnalysisPeriod [] aps = entry.getValue();
+ for (int i = 0; i < aps.length; ++i) {
+ AnalysisPeriod ap = aps[i];
QWD [] qwds = ap.getQWDs();
- if (qwds != null) {
- for (QWD qwd: qwds) {
- dum.makeUnique(qwd);
- }
+ if (qwds == null) {
+ continue;
+ }
+ DateUniqueMaker dum = (DateUniqueMaker)dums.get(i);
+ if (dum == null) {
+ dums.put(i, dum = new DateUniqueMaker());
+ }
+ for (QWD qwd: qwds) {
+ dum.makeUnique(qwd);
}
}
}
diff -r e96d3f6c7c42 -r 3e93f29281bc artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixAnalysisCompute.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixAnalysisCompute.java Thu Sep 12 11:50:39 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/FixAnalysisCompute.java Thu Sep 12 16:35:07 2013 +0200
@@ -173,7 +173,7 @@
int qsE = access.getQSectorEnd();
DateFormat df = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy");
- DateFormat lf = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyy'T'HH:mm");
+ DateFormat lf = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy'T'HH:mm");
DateRange [] periods = access.getAnalysisPeriods();
More information about the Dive4elements-commits
mailing list