annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
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: 5962
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: 5962
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: 5339
diff changeset
9 package org.dive4elements.river.artifacts.model;
2215
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
11 import java.util.ArrayList;
4241
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4232
diff changeset
12 import java.util.Arrays;
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
13 import java.util.Date;
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
14 import java.util.HashMap;
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
15 import java.util.List;
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
16 import java.util.Map;
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
17
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
18 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
19 import org.apache.logging.log4j.LogManager;
2215
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5339
diff changeset
21 import org.dive4elements.river.model.DischargeTable;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5339
diff changeset
22 import org.dive4elements.river.model.Gauge;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5339
diff changeset
23 import org.dive4elements.river.model.TimeInterval;
2219
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
24
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
25 import org.dive4elements.river.artifacts.access.HistoricalDischargeAccess;
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
26 import org.dive4elements.river.artifacts.access.HistoricalDischargeAccess.EvaluationMode;
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
27
2215
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 /**
5339
1b73b731f7bd Doc, debug fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4281
diff changeset
30 * Historical Discharge Calculation.
2215
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 */
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 public class Calculation6 extends Calculation {
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
35 private static final Logger log = LogManager.getLogger(Calculation6.class);
2215
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
37 private int mode;
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
38 private long [] timerange;
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
39 private double [] values;
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
40 private Long officialGaugeNumber;
6839
fe03337c8011 (issue1353) Add river name handling
Andre Heinecke <aheinecke@intevation.de>
parents: 6301
diff changeset
41 private String riverName;
2215
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
2219
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
43
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
44 public Calculation6(HistoricalDischargeAccess access) {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
45 EvaluationMode mode = access.getEvaluationMode();
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
46 Timerange tr = access.getEvaluationTimerange();
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
47 double [] vs = mode != null && mode == EvaluationMode.W
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
48 ? access.getWs()
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
49 : access.getQs();
7261
a56fe3bc6700 Refactoring: Let RiverAccess.getRiver return an River.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6839
diff changeset
50 riverName = access.getRiverName();
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
51
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
52 Long officialGaugeNumber = access.getOfficialGaugeNumber();
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
53
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
54 if (mode == null) {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
55 // TODO: i18n
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
56 addProblem("hist.discharge.mode.not.set");
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
57 }
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
58 if (tr == null) {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
59 // TODO: i18n
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
60 addProblem("hist.discharge.time.interval.not.set");
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
61 }
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
62 if (vs == null || vs.length == 0) {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
63 // TODO: i18n
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
64 addProblem("hist.discharge.values.not.set");
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
65 }
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
66
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
67 if (officialGaugeNumber == null) {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
68 // TODO: i18n
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
69 addProblem("hist.discharge.reference.gauge.not.set");
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
70 }
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
71
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
72 if (!hasProblems()) {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
73 set(
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5962
diff changeset
74 mode.getMode(),
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
75 new long [] { tr.getStart(), tr.getEnd()},
5918
46e85199b667 Historical discharge curve: Fixed NPE in setup.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5914
diff changeset
76 vs,
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
77 officialGaugeNumber);
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
78 }
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
79 }
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
80
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
81 protected void set(
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
82 int mode,
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
83 long [] timerange,
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
84 double [] values,
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
85 Long officialGaugeNumber
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
86 ) {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
87 this.mode = mode;
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
88 this.timerange = timerange;
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
89 this.values = values;
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
90 this.officialGaugeNumber = officialGaugeNumber;
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
91 }
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
92
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
93 protected CalculationResult error(String msg) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
94 addProblem(msg);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
95 return new CalculationResult(new HistoricalDischargeData(), this);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
96 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
97
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
98 public CalculationResult calculate() {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
99 if (hasProblems()) {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
100 log.warn("Parameters not valid for calculation.");
2219
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
101 return null;
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
102 }
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
103
6839
fe03337c8011 (issue1353) Add river name handling
Andre Heinecke <aheinecke@intevation.de>
parents: 6301
diff changeset
104 Gauge gauge = Gauge.getGaugeByOfficialNumber(officialGaugeNumber,
fe03337c8011 (issue1353) Add river name handling
Andre Heinecke <aheinecke@intevation.de>
parents: 6301
diff changeset
105 riverName);
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
106 if (gauge == null) {
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
107 // TODO: i18n
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
108 return error("hist.discharge.gauge.not.found");
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
109 }
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
110
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
111 if (log.isDebugEnabled()) {
2219
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
112 debug();
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
113 }
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
114
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
115 List<DischargeTable> dts = fetchDischargeTables(gauge);
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
116 if (dts.isEmpty()) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
117 return error("cannot.find.hist.q.tables");
2304
abb390101595 #483 Display error message in calculation report for empty historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2250
diff changeset
118 }
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
119
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
120 DischargeTable refTable = fetchReferenceTable(dts);
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
121
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
122 boolean debug = log.isDebugEnabled();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
123
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
124 if (debug) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
125 log.debug("Take " + dts.size() + " into account.");
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
126 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
127
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
128 ValuesCache vc = new ValuesCache();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
129
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
130 WQTimerange [] wqt = prepareData(refTable, dts, vc);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
131
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
132 if (debug) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
133 log.debug("Number of calculation results: " + wqt.length);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
134 }
2250
40608c82e9cb Bugfix: create a report facet for historical discharge curves even if no data has been computed.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2244
diff changeset
135
8462
1127dbe95083 Remove obsolete historical discharge curve implementations.
Tom Gottfried <tom@intevation.de>
parents: 8358
diff changeset
136 return new CalculationResult(new HistoricalDischargeData(wqt),
4241
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4232
diff changeset
137 this);
2215
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 }
2219
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
139
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
140 /** The youngest discharge table of the selected set is the reference */
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
141 protected DischargeTable fetchReferenceTable(List<DischargeTable> dts) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
142 DischargeTable ref = null;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
143 long now = System.currentTimeMillis();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
144 for (DischargeTable dt: dts) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
145 if (ref == null) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
146 ref = dt;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
147 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
148 else {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
149 TimeInterval cti = dt.getTimeInterval();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
150 TimeInterval rti = ref.getTimeInterval();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
151
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
152 long ct = cti.getStopTime() != null
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
153 ? cti.getStopTime().getTime()
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
154 : now;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
155 long rt = rti.getStopTime() != null
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
156 ? rti.getStopTime().getTime()
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
157 : now;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
158
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
159 if (ct > rt) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
160 ref = dt;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
161 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
162
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
163 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
164 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
165 return ref;
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
166 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
167
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
168 protected List<DischargeTable> fetchDischargeTables(Gauge gauge) {
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
169
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
170 List<DischargeTable> all = gauge.getDischargeTables();
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8462
diff changeset
171 List<DischargeTable> relevant =
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8462
diff changeset
172 new ArrayList<DischargeTable>(all.size());
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
173
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
174 for (DischargeTable dt: all) {
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
175 if (isDischargeTableRelevant(dt)) {
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
176 relevant.add(dt);
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
177 }
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
178 }
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
179
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
180 return relevant;
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
181 }
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
182
5339
1b73b731f7bd Doc, debug fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4281
diff changeset
183 /** True if timerange of given discharge table overlaps with timerange. */
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
184 protected boolean isDischargeTableRelevant(DischargeTable dt) {
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
185
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
186 TimeInterval ti = dt.getTimeInterval();
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
187
2598
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2418
diff changeset
188 if (dt.getKind() == Gauge.MASTER_DISCHARGE_TABLE || ti == null) {
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
189 return false;
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
190 }
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
191
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
192 long dtStart = ti.getStartTime().getTime();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
193 long dtStop = ti.getStopTime() != null
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
194 ? ti.getStopTime().getTime()
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
195 : System.currentTimeMillis();
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
196
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
197 return !(timerange[1] < dtStart || timerange[0] > dtStop);
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
198 }
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
199
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
200 protected String name(double value) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
201 return mode == EvaluationMode.W.getMode()
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
202 ? "W=" + value
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
203 : "Q=" + value;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
204 }
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
205
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
206 /** With reference. */
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
207 protected HistoricalWQTimerange[] prepareData(
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
208 DischargeTable refTable,
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
209 List<DischargeTable> dts,
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
210 ValuesCache vc
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
211 ) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
212 List<HistoricalWQTimerange> wqts =
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
213 new ArrayList<HistoricalWQTimerange>(values.length);
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
214
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
215 boolean debug = log.isDebugEnabled();
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
216
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
217 for (double value: values) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
218 if (debug) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
219 log.debug("Prepare data plus diff for value: " + value);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
220 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
221
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
222 double ref = mode == EvaluationMode.W.getMode()
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
223 ? vc.findValueForW(refTable, value)
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
224 : vc.findValueForQ(refTable, value);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
225
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
226 if (Double.isNaN(ref)) {
8247
b8f343230eab Some i18n completion in hist. discharge curves.
Tom Gottfried <tom@intevation.de>
parents: 7261
diff changeset
227 addProblem("hist.discharge.no.value.in.ref", value,
b8f343230eab Some i18n completion in hist. discharge curves.
Tom Gottfried <tom@intevation.de>
parents: 7261
diff changeset
228 mode == EvaluationMode.W.getMode()
b8f343230eab Some i18n completion in hist. discharge curves.
Tom Gottfried <tom@intevation.de>
parents: 7261
diff changeset
229 ? "cm"
b8f343230eab Some i18n completion in hist. discharge curves.
Tom Gottfried <tom@intevation.de>
parents: 7261
diff changeset
230 : "m\u00b3/s");
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
231 continue;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
232 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
233
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
234 String name = name(value);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
235 HistoricalWQTimerange wqt = null;
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
236
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
237 for (DischargeTable dt : dts) {
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
238 Date[] ti = prepareTimeInterval(dt);
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
239 Timerange t = new Timerange(ti[0], ti[1]);
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
240 double w;
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
241 double q;
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
242 double diff;
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
243
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
244 if (mode == EvaluationMode.W.getMode()) {
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
245 q = vc.findValueForW(dt, w = value);
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
246
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
247 if (Double.isNaN(q)) {
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
248 log.warn("Cannot find Q for W: " + w);
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
249 addProblem("cannot.find.hist.q.for.w", w, ti[0], ti[1]);
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
250 continue;
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
251 }
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
252
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
253 diff = ref - q;
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
254 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
255 else {
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
256 w = vc.findValueForQ(dt, q = value);
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
257
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
258 if (Double.isNaN(w)) {
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
259 log.warn("Cannot find W for Q: " + q);
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
260 addProblem("cannot.find.hist.w.for.q", q, ti[0], ti[1]);
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
261 continue;
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
262 }
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
263 diff = ref - w;
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
264 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
265
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
266 if (debug) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
267 log.debug("Q=" + q + " | W=" + w + " | Ref = " + ref);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
268 }
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
269
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
270 if (wqt == null) {
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
271 wqt = new HistoricalWQTimerange(name);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
272 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
273
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
274 wqt.add(w, q, diff, t);
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
275 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
276
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
277 if (wqt != null) {
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
278 wqts.add(wqt);
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
279 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
280 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
281
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
282 return (HistoricalWQTimerange[])wqts.toArray(
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
283 new HistoricalWQTimerange[wqts.size()]);
2311
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
284 }
b8df8d1476ba Compute differences between discharge table values and reference discharge table values in historical discharge curve calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2304
diff changeset
285
5339
1b73b731f7bd Doc, debug fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4281
diff changeset
286 /** Returns discharge table interval as Date[]. */
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
287 protected Date[] prepareTimeInterval(DischargeTable dt) {
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
288 TimeInterval ti = dt.getTimeInterval();
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
289
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
290 Date start = ti.getStartTime();
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
291 Date end = ti.getStopTime();
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
292
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
293 if (end == null) {
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
294 log.warn("TimeInterval has no stop time set!");
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
295
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
296 end = new Date();
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
297 }
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
298
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
299 return new Date[] { start, end };
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
300 }
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
301
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
302
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
303 /** Helper to avoid redundant loading of discharge table values. */
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
304 private static final class ValuesCache {
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
305
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
306 private Map<Integer, double[][]> cache;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
307
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
308 ValuesCache() {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
309 cache = new HashMap<Integer, double [][]>();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
310 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
311
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
312 double [][] getValues(DischargeTable dt) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
313 Integer id = dt.getId();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
314 double [][] vs = cache.get(id);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
315 if (vs == null) {
6301
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 6064
diff changeset
316 vs = DischargeTables.loadDischargeTableValues(dt);
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
317 cache.put(id, vs);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
318 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
319 return vs;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
320 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
321
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
322 private static double firstOrNaN(double [] vs) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
323 return vs.length > 0 ? vs[0] : Double.NaN;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
324 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
325
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
326 double findValueForW(DischargeTable dt, double w) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
327 return firstOrNaN(DischargeTables.getQsForW(getValues(dt), w));
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
328 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
329
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
330 double findValueForQ(DischargeTable dt, double q) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
331 return firstOrNaN(DischargeTables.getWsForQ(getValues(dt), q));
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
332 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
333 } // class ValuesCache
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
334
2219
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
335 /**
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
336 * Writes the parameters used for this calculation to log.
2219
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
337 */
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
338 public void debug() {
5914
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
339 log.debug("========== Calculation6 ==========");
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
340 log.debug(" Mode: " + mode);
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
341 log.debug(" Timerange: " + timerange[0] + " - " + timerange[1]);
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
342 log.debug(" Input values: " + Arrays.toString(values));
1058b3436dad D4E river artifacts: Removed historical discharge calculation from WINFO artifact and use access instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
343 log.debug("==================================");
2219
4b6e9b377a84 Fetch parameters for 'historical discharge curve' calculation; call Calculation6 with those information and check input parameters.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2215
diff changeset
344 }
2215
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
345 }
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
346 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org