Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/predefinedtkh/PredefinedTkhFacet.java @ 9016:6e5ff436febe
Added datacage select and chart display for TKH series loaded from database
author | mschaefer |
---|---|
date | Mon, 23 Apr 2018 15:18:48 +0200 |
parents | |
children | 384eee4b4135 |
comparison
equal
deleted
inserted
replaced
9015:baef34f54ee2 | 9016:6e5ff436febe |
---|---|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 | |
11 package org.dive4elements.river.artifacts.sinfo.predefinedtkh; | |
12 | |
13 import java.util.ArrayList; | |
14 import java.util.Collection; | |
15 import java.util.List; | |
16 | |
17 import org.dive4elements.artifacts.Artifact; | |
18 import org.dive4elements.artifacts.CallContext; | |
19 import org.dive4elements.river.artifacts.D4EArtifact; | |
20 import org.dive4elements.river.artifacts.common.GeneralResultType; | |
21 import org.dive4elements.river.artifacts.common.ResultRow; | |
22 import org.dive4elements.river.artifacts.model.BlackboardDataFacet; | |
23 import org.dive4elements.river.artifacts.model.Calculation; | |
24 import org.dive4elements.river.artifacts.model.FacetTypes; | |
25 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; | |
26 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.SoilKind; | |
27 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.SoilKindKmValueFinder; | |
28 import org.dive4elements.river.model.sinfo.TkhColumn; | |
29 import org.dive4elements.river.model.sinfo.TkhValue; | |
30 | |
31 /** | |
32 * Facet for a tkh value series loaded from the database | |
33 * | |
34 * @author Matthias Schäfer | |
35 */ | |
36 public class PredefinedTkhFacet extends BlackboardDataFacet implements FacetTypes { | |
37 | |
38 private static final long serialVersionUID = 5508868967789155306L; | |
39 | |
40 public PredefinedTkhFacet(final String name, final String description) { | |
41 super(0, name, description); | |
42 | |
43 this.metaData.put("X", "chart.longitudinal.section.xaxis.label"); | |
44 this.metaData.put("Y", "chart.tkh.section.yaxis.label"); | |
45 } | |
46 | |
47 /** | |
48 * Returns the data this facet requires. | |
49 * | |
50 * @param artifact | |
51 * the owner artifact. | |
52 * @param context | |
53 * the CallContext (ignored). | |
54 * | |
55 * @return | |
56 * the data as PredefinedTkhQueryCalculationResult | |
57 */ | |
58 @Override | |
59 public Object getData(final Artifact artifact, final CallContext context) { | |
60 | |
61 final PredefinedTkhColumnAccess access = new PredefinedTkhColumnAccess((D4EArtifact) artifact); | |
62 final TkhColumn series = TkhColumn.getTkhColumnById(access.getColumnId()); | |
63 final List<TkhValue> tkhValues = TkhValue.getTkhValues(series, access.getFrom(true), access.getTo(true)); | |
64 final Calculation problems = new Calculation(); | |
65 final SoilKindKmValueFinder soilKindFinder = SoilKindKmValueFinder.loadValues(problems, access.getRiver(), access.getRange()); | |
66 | |
67 final Collection<ResultRow> rows = new ArrayList<>(); | |
68 SoilKind bedMobility = SoilKind.mobil; | |
69 for (final TkhValue tkhValue : tkhValues) { | |
70 final ResultRow row = ResultRow.create(); | |
71 row.putValue(GeneralResultType.station, tkhValue.getStation().doubleValue()); | |
72 if (soilKindFinder != null) | |
73 bedMobility = soilKindFinder.findSoilKind(tkhValue.getStation().doubleValue()); | |
74 row.putValue(SInfoResultType.soilkind, bedMobility); | |
75 final double tkh = tkhValue(tkhValue.getTkheight()) * 100; | |
76 row.putValue(SInfoResultType.tkh, tkh); | |
77 switch (bedMobility) { | |
78 case starr: | |
79 row.putValue(SInfoResultType.tkhup, tkh); | |
80 row.putValue(SInfoResultType.tkhdown, 0.0); | |
81 break; | |
82 case mobil: | |
83 default: | |
84 row.putValue(SInfoResultType.tkhup, tkh / 2); | |
85 row.putValue(SInfoResultType.tkhdown, -tkh / 2); | |
86 break; | |
87 } | |
88 rows.add(row); | |
89 } | |
90 return new PredefinedTkhQueryCalculationResult(series.getName(), rows); | |
91 } | |
92 | |
93 private double tkhValue(final Double value) { | |
94 if (value != null) | |
95 return value.doubleValue(); | |
96 else | |
97 return Double.NaN; | |
98 } | |
99 | |
100 /** | |
101 * Create a deep copy of this Facet. | |
102 * | |
103 * @return a deep copy. | |
104 */ | |
105 @Override | |
106 public PredefinedTkhFacet deepCopy() { | |
107 final PredefinedTkhFacet copy = new PredefinedTkhFacet(this.name, this.description); | |
108 copy.set(this); | |
109 return copy; | |
110 } | |
111 } |