Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java @ 8326:10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 25 Sep 2014 17:23:12 +0200 |
parents | d4c501d2c098 |
children | 1c732c88a2d6 |
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:
5867
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:
5867
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:
4919
diff
changeset
|
9 package org.dive4elements.river.artifacts.model; |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
10 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
11 import java.util.Arrays; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
12 import java.util.Map; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
13 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4919
diff
changeset
|
14 import org.dive4elements.artifacts.Artifact; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4919
diff
changeset
|
15 import org.dive4elements.artifacts.CallContext; |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
16 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4919
diff
changeset
|
17 import org.dive4elements.artifactdatabase.state.Facet; |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
18 |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5865
diff
changeset
|
19 import org.dive4elements.river.artifacts.D4EArtifact; |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
20 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4919
diff
changeset
|
21 import org.dive4elements.river.model.Gauge; |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
22 |
5865
73da40528cf2
River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
23 import org.dive4elements.river.utils.RiverUtils; |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
24 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
25 import org.apache.log4j.Logger; |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
26 |
8326
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
27 import static org.dive4elements.river.exports.injector.InjectorConstants.PNP; |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
28 |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
29 /** |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
30 * A Facet that returns discharge curve data at a gauge |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
31 * |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
32 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
33 */ |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
34 public class GaugeDischargeCurveFacet |
8302
8578babdb2c8
Configured gauge discharge curve to use a default D4EArtifact and two states to hold the parameters and outs.
Raimund Renkert <rrenkert@intevation.de>
parents:
6301
diff
changeset
|
35 extends DataFacet |
4032
a5e1ca620f15
Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents:
3986
diff
changeset
|
36 implements FacetTypes |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 { |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
38 private static final Logger log = |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
39 Logger.getLogger(GaugeDischargeCurveFacet.class); |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
40 |
8302
8578babdb2c8
Configured gauge discharge curve to use a default D4EArtifact and two states to hold the parameters and outs.
Raimund Renkert <rrenkert@intevation.de>
parents:
6301
diff
changeset
|
41 public GaugeDischargeCurveFacet() { |
8578babdb2c8
Configured gauge discharge curve to use a default D4EArtifact and two states to hold the parameters and outs.
Raimund Renkert <rrenkert@intevation.de>
parents:
6301
diff
changeset
|
42 } |
8578babdb2c8
Configured gauge discharge curve to use a default D4EArtifact and two states to hold the parameters and outs.
Raimund Renkert <rrenkert@intevation.de>
parents:
6301
diff
changeset
|
43 |
4187
21f4e4b79121
Refactor GaugeDischargeCurveFacet to be able to set a facet name
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4032
diff
changeset
|
44 public GaugeDischargeCurveFacet(String name, String description) { |
8302
8578babdb2c8
Configured gauge discharge curve to use a default D4EArtifact and two states to hold the parameters and outs.
Raimund Renkert <rrenkert@intevation.de>
parents:
6301
diff
changeset
|
45 super(name, description); |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
46 } |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
47 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
48 @Override |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
49 public Object getData(Artifact art, CallContext context) { |
4583
5d19a291bd9f
Refactor getting the WQKms into it's own method
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4187
diff
changeset
|
50 return getWQKms(art, context); |
5d19a291bd9f
Refactor getting the WQKms into it's own method
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4187
diff
changeset
|
51 } |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
52 |
4583
5d19a291bd9f
Refactor getting the WQKms into it's own method
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4187
diff
changeset
|
53 protected WQKms getWQKms(Artifact art, CallContext context) { |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5865
diff
changeset
|
54 if (!(art instanceof D4EArtifact)) { |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
55 log.warn("Invalid artifact type"); |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
56 return null; |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
57 } |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
58 |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5865
diff
changeset
|
59 D4EArtifact flys = (D4EArtifact)art; |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
60 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
61 String river = flys.getDataAsString("river"); |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
62 |
5865
73da40528cf2
River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
63 Gauge gauge = RiverUtils.getReferenceGauge(flys); |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
64 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
65 if (river == null || gauge == null) { |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
66 log.warn("Unknown river or gauge"); |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
67 return null; |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
68 } |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
69 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
70 String name = gauge.getName(); |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
71 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
72 DischargeTables dt = new DischargeTables(river, name); |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
73 |
6301
20a32dbdbb59
Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents:
5994
diff
changeset
|
74 Map<String, double [][]> map = dt.getValues(); |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
75 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
76 double [][] values = map.get(name); |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
77 if (values == null) { |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
78 return null; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
79 } |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
80 double [] kms = new double[values[0].length]; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
81 Arrays.fill(kms, gauge.getStation().doubleValue()); |
8326
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
82 |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
83 Object pnpObject = context.getContextValue(PNP); |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
84 if (!(pnpObject instanceof Number)) { |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
85 return new WQKms(kms, values[0], values[1], name, W.CENTIMETER_AT_GAUGE); |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
86 } |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
87 double pnp = Double.valueOf(pnpObject.toString()); |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
88 double[] ws = transformToM(values[1], pnp); |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
89 |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
90 return new WQKms(kms, values[0], ws, name); |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
91 } |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
92 |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
93 private double[] transformToM(double[] ws, double pnp) { |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
94 double[] retVals = new double[ws.length]; |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
95 for (int i = 0; i < ws.length; i++) { |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
96 retVals[i] = ws[i]/100 + pnp; |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
97 } |
10917ec29625
Inject current km and pnp into the context used to calculate W in cm at gauge.
Raimund Renkert <rrenkert@intevation.de>
parents:
8315
diff
changeset
|
98 return retVals; |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
99 } |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
100 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
101 @Override |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
102 public Facet deepCopy() { |
4032
a5e1ca620f15
Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents:
3986
diff
changeset
|
103 GaugeDischargeCurveFacet copy = new GaugeDischargeCurveFacet( |
4187
21f4e4b79121
Refactor GaugeDischargeCurveFacet to be able to set a facet name
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4032
diff
changeset
|
104 this.name, |
4032
a5e1ca620f15
Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents:
3986
diff
changeset
|
105 this.description); |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
106 copy.set(this); |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
107 return copy; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
108 } |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
109 } |