[PATCH 2 of 3] Added gauge name column for uinfo iota
Wald Commits
scm-commit at wald.intevation.org
Mon Aug 13 17:28:13 CEST 2018
# HG changeset patch
# User mschaefer
# Date 1534173993 -7200
# Node ID 6e7094368e973d066a6f5760578f282bb9ed9b89
# Parent 6ebc9357550cd6fe0ccffddfda754f7ee6e9a424
Added gauge name column for uinfo iota
diff -r 6ebc9357550c -r 6e7094368e97 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/RiverInfoProvider.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/RiverInfoProvider.java Mon Aug 13 17:15:05 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/RiverInfoProvider.java Mon Aug 13 17:26:33 2018 +0200
@@ -37,11 +37,18 @@
public static RiverInfoProvider forRange(final CallContext context, final River river, final DoubleRange calcRange) {
+ return forRange(context, river, calcRange, false);
+ }
+
+ public static RiverInfoProvider forRange(final CallContext context, final River river, final DoubleRange calcRange, final boolean firstGaugeIsRefGauge) {
+
final List<Gauge> gauges = river.determineGauges(calcRange.getMinimumDouble(), calcRange.getMaximumDouble());
final GaugeIndex gaugeIndex = new GaugeIndex(gauges);
final String notinrange = Resources.getMsg(context.getMeta(), CSV_NOT_IN_GAUGE_RANGE, CSV_NOT_IN_GAUGE_RANGE);
+ if (firstGaugeIsRefGauge && !gauges.isEmpty())
+ return new RiverInfoProvider(notinrange, river, false, gaugeIndex, gauges.get(0));
return new RiverInfoProvider(notinrange, river, false, gaugeIndex, null);
}
@@ -93,14 +100,14 @@
return gauge == null ? this.notinrange : gauge.getName();
}
- public String findGauge(final double km, final boolean allGauges) {
+ private String findGauge(final double km, final boolean allGauges) {
// REMARK: access the gauge once only during calculation
final Gauge gauge = getGauge(km, allGauges);
return gauge == null ? this.notinrange : gauge.getName();
}
- private Gauge getGauge(final double km) {
+ public Gauge getGauge(final double km) {
// REMARK: using same logic as in WaterlevelExporter here
diff -r 6ebc9357550c -r 6e7094368e97 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java Mon Aug 13 17:15:05 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java Mon Aug 13 17:26:33 2018 +0200
@@ -18,6 +18,7 @@
import org.apache.commons.lang.math.DoubleRange;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.access.RangeAccess;
+import org.dive4elements.river.artifacts.common.AbstractResultType;
import org.dive4elements.river.artifacts.common.GeneralResultType;
import org.dive4elements.river.artifacts.model.Calculation;
import org.dive4elements.river.artifacts.model.CalculationResult;
@@ -69,7 +70,7 @@
final ScenarioType scenarioType = accessSalix.getScenario();
- final RiverInfoProvider riverInfoProvider = RiverInfoProvider.forRange(this.context, river, range);
+ final RiverInfoProvider riverInfoProvider = RiverInfoProvider.forRange(this.context, river, range, true);
final SalixLineCalculationResults results = new SalixLineCalculationResults(calcModeLabel, user, riverInfo, range);
@@ -254,4 +255,15 @@
}
return "";
}
+
+ /**
+ * Fetches a iota or waterlevel height of a station from a salix calculation result
+ */
+ public double fetchStationHeight(final double station, final AbstractResultType resultType, final SalixLineCalculationResult result) {
+
+ final Calculation problems = new Calculation();
+
+ final SalixLineCalculator calculator = new SalixLineCalculator(null);
+ return calculator.fetchStationHeight(problems, station, resultType, result);
+ }
}
\ No newline at end of file
diff -r 6ebc9357550c -r 6e7094368e97 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationResult.java Mon Aug 13 17:15:05 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculationResult.java Mon Aug 13 17:26:33 2018 +0200
@@ -85,6 +85,7 @@
header.add(exportContextCSV.msg(SalixScenario.getDeltaWHeader()));
header.add(exportContextCSV.msg(SalixScenario.getScenarioValueHeader()));
}
+ header.add(exportContextCSV.formatCsvHeader(GeneralResultType.gaugeLabel));
exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
}
@@ -114,6 +115,7 @@
for (int i = 1; i <= this.getScenarioCount(); i++) {
// TODO Spaltenueberschriften der Scenarios
}
+ exportContextPDF.addJRMetadata(source, "gauge_header", GeneralResultType.gaugeLabel);
}
private String[] formatRow(final IExportContext context, final ResultRow row) {
@@ -136,6 +138,7 @@
lines.add("");
}
}
+ lines.add(context.formatRowValue(row, GeneralResultType.gaugeLabel));
return lines.toArray(new String[lines.size()]);
}
diff -r 6ebc9357550c -r 6e7094368e97 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Mon Aug 13 17:15:05 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculator.java Mon Aug 13 17:26:33 2018 +0200
@@ -11,6 +11,7 @@
import java.math.BigDecimal;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -19,6 +20,7 @@
import org.dive4elements.river.artifacts.WINFOArtifact;
import org.dive4elements.river.artifacts.access.ComputationRangeAccess;
+import org.dive4elements.river.artifacts.common.AbstractResultType;
import org.dive4elements.river.artifacts.common.GeneralResultType;
import org.dive4elements.river.artifacts.common.ResultRow;
import org.dive4elements.river.artifacts.model.Calculation;
@@ -54,6 +56,7 @@
private QPosition refGaugeMwPos;
private QPosition refGaugeMnwPos;
private QPosition refGaugeMhwPos;
+ private Gauge firstGauge;
private Calculation problems;
@@ -101,7 +104,7 @@
this.gaugeMwPos.clear();
this.gaugeMnwPos.clear();
this.gaugeMhwPos.clear();
- boolean first = true;
+ this.firstGauge = null;
for (final Gauge gauge : this.riverInfoProvider.getGauges()) {
this.gaugeMwPos.put(gauge, null);
this.gaugeMnwPos.put(gauge, null);
@@ -115,11 +118,11 @@
else if (mv.getMainValue().getName().equalsIgnoreCase("mhq"))
this.gaugeMhwPos.put(gauge, this.wst.getQPosition(gaugeKm, mv.getValue().doubleValue()));
}
- if (first) {
+ if (this.firstGauge == null) {
this.refGaugeMwPos = this.gaugeMwPos.get(gauge);
this.refGaugeMnwPos = this.gaugeMnwPos.get(gauge);
this.refGaugeMhwPos = this.gaugeMhwPos.get(gauge);
- first = false;
+ this.firstGauge = gauge;
}
}
if (this.refGaugeMwPos == null)
@@ -167,6 +170,7 @@
}
}
row.putValue(UInfoResultType.customMultiRowColSalixScenarios, scenarios);
+ row.putValue(GeneralResultType.gaugeLabel, this.riverInfoProvider.findGauge(station));
return row;
}
@@ -209,4 +213,28 @@
noScen.add(null);
return noScen;
}
+
+ /**
+ * Find and return a height (iota, w main value) of a station in a previously calculated result
+ */
+ public double fetchStationHeight(final Calculation problems, final double station, final AbstractResultType resultType,
+ final SalixLineCalculationResult result) {
+
+ // Search the station in the previously calculated result rows
+ final ResultRow stationRow = searchStation(station, result.getRows());
+ if (stationRow != null)
+ return stationRow.getDoubleValue(resultType);
+ return Double.NaN;
+ }
+
+ /**
+ * Searches the row of a station in a result rows collection
+ */
+ private ResultRow searchStation(final double station, final Collection<ResultRow> rows) {
+ for (final ResultRow row : rows) {
+ if (row.getDoubleValue(GeneralResultType.station) > station + 0.0001)
+ return row;
+ }
+ return null;
+ }
}
\ No newline at end of file
diff -r 6ebc9357550c -r 6e7094368e97 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineProcessor.java Mon Aug 13 17:15:05 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineProcessor.java Mon Aug 13 17:26:33 2018 +0200
@@ -16,6 +16,8 @@
import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.artifactdatabase.state.Facet;
import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.RangeAccess;
import org.dive4elements.river.artifacts.common.AbstractProcessor;
import org.dive4elements.river.artifacts.resources.Resources;
import org.dive4elements.river.artifacts.uinfo.common.UInfoResultType;
@@ -137,7 +139,15 @@
}
if (bundle.getFacetName().equals(FACET_SALIX_RANK)) {
- // TODO return buildSeriesForType(generator, bundle, theme, visible, UInfoResultType.salixline, GAP_DISTANCE);
+ final CallContext context = generator.getContext();
+ final RangeAccess kmRange = new RangeAccess((D4EArtifact) bundle.getArtifact());
+ // TODO get all rank data (5 ranks) from database
+ final double[][] points = new double[2][2];
+ points[0][0] = kmRange.getLowerKm();
+ points[0][1] = kmRange.getUpperKm();
+ points[1][0] = 1.5;
+ points[1][1] = 1.5;
+ return buildSeriesForPoints(points, generator, bundle, theme, visible, null);
}
return buildSeriesForType(generator, bundle, theme, visible, doGetType(bundle.getFacetName()), GAP_DISTANCE);
More information about the Dive4Elements-commits
mailing list