annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/MiddleBedHeightCalculation.java @ 6152:0587819960c3

Waterlevel differences & bed height differences: Add new model LinearInterpolated intented to unify the two very similiar calculations. The focus of the current implementation is correctness and not speed! The fact that the data sets more mostly sorted by station is not exploited. Doing so would improve performance significantly.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 02 Jun 2013 17:52:53 +0200
parents af13ceeba52a
children 2c7a16d59f67
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5920
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5920
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3931
diff changeset
9 package org.dive4elements.river.artifacts.model;
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import java.util.ArrayList;
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import java.util.List;
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import org.apache.log4j.Logger;
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3931
diff changeset
16 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3931
diff changeset
17 import org.dive4elements.artifacts.common.utils.DateUtils;
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3931
diff changeset
19 import org.dive4elements.river.model.BedHeightEpoch;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3931
diff changeset
20 import org.dive4elements.river.model.BedHeightEpochValue;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3931
diff changeset
21 import org.dive4elements.river.model.BedHeightSingle;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3931
diff changeset
22 import org.dive4elements.river.model.BedHeightSingleValue;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3931
diff changeset
23 import org.dive4elements.river.model.TimeInterval;
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3931
diff changeset
25 import org.dive4elements.river.artifacts.access.BedHeightAccess;
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 public class MiddleBedHeightCalculation extends Calculation {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 private static final Logger logger =
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 Logger.getLogger(MiddleBedHeightCalculation.class);
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
3230
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
34 public CalculationResult calculate(BedHeightAccess access) {
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 logger.info("MiddleBedHeightCalculation.calculate");
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
3230
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
37 int[] singleIds = access.getBedHeightSingleIDs();
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
38 int[] epochIds = access.getBedHeightEpochIDs();
3232
cdbc457e23e2 Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3230
diff changeset
39
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 if (logger.isDebugEnabled()) {
3258
3c006a53e551 Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3232
diff changeset
42 Artifact artifact = access.getArtifact();
3232
cdbc457e23e2 Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3230
diff changeset
43
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 logger.debug("Artifact '" + artifact.identifier() + "' contains:");
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 if (singleIds != null) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 logger.debug(" " + singleIds.length + " single bedheight ids");
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 if (epochIds != null) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 logger.debug(" " + epochIds.length + " epoch bedheight ids");
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
3230
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
54 List<BedHeightSingle> singles = getSingles(access, singleIds);
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
55 List<BedHeightEpoch> epochs = getEpochs(access, epochIds);
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
3230
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
57 return buildCalculationResult(access, singles, epochs);
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
3230
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
61 protected List<BedHeightSingle> getSingles(
3258
3c006a53e551 Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3232
diff changeset
62 BedHeightAccess access,
3c006a53e551 Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3232
diff changeset
63 int[] ids
3230
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
64 ) {
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 List<BedHeightSingle> singles = new ArrayList<BedHeightSingle>();
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 for (int id: ids) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 BedHeightSingle s = BedHeightSingle.getBedHeightSingleById(id);
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 if (s != null) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 singles.add(s);
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 else {
3924
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
74 logger.warn("Cannot find Single by id: " + id);
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 // TODO ADD WARNING
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 return singles;
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82
3230
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
83 protected List<BedHeightEpoch> getEpochs(
3258
3c006a53e551 Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3232
diff changeset
84 BedHeightAccess access,
3c006a53e551 Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3232
diff changeset
85 int[] ids
3230
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
86 ) {
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 List<BedHeightEpoch> epochs = new ArrayList<BedHeightEpoch>();
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 for (int id: ids) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 BedHeightEpoch e = BedHeightEpoch.getBedHeightEpochById(id);
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 if (e != null) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 epochs.add(e);
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 else {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 logger.warn("Cannot find Epoch by id: " + id);
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 // TODO ADD WARNING
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 return epochs;
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 protected CalculationResult buildCalculationResult(
3931
c79b98085096 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3926
diff changeset
106 BedHeightAccess access,
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 List<BedHeightSingle> singles,
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 List<BedHeightEpoch> epochs
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 ) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 logger.info("MiddleBedHeightCalculation.buildCalculationResult");
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111
3230
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
112 double kmLo = access.getLowerKM();
b888c5eb65b3 Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2715
diff changeset
113 double kmHi = access.getUpperKM();
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>();
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 for (BedHeightSingle single: singles) {
2715
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
118 MiddleBedHeightData d = prepareSingleData(single, kmLo, kmHi);
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 if (d != null) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 data.add(d);
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 for (BedHeightEpoch epoch: epochs) {
2715
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
126 MiddleBedHeightData d = prepareEpochData(epoch, kmLo, kmHi);
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 if (d != null) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 data.add(d);
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 logger.debug("Calculation results in " + data.size() + " data objects.");
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 return new CalculationResult((MiddleBedHeightData[])
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 data.toArray(new MiddleBedHeightData[data.size()]), this);
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139
2715
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
140 protected MiddleBedHeightData prepareSingleData(
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
141 BedHeightSingle single,
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
142 double kmLo,
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
143 double kmHi
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
144 ) {
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 logger.debug("Prepare data for single: " + single.getDescription());
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146
2715
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
147 List<BedHeightSingleValue> values =
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
148 BedHeightSingleValue.getBedHeightSingleValues(single, kmLo, kmHi);
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149
5920
22dbf92a4f18 Partial fix for issue862: avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5863
diff changeset
150 int year = single.getYear() != null ? single.getYear() : 0;
22dbf92a4f18 Partial fix for issue862: avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5863
diff changeset
151
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 MiddleBedHeightData data = new MiddleBedHeightData(
5920
22dbf92a4f18 Partial fix for issue862: avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5863
diff changeset
153 year,
22dbf92a4f18 Partial fix for issue862: avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5863
diff changeset
154 year,
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 single.getEvaluationBy(),
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 single.getDescription());
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 for (BedHeightSingleValue value: values) {
3924
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
159 if (value.getHeight() != null) {
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
160 data.addAll(value.getStation().doubleValue(),
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
161 value.getHeight().doubleValue(),
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
162 value.getUncertainty().doubleValue(),
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
163 value.getSoundingWidth().doubleValue(),
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
164 value.getDataGap().doubleValue(),
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
165 value.getWidth().doubleValue(),
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
166 false);
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
167 }
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
168 else {
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
169 data.addAll(value.getStation().doubleValue(),
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
170 0,
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
171 0,
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
172 0,
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
173 0,
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
174 0,
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
175 true);
5fced192b95c Towards fix of issue863 (gaps in middle heigh bed data).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
176 }
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 logger.debug("Single contains " + values.size() + " values");
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 return data;
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184
3926
e20307be4cc3 Fix issue863.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3924
diff changeset
185 /** Create MiddleBedHeightData to return. */
2715
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
186 protected MiddleBedHeightData prepareEpochData(
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
187 BedHeightEpoch epoch,
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
188 double kmLo,
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
189 double kmHi
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
190 ) {
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 logger.debug("Prepare data for epoch: " + epoch.getDescription());
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 TimeInterval ti = epoch.getTimeInterval();
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194
2715
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
195 List<BedHeightEpochValue> values =
250a370c377d Added chart generator for middle bed height charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2713
diff changeset
196 BedHeightEpochValue.getBedHeightEpochValues(epoch, kmLo, kmHi);
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 MiddleBedHeightData data = new MiddleBedHeightData(
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 DateUtils.getYearFromDate(ti.getStartTime()),
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 DateUtils.getYearFromDate(ti.getStopTime()),
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 epoch.getEvaluationBy(),
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 epoch.getDescription()
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 );
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 for (BedHeightEpochValue value: values) {
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 data.addKM(value.getStation().doubleValue());
3926
e20307be4cc3 Fix issue863.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3924
diff changeset
207 if (value.getHeight() != null) {
e20307be4cc3 Fix issue863.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3924
diff changeset
208 data.addMiddleHeight(value.getHeight().doubleValue());
e20307be4cc3 Fix issue863.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3924
diff changeset
209 data.addIsEmpty(false);
e20307be4cc3 Fix issue863.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3924
diff changeset
210 }
e20307be4cc3 Fix issue863.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3924
diff changeset
211 else {
e20307be4cc3 Fix issue863.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3924
diff changeset
212 data.addMiddleHeight(Double.NaN);
e20307be4cc3 Fix issue863.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3924
diff changeset
213 data.addIsEmpty(true);
e20307be4cc3 Fix issue863.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3924
diff changeset
214 }
2713
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217 logger.debug("Epoch contains " + values.size() + " values");
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 return data;
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221 }
b60751cfdd6c Start MINFO middle bed height calculation in the relevant state and creates facets for chart and csv.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org