annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/GaugeDischargeCurveFacet.java @ 4030:4bc58d6ee9db

Add template for the gauge discharge curve description
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 04 Oct 2012 14:12:03 +0200
parents b7bdef1831ac
children a5e1ca620f15
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
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
27 {
3986
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
28 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
29 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
30
3986
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
31 public GaugeDischargeCurveFacet() {
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
32 super(0, "facet.gauge.discharge_curve", "facet.gauge.discharge_curve");
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
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
35 @Override
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
36 public Object getData(Artifact art, CallContext context) {
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 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
39 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
40 return null;
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
41 }
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
42
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
43 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
44
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
45 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
46
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
47 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
48
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
49 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
50 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
51 return null;
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
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
54 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
55
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
56 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
57
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
58 Map<String, double [][]> map = dt.getValues(100d);
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
59
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
60 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
61 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
62 return null;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
63 }
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
64 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
65 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
66 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
67 }
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 @Override
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
70 public Facet deepCopy() {
3986
b7bdef1831ac Removed heavy weight data from the gauge discharge curve facet.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3985
diff changeset
71 GaugeDischargeCurveFacet copy = new GaugeDischargeCurveFacet();
3936
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
72 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
73 return copy;
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
74 }
4e1b3b4ef132 Add new Artifacts and State for displaying discharge curves at a gauge
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
75 }

http://dive4elements.wald.intevation.org