Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java @ 8098:09725b65955a
Add new and simplyfied SedimentLoadFacet
The SedimentLoadFacet is intended to work with the Measurement stations.
It uses the same mechanismn to access the Mesurement station values
as the calculation does.
SedimentLoadLS values need a different facet that will come soon.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Fri, 15 Aug 2014 18:27:19 +0200 |
parents | |
children | 4bcc0c8425d2 |
comparison
equal
deleted
inserted
replaced
8097:6f3cf934ae99 | 8098:09725b65955a |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts.model.minfo; | |
10 | |
11 import gnu.trove.TDoubleArrayList; | |
12 | |
13 import org.dive4elements.artifactdatabase.state.Facet; | |
14 import org.dive4elements.artifactdatabase.state.StaticFacet; | |
15 | |
16 import org.dive4elements.artifacts.Artifact; | |
17 import org.dive4elements.artifacts.CallContext; | |
18 import org.dive4elements.artifacts.CallMeta; | |
19 | |
20 import org.dive4elements.river.artifacts.D4EArtifact; | |
21 import org.dive4elements.river.artifacts.access.RiverAccess; | |
22 import org.dive4elements.river.artifacts.resources.Resources; | |
23 | |
24 import org.dive4elements.river.artifacts.model.DataFacet; | |
25 import org.dive4elements.river.artifacts.model.FacetTypes; | |
26 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataFactory; | |
27 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData; | |
28 | |
29 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | |
30 | |
31 import org.dive4elements.river.utils.RiverUtils; | |
32 | |
33 import java.util.ArrayList; | |
34 import java.util.Collections; | |
35 import java.util.List; | |
36 import java.util.Map; | |
37 import java.util.TreeSet; | |
38 import java.util.TreeMap; | |
39 | |
40 import org.apache.log4j.Logger; | |
41 | |
42 import org.w3c.dom.Document; | |
43 | |
44 | |
45 /** Facet to access various sediment loads. */ | |
46 public class SedimentLoadFacet | |
47 extends DataFacet | |
48 implements FacetTypes, StaticFacet | |
49 { | |
50 private static Logger logger = Logger.getLogger(SedimentLoadFacet.class); | |
51 | |
52 /* Aheinecke we probably need to get the kind and split this up here | |
53 * in some way */ | |
54 private static final String NAME = SEDIMENT_LOAD_TA_STATIC; | |
55 | |
56 public SedimentLoadFacet() { | |
57 } | |
58 | |
59 public SedimentLoadFacet(int idx, String name, String description, | |
60 ComputeType type, String stateId, String hash) { | |
61 super(idx, name, description, type, hash, stateId); | |
62 this.metaData.put("X", "chart.longitudinal.section.xaxis.label"); | |
63 this.metaData.put("Y", ""); | |
64 } | |
65 | |
66 @Override | |
67 public Object getData(Artifact artifact, CallContext context) { | |
68 logger.debug("get Data"); | |
69 D4EArtifact arti = (D4EArtifact) artifact; | |
70 | |
71 RiverAccess access = new RiverAccess(arti); | |
72 String idStr = arti.getDataAsString("load_id"); | |
73 int id = Integer.valueOf(idStr); | |
74 | |
75 /* Get all the data from the river. This will be nicely cached. */ | |
76 SedimentLoadData allLoadData = SedimentLoadDataFactory.INSTANCE.getSedimentLoadData( | |
77 access.getRiverName()); | |
78 | |
79 /* Now lets get what we want */ | |
80 TDoubleArrayList xPos = new TDoubleArrayList(); | |
81 TDoubleArrayList yPos = new TDoubleArrayList(); | |
82 | |
83 for (SedimentLoadData.Station sta: allLoadData.getStations()) { | |
84 double value = sta.findValueByLoadId(id); | |
85 if (Double.isNaN(value)) { | |
86 continue; | |
87 } | |
88 xPos.add(sta.getStation()); | |
89 yPos.add(value); | |
90 } | |
91 | |
92 return new double[][] {xPos.toNativeArray(), yPos.toNativeArray()}; | |
93 } | |
94 | |
95 @Override | |
96 public void setup(Artifact artifact, Document data, CallMeta callMeta) { | |
97 logger.debug("setup"); | |
98 String code = D4EArtifact.getDatacageIDValue(data); | |
99 String[] split = code.split(";"); | |
100 String idStr = split[0]; | |
101 String desc = ""; | |
102 if (split.length >= 2) { | |
103 desc = split[1]; | |
104 } | |
105 | |
106 logger.debug("Create for id: " + idStr + " with desc: " + desc); | |
107 | |
108 name = NAME; | |
109 description = Resources.getMsg( | |
110 callMeta, | |
111 "facet.sedimentload", | |
112 "Sedimentload", | |
113 new Object[] { desc }); | |
114 ((D4EArtifact)artifact).addStringData("load_id", idStr); | |
115 } | |
116 | |
117 | |
118 /** Copy deeply. */ | |
119 @Override | |
120 public Facet deepCopy() { | |
121 SedimentLoadFacet copy = new SedimentLoadFacet(); | |
122 copy.set(this); | |
123 copy.type = type; | |
124 copy.hash = hash; | |
125 copy.stateId = stateId; | |
126 return copy; | |
127 } | |
128 } | |
129 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |