annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java @ 8856:5e38e2924c07 3.2.x

Fix code style.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:12:01 +0100
parents 1127dbe95083
children 0a5239a1e46e
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
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
18 import org.apache.log4j.Logger;
ebbb18ed78c4 Added new classes and stubs used to calculate data for historical discharge curve charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5339
diff changeset
20 import org.dive4elements.river.model.DischargeTable;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5339
diff changeset
21 import org.dive4elements.river.model.Gauge;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5339
diff changeset
22 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
23
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
24 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
25 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
26
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
27
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 /**
5339
1b73b731f7bd Doc, debug fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4281
diff changeset
29 * 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
30 * @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
31 */
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 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
33
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
34 private static final Logger log = Logger.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
35
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
36 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
37 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
38 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
39 private Long officialGaugeNumber;
6839
fe03337c8011 (issue1353) Add river name handling
Andre Heinecke <aheinecke@intevation.de>
parents: 6301
diff changeset
40 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
41
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
42
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
43 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
44 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
45 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
46 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
47 ? 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
48 : access.getQs();
7261
a56fe3bc6700 Refactoring: Let RiverAccess.getRiver return an River.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6839
diff changeset
49 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
50
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 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
52
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 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
54 // 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
55 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
56 }
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 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
58 // 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
59 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
60 }
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 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
62 // 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
63 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
64 }
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 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
67 // 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
68 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
69 }
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 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
72 set(
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5962
diff changeset
73 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
74 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
75 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
76 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
77 }
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 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
81 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
82 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
83 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
84 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
85 ) {
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 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
87 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
88 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
89 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
90 }
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
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
92 protected CalculationResult error(String msg) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
93 addProblem(msg);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
94 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
95 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
96
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
97 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
98 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
99 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
100 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
101 }
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
6839
fe03337c8011 (issue1353) Add river name handling
Andre Heinecke <aheinecke@intevation.de>
parents: 6301
diff changeset
103 Gauge gauge = Gauge.getGaugeByOfficialNumber(officialGaugeNumber,
fe03337c8011 (issue1353) Add river name handling
Andre Heinecke <aheinecke@intevation.de>
parents: 6301
diff changeset
104 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
105 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
106 // TODO: i18n
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
107 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
108 }
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 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
111 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
112 }
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
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
114 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
115 if (dts.isEmpty()) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
116 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
117 }
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
118
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
119 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
120
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
121 boolean debug = log.isDebugEnabled();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
122
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
123 if (debug) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
124 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
125 }
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 ValuesCache vc = new ValuesCache();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
128
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
129 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
130
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
131 if (debug) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
132 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
133 }
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
134
8462
1127dbe95083 Remove obsolete historical discharge curve implementations.
Tom Gottfried <tom@intevation.de>
parents: 8358
diff changeset
135 return new CalculationResult(new HistoricalDischargeData(wqt),
4241
49cb65d5932d Improved the historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4232
diff changeset
136 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
137 }
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
138
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
139 /** 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
140 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
141 DischargeTable ref = null;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
142 long now = System.currentTimeMillis();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
143 for (DischargeTable dt: dts) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
144 if (ref == null) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
145 ref = dt;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
146 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
147 else {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
148 TimeInterval cti = dt.getTimeInterval();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
149 TimeInterval rti = ref.getTimeInterval();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
150
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
151 long ct = cti.getStopTime() != null
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
152 ? cti.getStopTime().getTime()
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
153 : now;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
154 long rt = rti.getStopTime() != null
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
155 ? rti.getStopTime().getTime()
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
156 : now;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
157
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
158 if (ct > rt) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
159 ref = dt;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
160 }
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 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
165 }
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
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
167 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
168
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
169 List<DischargeTable> all = gauge.getDischargeTables();
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8462
diff changeset
170 List<DischargeTable> relevant =
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8462
diff changeset
171 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
172
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
173 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
174 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
175 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
176 }
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 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
180 }
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
181
5339
1b73b731f7bd Doc, debug fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4281
diff changeset
182 /** 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
183 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
184
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
185 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
186
2598
e96bf6c47c12 Improved selecting discharge tables for historical discharge calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2418
diff changeset
187 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
188 return false;
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
189 }
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
190
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
191 long dtStart = ti.getStartTime().getTime();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
192 long dtStop = ti.getStopTime() != null
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
193 ? ti.getStopTime().getTime()
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
194 : 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
195
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
196 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
197 }
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
198
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
199 protected String name(double value) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
200 return mode == EvaluationMode.W.getMode()
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
201 ? "W=" + value
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
202 : "Q=" + value;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
203 }
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
204
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
205 /** With reference. */
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
206 protected HistoricalWQTimerange[] prepareData(
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
207 DischargeTable refTable,
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
208 List<DischargeTable> dts,
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
209 ValuesCache vc
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
210 ) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
211 List<HistoricalWQTimerange> wqts =
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
212 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
213
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
214 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
215
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
216 for (double value: values) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
217 if (debug) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
218 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
219 }
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 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
222 ? vc.findValueForW(refTable, value)
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
223 : vc.findValueForQ(refTable, value);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
224
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
225 if (Double.isNaN(ref)) {
8247
b8f343230eab Some i18n completion in hist. discharge curves.
Tom Gottfried <tom@intevation.de>
parents: 7261
diff changeset
226 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
227 mode == EvaluationMode.W.getMode()
b8f343230eab Some i18n completion in hist. discharge curves.
Tom Gottfried <tom@intevation.de>
parents: 7261
diff changeset
228 ? "cm"
b8f343230eab Some i18n completion in hist. discharge curves.
Tom Gottfried <tom@intevation.de>
parents: 7261
diff changeset
229 : "m\u00b3/s");
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
230 continue;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
231 }
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 String name = name(value);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
234 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
235
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
236 for (DischargeTable dt : dts) {
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
237 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
238 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
239 double w;
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
240 double q;
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
241 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
242
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
243 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
244 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
245
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 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
247 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
248 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
249 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
250 }
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
251
4232
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
252 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
253 }
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 else {
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
255 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
256
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
257 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
258 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
259 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
260 continue;
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
261 }
b3aa91e45010 Implemented the Q evaluation mode for historical discharge calculations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 4138
diff changeset
262 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
263 }
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
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
265 if (debug) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
266 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
267 }
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
268
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 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
270 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
271 }
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
2315
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
273 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
274 }
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 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
277 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
278 }
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
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
281 return (HistoricalWQTimerange[])wqts.toArray(
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
282 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
283 }
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
5339
1b73b731f7bd Doc, debug fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4281
diff changeset
285 /** 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
286 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
287 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
288
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
289 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
290 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
291
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
292 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
293 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
294
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
295 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
296 }
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 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
299 }
c0dfa36add96 Some bugfixes and improvements in the calculation of historical discharge curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2311
diff changeset
300
2228
4db19a88bddb Implemented the first step of Calculation6; create Facets for each calculation results.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2219
diff changeset
301
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
302 /** 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
303 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
304
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
305 private Map<Integer, double[][]> cache;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
306
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
307 ValuesCache() {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
308 cache = new HashMap<Integer, double [][]>();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
309 }
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 double [][] getValues(DischargeTable dt) {
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
312 Integer id = dt.getId();
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
313 double [][] vs = cache.get(id);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
314 if (vs == null) {
6301
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 6064
diff changeset
315 vs = DischargeTables.loadDischargeTableValues(dt);
5962
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
316 cache.put(id, vs);
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
317 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
318 return vs;
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
319 }
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 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
322 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
323 }
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 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
326 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
327 }
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 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
330 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
331 }
d861efa13272 Partial rewrite of historical discharge curves. Needs testing.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5959
diff changeset
332 } // 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
333
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
334 /**
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
335 * 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
336 */
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 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
338 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
339 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
340 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
341 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
342 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
343 }
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
344 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org