Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadLSFacet.java @ 8103:54d35418141e
Add SedimentLoadLSFacet
TODO: correct handling of the facet name with regards to grain fraction and unit
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 20 Aug 2014 12:09:41 +0200 |
parents | |
children | 2707c3aa1aa7 |
comparison
equal
deleted
inserted
replaced
8102:28816abe7d5c | 8103:54d35418141e |
---|---|
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.resources.Resources; | |
22 | |
23 import org.dive4elements.river.artifacts.model.DataFacet; | |
24 import org.dive4elements.river.artifacts.model.FacetTypes; | |
25 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataFactory; | |
26 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData; | |
27 | |
28 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | |
29 | |
30 import org.dive4elements.river.model.SedimentLoadLS; | |
31 import org.dive4elements.river.model.SedimentLoadLSValue; | |
32 | |
33 import org.dive4elements.river.utils.RiverUtils; | |
34 | |
35 import java.util.ArrayList; | |
36 import java.util.Collections; | |
37 import java.util.List; | |
38 import java.util.Map; | |
39 import java.util.TreeSet; | |
40 import java.util.TreeMap; | |
41 | |
42 import org.apache.log4j.Logger; | |
43 | |
44 import org.w3c.dom.Document; | |
45 | |
46 | |
47 /** Facet to access sediment loads for longitudinal sections. | |
48 * This facet differs from the sedimentloadfacet in that it | |
49 * handles values from the sedimentload_ls table in the backend db. | |
50 * | |
51 * The sedimentload facet uses the internal sedimentload data model | |
52 * to work with measurement stations instead. | |
53 */ | |
54 public class SedimentLoadLSFacet | |
55 extends DataFacet | |
56 implements FacetTypes, StaticFacet | |
57 { | |
58 private static Logger logger = Logger.getLogger(SedimentLoadLSFacet.class); | |
59 | |
60 /* Aheinecke we probably need to get the kind and split this up here | |
61 * in some way */ | |
62 private static final String NAME = SEDIMENT_LOAD_TA_STATIC; | |
63 | |
64 public SedimentLoadLSFacet() { | |
65 } | |
66 | |
67 public SedimentLoadLSFacet(int idx, String name, String description, | |
68 ComputeType type, String stateId, String hash) { | |
69 super(idx, name, description, type, hash, stateId); | |
70 this.metaData.put("X", "chart.longitudinal.section.xaxis.label"); | |
71 this.metaData.put("Y", ""); | |
72 } | |
73 | |
74 @Override | |
75 public Object getData(Artifact artifact, CallContext context) { | |
76 logger.debug("get Data"); | |
77 D4EArtifact arti = (D4EArtifact) artifact; | |
78 | |
79 String idStr = arti.getDataAsString("load_id"); | |
80 int id = Integer.valueOf(idStr); | |
81 | |
82 SedimentLoadLS theLoad = SedimentLoadLS.getSedimentLoadById(id); | |
83 | |
84 if (theLoad == null) { | |
85 logger.error("No load found for id: " + idStr); | |
86 return null; | |
87 } | |
88 | |
89 /* Now lets get what we want */ | |
90 TDoubleArrayList xPos = new TDoubleArrayList(); | |
91 TDoubleArrayList yPos = new TDoubleArrayList(); | |
92 | |
93 for (SedimentLoadLSValue val: theLoad.getSedimentLoadLSValues()) { | |
94 double value = val.getValue(); | |
95 if (Double.isNaN(value)) { | |
96 continue; | |
97 } | |
98 xPos.add(val.getStation()); | |
99 yPos.add(value); | |
100 } | |
101 | |
102 return new double[][] {xPos.toNativeArray(), yPos.toNativeArray()}; | |
103 } | |
104 | |
105 @Override | |
106 public void setup(Artifact artifact, Document data, CallMeta callMeta) { | |
107 logger.debug("setup"); | |
108 String code = D4EArtifact.getDatacageIDValue(data); | |
109 String[] split = code.split(";"); | |
110 String idStr = split[0]; | |
111 String desc = ""; | |
112 if (split.length >= 2) { | |
113 desc = split[1]; | |
114 } | |
115 | |
116 int id = Integer.valueOf(idStr); | |
117 SedimentLoadLS theLoad = SedimentLoadLS.getSedimentLoadById(id); | |
118 if (theLoad == null) { | |
119 logger.error("No load found for id: " + idStr); | |
120 return; | |
121 } | |
122 logger.debug("Setting up SedimentLoadLSFacet for id: " + id); | |
123 logger.debug("GrainFraction: " + theLoad.getGrainFraction().getName()); | |
124 logger.debug("Kind: " + theLoad.getKind()); | |
125 logger.debug("Unit: " + theLoad.getUnit().getName()); | |
126 | |
127 /* TODO: Name is important. We have to add the Grain Fraction and the | |
128 * unit in here so that theming is done correctly and unit is correct.*/ | |
129 name = NAME; | |
130 description = Resources.getMsg( | |
131 callMeta, | |
132 "facet.sedimentload", | |
133 "Sedimentload", | |
134 new Object[] { desc }); | |
135 ((D4EArtifact)artifact).addStringData("load_id", idStr); | |
136 } | |
137 | |
138 | |
139 /** Copy deeply. */ | |
140 @Override | |
141 public Facet deepCopy() { | |
142 SedimentLoadLSFacet copy = new SedimentLoadLSFacet(); | |
143 copy.set(this); | |
144 copy.type = type; | |
145 copy.hash = hash; | |
146 copy.stateId = stateId; | |
147 return copy; | |
148 } | |
149 } | |
150 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |