annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/PredefinedDepthEvolPerYearProcessor.java @ 9033:384eee4b4135

Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
author mschaefer
date Fri, 27 Apr 2018 17:41:59 +0200
parents
children 1cc7653ca84f
rev   line source
9033
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
2 * Software engineering by
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
5 *
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
9 */
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
10
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
11 package org.dive4elements.river.artifacts.sinfo.common;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
12
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
13 import java.util.HashSet;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
14 import java.util.Map;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
15 import java.util.Set;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
16
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
18 import org.dive4elements.artifactdatabase.state.Facet;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
19 import org.dive4elements.artifacts.Artifact;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
20 import org.dive4elements.artifacts.CallContext;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
21 import org.dive4elements.artifacts.CallMeta;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
22 import org.dive4elements.river.artifacts.resources.Resources;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
23 import org.dive4elements.river.artifacts.sinfo.predefineddepthevol.PredefinedDepthEvolFacet;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
24 import org.dive4elements.river.artifacts.sinfo.predefineddepthevol.PredefinedDepthEvolQueryCalculationResult;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
25 import org.dive4elements.river.exports.DiagramGenerator;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
26 import org.dive4elements.river.exports.StyledSeriesBuilder;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
27 import org.dive4elements.river.jfree.StyledXYSeries;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
28 import org.dive4elements.river.themes.ThemeDocument;
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
29
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
30 /**
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
31 * Processor to generate a data series for depth evolution per year data loaded from the database
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
32 *
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
33 * @author Matthias Schäfer
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
34 *
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
35 */
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
36 public class PredefinedDepthEvolPerYearProcessor extends AbstractSInfoProcessor {
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
37
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
38 // private final static Logger log = Logger.getLogger(PredefinedDepthEvolPerYearProcessor.class);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
39
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
40 public static final String FACET_PREDEFINED_DEPTHEVOL_PER_YEAR = "sinfo_facet_predefined_depthevol_per_year";
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
41
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
42 private static final String I18N_AXIS_LABEL = "sinfo.chart.flow_depth_development_per_year.section.yaxis.label";
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
43
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
44 private static final String I18N_SERIES_NAME_PATTERN = "predefineddepthevol.peryear.title";
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
45
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
46 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>();
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
47
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
48 static {
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
49 HANDLED_FACET_TYPES.add(FACET_PREDEFINED_DEPTHEVOL_PER_YEAR);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
50 }
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
51
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
52 public PredefinedDepthEvolPerYearProcessor() {
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
53 super(I18N_AXIS_LABEL, HANDLED_FACET_TYPES);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
54 }
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
55
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
56 @Override
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
57 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
58
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
59 final CallContext context = generator.getCallContext();
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
60 final Map<String, String> metaData = bundle.getFacet().getMetaData();
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
61
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
62 final Artifact artifact = bundle.getArtifact();
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
63
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
64 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
65 series.putMetaData(metaData, artifact, context);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
66
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
67 final String facetName = bundle.getFacetName();
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
68 final PredefinedDepthEvolQueryCalculationResult data = (PredefinedDepthEvolQueryCalculationResult) bundle.getData(context);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
69 if (data == null) {
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
70 // Check has been here before so we keep it for security reasons
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
71 // this should never happen though.
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
72 throw new IllegalStateException("Data is null for facet: " + facetName);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
73 }
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
74
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
75 final double[][] points = data.getStationPoints(SInfoResultType.flowdepthDevelopmentPerYear);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
76
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
77 StyledSeriesBuilder.addPoints(series, points, true);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
78 generator.addAxisSeries(series, getAxisName(), visible);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
79
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
80 return metaData.get("Y");
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
81 }
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
82
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
83 public static Facet createFacet(final CallMeta callMeta, final String seriesName) {
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
84 return new PredefinedDepthEvolFacet(FACET_PREDEFINED_DEPTHEVOL_PER_YEAR,
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
85 Resources.getMsg(callMeta, I18N_SERIES_NAME_PATTERN, I18N_SERIES_NAME_PATTERN, seriesName), I18N_AXIS_LABEL);
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
86 }
384eee4b4135 Added datacage select and chart display for flow depth evolution series loaded from database, and a correction for the tkh data
mschaefer
parents:
diff changeset
87 }

http://dive4elements.wald.intevation.org