annotate artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java @ 9556:9b8e8fc1f408

Use facetName in all processors as themeType for legend aggregation.
author gernotbelger
date Tue, 23 Oct 2018 16:26:58 +0200
parents 1cc7653ca84f
children
rev   line source
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 *
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7 */
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 package org.dive4elements.river.exports.process;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11 import org.apache.log4j.Logger;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 import org.jfree.data.xy.XYSeries;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13
8204
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
14 import gnu.trove.TDoubleArrayList;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
15
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 import org.dive4elements.artifacts.CallContext;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 import org.dive4elements.river.exports.DiagramGenerator;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19 import org.dive4elements.river.exports.StyledSeriesBuilder;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 import org.dive4elements.river.jfree.StyledXYSeries;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 import org.dive4elements.river.themes.ThemeDocument;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22
8204
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
23 import org.dive4elements.river.artifacts.D4EArtifact;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
24 import org.dive4elements.river.artifacts.access.RiverAccess;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
25 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
26 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
27 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataFactory;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
28
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 // Base class for SedimantLoad$UNITProcessors
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 public class SedimentLoadProcessor extends DefaultProcessor
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8154
diff changeset
32 private final static Logger log =
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 Logger.getLogger(SedimentLoadProcessor.class);
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34
8204
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
35 private static final double EPS = 1e-4;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
36
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 @Override
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 public void doOut(
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 DiagramGenerator generator,
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 ArtifactAndFacet bundle,
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 ThemeDocument theme,
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 boolean visible) {
8215
204905c16ade Fetch missing values from database and show them in diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8204
diff changeset
43
9123
1cc7653ca84f Cleanup of ChartGenerator and ChartGenerator2 code. Put some of the copy/pasted code into a common abstraction.
gernotbelger
parents: 8215
diff changeset
44 CallContext context = generator.getContext();
9556
9b8e8fc1f408 Use facetName in all processors as themeType for legend aggregation.
gernotbelger
parents: 9123
diff changeset
45 XYSeries series = new StyledXYSeries(bundle.getFacetName(),bundle.getFacetDescription(),
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 false, // Handle NaN
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 theme);
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 Object data = bundle.getData(context);
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 String facetName = bundle.getFacetName();
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8154
diff changeset
51 log.debug("Do out for: " + facetName);
8148
eb48b244921d The rest is silence.
Tom Gottfried <tom@intevation.de>
parents: 8117
diff changeset
52 if (facetName.startsWith("sedimentload.")) {
8204
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
53 /* Remove stations (with NaN-values) at stations of
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
54 different type than appropriate for current fraction.*/
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
55 String [] facetNameParts = facetName.split("\\.");
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
56 int gfSType = SedimentLoadData.measurementStationType(
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
57 SedimentLoadData.grainFractionIndex(
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
58 facetNameParts[facetNameParts.length-1]));
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
59
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
60 RiverAccess access =
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
61 new RiverAccess((D4EArtifact)bundle.getArtifact());
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
62 String river = access.getRiverName();
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
63 SedimentLoadData sld =
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
64 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
65
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
66 double [][] allData = (double[][]) data;
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
67 TDoubleArrayList cleanedKms =
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
68 new TDoubleArrayList(allData[0].length);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
69 TDoubleArrayList cleanedValues =
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
70 new TDoubleArrayList(allData[0].length);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
71
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
72 for (int i = 0; i < allData[0].length; ++i) {
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
73 double km = allData[0][i];
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
74 Station station = sld.findStations(km-EPS, km+EPS).get(0);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
75 if (station.isType(gfSType)) {
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
76 cleanedKms.add(km);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
77 cleanedValues.add(allData[1][i]);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
78 }
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
79 }
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
80
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
81 double [][] points = new double[2][cleanedKms.size()];
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
82 points[0] = cleanedKms.toNativeArray();
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
83 points[1] = cleanedValues.toNativeArray();
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
84
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
85 StyledSeriesBuilder.addPoints(series, points, false); // Keep NaN
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
86
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
87 generator.addAxisSeries(series, axisName, visible);
c657ddcf1fa6 Sediment loads at measurement stations and longitudinal sections need different processing and styling for diagrams.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
88
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 } else {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8154
diff changeset
90 log.error("Unknown facet name: " + facetName);
7685
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
91 return;
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
92 }
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93 }
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
94 }
270946b97539 (issue1614) Handle NaN in Styled Series created by SedimentLoadProcessors
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
95

http://dive4elements.wald.intevation.org