Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeCurveFacet.java @ 4992:ecc6fd57b630 dami
SCHEMA CHANGE: added column dem.srid
author | Tom Gottfried <tom.gottfried@intevation.de> |
---|---|
date | Thu, 14 Feb 2013 17:38:34 +0100 |
parents | 9745f37c0d52 |
children | dbe9b7d6b80b |
rev | line source |
---|---|
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
2 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
3 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
|
4 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
|
5 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
6 import de.intevation.artifacts.Artifact; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
7 import de.intevation.artifacts.CallContext; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
8 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.artifactdatabase.state.DefaultFacet; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.artifactdatabase.state.Facet; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
11 |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
12 import de.intevation.flys.artifacts.FLYSArtifact; |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
13 |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.flys.model.Gauge; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
15 |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
16 import de.intevation.flys.utils.FLYSUtils; |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
17 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
18 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
|
19 |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
20 /** |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
21 * 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
|
22 * |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
23 * @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
|
24 */ |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
25 public class GaugeDischargeCurveFacet |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
26 extends DefaultFacet |
4032
a5e1ca620f15
Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents:
3986
diff
changeset
|
27 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
|
28 { |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
29 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
|
30 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
|
31 |
4187
21f4e4b79121
Refactor GaugeDischargeCurveFacet to be able to set a facet name
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4032
diff
changeset
|
32 public GaugeDischargeCurveFacet(String name, String description) { |
21f4e4b79121
Refactor GaugeDischargeCurveFacet to be able to set a facet name
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4032
diff
changeset
|
33 super(0, 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
|
34 } |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
35 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
36 @Override |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 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
|
38 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
|
39 } |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
40 |
4583
5d19a291bd9f
Refactor getting the WQKms into it's own method
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4187
diff
changeset
|
41 protected WQKms getWQKms(Artifact art, CallContext context) { |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
42 if (!(art instanceof FLYSArtifact)) { |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
43 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
|
44 return null; |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
45 } |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
46 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
47 FLYSArtifact flys = (FLYSArtifact)art; |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
48 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
49 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
|
50 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
51 Gauge gauge = FLYSUtils.getReferenceGauge(flys); |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
52 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
53 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
|
54 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
|
55 return null; |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
56 } |
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 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
|
59 |
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
60 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
|
61 |
4584
9745f37c0d52
Use constant from DischargeTables for the scaling factor
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4583
diff
changeset
|
62 Map<String, double [][]> map = dt.getValues( |
9745f37c0d52
Use constant from DischargeTables for the scaling factor
Björn Ricks <bjoern.ricks@intevation.de>
parents:
4583
diff
changeset
|
63 DischargeTables.HISTORICAL_SCALE); |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
64 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
65 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
|
66 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
|
67 return null; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
68 } |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
69 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
|
70 Arrays.fill(kms, gauge.getStation().doubleValue()); |
3986
b7bdef1831ac
Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3985
diff
changeset
|
71 return new WQKms(kms, values[0], values[1], name); |
3936
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
72 } |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
73 |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
74 @Override |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
75 public Facet deepCopy() { |
4032
a5e1ca620f15
Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents:
3986
diff
changeset
|
76 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
|
77 this.name, |
4032
a5e1ca620f15
Add description and set correct name for GaugeDischargeCurveFacet
Björn Ricks <bjoern.ricks@intevation.de>
parents:
3986
diff
changeset
|
78 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
|
79 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
|
80 return copy; |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
81 } |
4e1b3b4ef132
Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
82 } |