[Dive4elements-commits] [PATCH 13 of 17] flys/issue1077: Show loads as step line, therefore transform data in
Wald Commits
scm-commit at wald.intevation.org
Wed Apr 10 17:14:19 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1365579307 -7200
# Node ID 696d710470f5f05209fdc4de7ca702b77f00a820
# Parent bae2b1568f3d2ec199628a09534f2b620cec8b71
flys/issue1077: Show loads as step line, therefore transform data in
SedimentLoadFacet to stretch as in the measurement stations bounds.
Deal with this new kind of data in the Generator.
diff -r bae2b1568f3d -r 696d710470f5 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/SedimentLoadFacet.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/SedimentLoadFacet.java Wed Apr 10 09:32:47 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/SedimentLoadFacet.java Wed Apr 10 09:35:07 2013 +0200
@@ -2,20 +2,30 @@
import org.apache.log4j.Logger;
+import java.util.ArrayList;
+import java.util.List;
+
import de.intevation.artifactdatabase.state.Facet;
import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.CallContext;
import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.model.CalculationResult;
import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.model.MeasurementStation;
+import de.intevation.flys.artifacts.model.FacetTypes;
import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+import de.intevation.flys.utils.FLYSUtils;
+
public class SedimentLoadFacet
extends DataFacet
{
+ /** Very own logger. */
private static Logger logger = Logger.getLogger(SedimentLoadFacet.class);
+ private static double EPSILON = 1e-5;
+
public SedimentLoadFacet() {
}
@@ -35,9 +45,73 @@
Object[] data =
(SedimentLoadResult[]) res.getData(); // TODO CAST TO SPECIFIC CLASS
- return data != null && data.length > index ? data[index] : null;
+ List<MeasurementStation> allStations = FLYSUtils.getRiver(flys).getMeasurementStations();
+ SedimentLoadResult result = data != null && data.length > index ? (SedimentLoadResult)data[index] : null;
+ if (result == null) {
+ return null;
+ }
+
+ // Filter stations according to type.
+ List<MeasurementStation> stations = new ArrayList<MeasurementStation>();
+ for (MeasurementStation station: allStations) {
+ if (station.getRange() == null || station.getMeasurementType() == null) {
+ continue;
+ }
+ if (FacetTypes.IS.SEDIMENT_LOAD_NO_FLOAT(this.getName()) && station.getMeasurementType().equals("Geschiebe"))
+ stations.add(station);
+ else if (!FacetTypes.IS.SEDIMENT_LOAD_NO_FLOAT(this.getName()) && station.getMeasurementType().equals("Schwebstoff"))
+ stations.add(station);
+ }
+
+ // Access data according to type.
+ double[][] sd = null;
+ if (getName().equals(FacetTypes.SEDIMENT_LOAD_SAND))
+ sd = result.getSandData();
+ else if (getName().equals(FacetTypes.SEDIMENT_LOAD_COARSE))
+ sd = result.getCoarseData();
+ else if (getName().equals(FacetTypes.SEDIMENT_LOAD_FINEMIDDLE))
+ sd = result.getFineMiddleData();
+ else if (getName().equals(FacetTypes.SEDIMENT_LOAD_SUSP_SAND))
+ sd = result.getSuspSandData();
+ else if (getName().equals(FacetTypes.SEDIMENT_LOAD_SUSP_SAND_BED))
+ sd = result.getSuspSandBedData();
+ else if (getName().equals(FacetTypes.SEDIMENT_LOAD_SUSP_SEDIMENT))
+ sd = result.getSuspSedimentData();
+ else if (getName().equals(FacetTypes.SEDIMENT_LOAD_TOTAL_LOAD))
+ sd = result.getTotalLoadData();
+ else if (getName().equals(FacetTypes.SEDIMENT_LOAD_TOTAL))
+ sd = result.getTotalData();
+
+ double[] km = sd[0];
+ double[] load = sd[1];
+
+ double[][] values = new double[2][];
+ values[0] = new double[km.length*2];
+ values[1] = new double[km.length*2];
+
+ // Find station via its station (km).
+ // TODO what to do with gaps in measurement stations.
+ for (int i = 0; i < km.length; i++) {
+ boolean matchFound = false;
+ for (MeasurementStation station: stations) {
+ if (Math.abs(station.getStation() - km[i]) < EPSILON) {
+ values[0][i*2] = station.getRange().getA().doubleValue();
+ values[1][i*2] = load[i];
+ values[0][i*2+1] = station.getRange().getB().doubleValue();
+ values[1][i*2+1] = load[i];
+ matchFound = true;
+ }
+ }
+ if (!matchFound) {
+ values[0][i*2] = km[i];
+ values[1][i*2] = load[i];
+ logger.debug("No measurement station for km " + km[i]);
+ }
+ }
+ return values;
}
+
/** Copy deeply. */
@Override
public Facet deepCopy() {
diff -r bae2b1568f3d -r 696d710470f5 flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/SedimentLoadLSGenerator.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/SedimentLoadLSGenerator.java Wed Apr 10 09:32:47 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/SedimentLoadLSGenerator.java Wed Apr 10 09:35:07 2013 +0200
@@ -128,56 +128,56 @@
}
if (name.equals(SEDIMENT_LOAD_COARSE)) {
doSedimentLoadCoarseOut(
- (SedimentLoadResult) bundle.getData(context),
+ (double[][]) bundle.getData(context),
bundle,
attr,
visible);
}
else if (name.equals(SEDIMENT_LOAD_SAND)) {
doSedimentLoadSandOut(
- (SedimentLoadResult) bundle.getData(context),
+ (double[][]) bundle.getData(context),
bundle,
attr,
visible);
}
else if (name.equals(SEDIMENT_LOAD_FINEMIDDLE)) {
doSedimentLoadFineMiddleOut(
- (SedimentLoadResult) bundle.getData(context),
+ (double[][]) bundle.getData(context),
bundle,
attr,
visible);
}
else if (name.equals(SEDIMENT_LOAD_SUSP_SAND)) {
doSedimentLoadSuspSandOut(
- (SedimentLoadResult) bundle.getData(context),
+ (double[][]) bundle.getData(context),
bundle,
attr,
visible);
}
else if (name.equals(SEDIMENT_LOAD_SUSP_SAND_BED)) {
doSedimentLoadSuspSandBedOut(
- (SedimentLoadResult) bundle.getData(context),
+ (double[][]) bundle.getData(context),
bundle,
attr,
visible);
}
else if (name.equals(SEDIMENT_LOAD_SUSP_SEDIMENT)) {
doSedimentLoadSuspSedimentOut(
- (SedimentLoadResult) bundle.getData(context),
+ (double[][]) bundle.getData(context),
bundle,
attr,
visible);
}
else if (name.equals(SEDIMENT_LOAD_TOTAL_LOAD)) {
doSedimentLoadTotalLoadOut(
- (SedimentLoadResult) bundle.getData(context),
+ (double[][]) bundle.getData(context),
bundle,
attr,
visible);
}
else if (name.equals(SEDIMENT_LOAD_TOTAL)) {
doSedimentLoadTotalOut(
- (SedimentLoadResult) bundle.getData(context),
+ (double[][]) bundle.getData(context),
bundle,
attr,
visible);
@@ -290,77 +290,77 @@
return label;
}
- protected void doSedimentLoadCoarseOut(SedimentLoadResult data,
+ // TODO all double[][] eating *Out() can be subsumed.
+ protected void doSedimentLoadCoarseOut(double[][] data,
ArtifactAndFacet aandf, Document theme, boolean visible) {
XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
- StyledSeriesBuilder.addPoints(series, data.getCoarseData(), true);
+ StyledSeriesBuilder.addPoints(series, data, true);
addAxisSeries(series, YAXIS.L.idx, visible);
}
- protected void doSedimentLoadSandOut(SedimentLoadResult data,
+ protected void doSedimentLoadSandOut(double[][] data,
ArtifactAndFacet aandf, Document theme, boolean visible) {
XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
- StyledSeriesBuilder.addPoints(series, data.getSandData(), true);
+ StyledSeriesBuilder.addPoints(series, data, true);
addAxisSeries(series, YAXIS.L.idx, visible);
}
- protected void doSedimentLoadFineMiddleOut(SedimentLoadResult data,
+ protected void doSedimentLoadFineMiddleOut(double[][] data,
ArtifactAndFacet aandf, Document theme, boolean visible) {
XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
- StyledSeriesBuilder.addPoints(series, data.getFineMiddleData(), true);
+ StyledSeriesBuilder.addPoints(series, data, true);
addAxisSeries(series, YAXIS.L.idx, visible);
}
- protected void doSedimentLoadSuspSandOut(SedimentLoadResult data,
+ protected void doSedimentLoadSuspSandOut(double[][] data,
ArtifactAndFacet aandf, Document theme, boolean visible) {
XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
- StyledSeriesBuilder.addPoints(series, data.getSuspSandData(), true);
+ StyledSeriesBuilder.addPoints(series, data, true);
addAxisSeries(series, YAXIS.L.idx, visible);
}
- protected void doSedimentLoadSuspSandBedOut(SedimentLoadResult data,
+ protected void doSedimentLoadSuspSandBedOut(double[][] data,
ArtifactAndFacet aandf, Document theme, boolean visible) {
XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
- StyledSeriesBuilder.addPoints(series, data.getSuspSandBedData(), true);
+ StyledSeriesBuilder.addPoints(series, data, true);
addAxisSeries(series, YAXIS.L.idx, visible);
}
- protected void doSedimentLoadSuspSedimentOut(SedimentLoadResult data,
+ protected void doSedimentLoadSuspSedimentOut(double[][] data,
ArtifactAndFacet aandf, Document theme, boolean visible) {
XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
- StyledSeriesBuilder.addPoints(series, data.getSuspSedimentData(), true);
+ StyledSeriesBuilder.addPoints(series, data, true);
addAxisSeries(series, YAXIS.L.idx, visible);
}
- protected void doSedimentLoadTotalLoadOut(SedimentLoadResult data,
+ protected void doSedimentLoadTotalLoadOut(double[][] data,
ArtifactAndFacet aandf, Document theme, boolean visible) {
XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
- StyledSeriesBuilder.addPoints(series, data.getTotalLoadData(), true);
+ StyledSeriesBuilder.addPoints(series, data, true);
addAxisSeries(series, YAXIS.L.idx, visible);
}
- protected void doSedimentLoadTotalOut(SedimentLoadResult data,
+ protected void doSedimentLoadTotalOut(double[][] data,
ArtifactAndFacet aandf, Document theme, boolean visible) {
XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
- StyledSeriesBuilder.addPoints(series, data.getTotalData(), true);
+ StyledSeriesBuilder.addPoints(series, data, true);
addAxisSeries(series, YAXIS.L.idx, visible);
- }
protected void doFlowVelocityMainOut(
FlowVelocityData data,
More information about the Dive4elements-commits
mailing list