Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesCrossSectionProcessor.java @ 9514:ee6508687e3f
Added default vegetation zones tzo iota result map.
author | gernotbelger |
---|---|
date | Mon, 01 Oct 2018 13:03:42 +0200 |
parents | 6146358c4842 |
children | 7c8d62867876 |
comparison
equal
deleted
inserted
replaced
9513:1722727803f7 | 9514:ee6508687e3f |
---|---|
16 | 16 |
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | 17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
18 import org.dive4elements.artifactdatabase.state.Facet; | 18 import org.dive4elements.artifactdatabase.state.Facet; |
19 import org.dive4elements.artifacts.Artifact; | 19 import org.dive4elements.artifacts.Artifact; |
20 import org.dive4elements.artifacts.CallContext; | 20 import org.dive4elements.artifacts.CallContext; |
21 import org.dive4elements.artifacts.CallMeta; | |
21 import org.dive4elements.artifacts.DataProvider; | 22 import org.dive4elements.artifacts.DataProvider; |
22 import org.dive4elements.river.artifacts.D4EArtifact; | 23 import org.dive4elements.river.artifacts.D4EArtifact; |
23 import org.dive4elements.river.artifacts.common.AbstractProcessor; | 24 import org.dive4elements.river.artifacts.access.RiverAccess; |
24 import org.dive4elements.river.artifacts.model.CrossSectionFacetUtils; | 25 import org.dive4elements.river.artifacts.model.CrossSectionFacetUtils; |
25 import org.dive4elements.river.artifacts.model.river.MainWstValuesCalculator; | 26 import org.dive4elements.river.artifacts.model.river.MainWstValuesCalculator; |
27 import org.dive4elements.river.artifacts.resources.Resources; | |
26 import org.dive4elements.river.exports.CrossSectionGenerator; | 28 import org.dive4elements.river.exports.CrossSectionGenerator; |
27 import org.dive4elements.river.exports.DiagramGenerator; | |
28 import org.dive4elements.river.jfree.StripedAreaDataset; | 29 import org.dive4elements.river.jfree.StripedAreaDataset; |
29 import org.dive4elements.river.jfree.StripedAreaDataset.Stripe; | 30 import org.dive4elements.river.jfree.StripedAreaDataset.Stripe; |
30 import org.dive4elements.river.model.FastCrossSectionLine; | 31 import org.dive4elements.river.model.FastCrossSectionLine; |
31 import org.dive4elements.river.model.River; | 32 import org.dive4elements.river.model.River; |
32 import org.dive4elements.river.themes.ThemeDocument; | 33 import org.dive4elements.river.themes.ThemeDocument; |
33 | 34 |
34 /** | 35 /** |
35 * @author Domenico Nardi Tironi | 36 * @author Domenico Nardi Tironi |
36 * | 37 * |
37 */ | 38 */ |
38 public class VegetationZonesCrossSectionProcessor extends AbstractProcessor { | 39 public final class VegetationZonesCrossSectionProcessor { |
39 | 40 |
40 private static final String MAIN_VALUE_MQ = "mq"; | 41 private static final String MAIN_VALUE_MQ = "mq"; |
41 | 42 |
42 public static final String FACET_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_vegetation_zones_cross_section"; | 43 private static final String FACET_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_vegetation_zones_cross_section"; |
43 | 44 |
45 private static final String FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION = "uinfo_facet_default_vegetation_zones_cross_section"; | |
46 | |
47 private static final String DEFAULT_VEGZONES_DESCRIPTION = "uinfo_facet_vegetation_default_zones_cross_section.description"; | |
44 | 48 |
45 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); | 49 private static final Set<String> HANDLED_FACET_TYPES = new HashSet<>(); |
46 | 50 |
47 static { | 51 static { |
48 HANDLED_FACET_TYPES.add(FACET_VEGETATION_ZONES_CROSS_SECTION); | 52 HANDLED_FACET_TYPES.add(FACET_VEGETATION_ZONES_CROSS_SECTION); |
53 HANDLED_FACET_TYPES.add(FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION); | |
54 } | |
55 | |
56 public static final boolean canHandle(final String facettype) { | |
57 return HANDLED_FACET_TYPES.contains(facettype); | |
49 } | 58 } |
50 | 59 |
51 public static Facet createVegetationZonesCrossSectionFacet(final String description) { | 60 public static Facet createVegetationZonesCrossSectionFacet(final String description) { |
52 | 61 |
53 return new VegetationZonesCrossSectionFacet(FACET_VEGETATION_ZONES_CROSS_SECTION, description); | 62 return new VegetationZonesCrossSectionFacet(FACET_VEGETATION_ZONES_CROSS_SECTION, description); |
63 } | |
64 | |
65 public static Facet createDefaultVegetationZonesCrossSectionFacet(final CallMeta callMeta) { | |
66 | |
67 final String description = Resources.getMsg(callMeta, DEFAULT_VEGZONES_DESCRIPTION); | |
68 | |
69 return new VegetationZonesCrossSectionFacet(FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION, description); | |
54 } | 70 } |
55 | 71 |
56 public static void generateSeries(final CrossSectionGenerator generator, final ArtifactAndFacet bundle, final CallContext context, | 72 public static void generateSeries(final CrossSectionGenerator generator, final ArtifactAndFacet bundle, final CallContext context, |
57 final ThemeDocument theme, final boolean visible) { | 73 final ThemeDocument theme, final boolean visible) { |
58 | 74 |
60 final FastCrossSectionLine crossSection = CrossSectionFacetUtils.getCrossSection(provider, context); | 76 final FastCrossSectionLine crossSection = CrossSectionFacetUtils.getCrossSection(provider, context); |
61 if (crossSection == null) | 77 if (crossSection == null) |
62 return; | 78 return; |
63 final double currentStation = crossSection.getKm(); | 79 final double currentStation = crossSection.getKm(); |
64 | 80 |
81 final RiverAccess rAccess = new RiverAccess((D4EArtifact) bundle.getArtifact()); | |
82 final River river = rAccess.getRiver(); | |
83 | |
84 final List<VegetationZoneServerClientXChange> zones = findZonesData(bundle, context, river); | |
85 | |
86 final StripedAreaDataset dataset = new StripedAreaDataset(theme); | |
87 | |
88 for (final VegetationZoneServerClientXChange zone : zones) { | |
89 | |
90 final double lower = uefdToHeight(context, river, currentStation, zone.getLowerFromTo()); | |
91 final double upper = uefdToHeight(context, river, currentStation, zone.getUpperFromTo()); | |
92 | |
93 final Color color = Color.decode(zone.getHexColor()); | |
94 final String label = String.format("%s (%dd-%dd)", zone.getZoneName(), zone.getLowerFromTo(), zone.getUpperFromTo()); | |
95 dataset.addStripe(new Stripe(label, color, lower, upper)); | |
96 } | |
97 | |
98 generator.addAxisDataset(dataset, 0, visible); | |
99 return; | |
100 } | |
101 | |
102 private static List<VegetationZoneServerClientXChange> findZonesData(final ArtifactAndFacet bundle, final CallContext context, final River river) { | |
103 | |
65 if (bundle.getFacetName().equals(FACET_VEGETATION_ZONES_CROSS_SECTION)) { | 104 if (bundle.getFacetName().equals(FACET_VEGETATION_ZONES_CROSS_SECTION)) { |
66 | |
67 final StripedAreaDataset dataset = new StripedAreaDataset(theme); | |
68 | 105 |
69 final Artifact artifact = bundle.getArtifact(); | 106 final Artifact artifact = bundle.getArtifact(); |
70 final VegetationzonesAccess vAccess = new VegetationzonesAccess((D4EArtifact) artifact); | 107 final VegetationzonesAccess vAccess = new VegetationzonesAccess((D4EArtifact) artifact); |
71 final River river = vAccess.getRiver(); | 108 return VegetationZoneServerClientXChange.parse(vAccess.getVegZones()); |
72 final List<VegetationZoneServerClientXChange> zones = VegetationZoneServerClientXChange.parse(vAccess.getVegZones()); | 109 } |
73 | 110 |
74 for (final VegetationZoneServerClientXChange zone : zones) { | 111 if (bundle.getFacetName().equals(FACET_DEFAULT_VEGETATION_ZONES_CROSS_SECTION)) { |
75 | 112 |
76 final double lower = uefdToHeight(context, river, currentStation, zone.getLowerFromTo()); | 113 return VegetationZoneServerClientXChange.getStandardList(river, context); |
77 final double upper = uefdToHeight(context, river, currentStation, zone.getUpperFromTo()); | |
78 | |
79 final Color color = Color.decode(zone.getHexColor()); | |
80 final String label = String.format("%s (%dd-%dd)", zone.getZoneName(), zone.getLowerFromTo(), zone.getUpperFromTo()); | |
81 dataset.addStripe(new Stripe(label, color, lower, upper)); | |
82 } | |
83 | |
84 generator.addAxisDataset(dataset, 0, visible); | |
85 return; | |
86 } | 114 } |
87 | 115 |
88 throw new UnsupportedOperationException(); | 116 throw new UnsupportedOperationException(); |
89 } | 117 } |
90 | 118 |
91 private static double uefdToHeight(final CallContext context, final River river, final double station, final int uefd) { | 119 private static double uefdToHeight(final CallContext context, final River river, final double station, final int uefd) { |
92 | 120 |
121 // FIXME: cache me | |
93 final MainWstValuesCalculator mainWstValues = MainWstValuesCalculator.forRiver(context, river, null, MAIN_VALUE_MQ); | 122 final MainWstValuesCalculator mainWstValues = MainWstValuesCalculator.forRiver(context, river, null, MAIN_VALUE_MQ); |
94 | 123 |
95 final double mw = mainWstValues.interpolateW(station, MAIN_VALUE_MQ); | 124 final double mw = mainWstValues.interpolateW(station, MAIN_VALUE_MQ); |
96 | 125 |
97 // Üfd = -70,559 ∗ ln((DGM - MW) + 0,5) + 80,711 | 126 // Üfd = -70,559 ∗ ln((DGM - MW) + 0,5) + 80,711 |
99 final double f2 = 88.711; | 128 final double f2 = 88.711; |
100 | 129 |
101 final double dgm = Math.exp((uefd - f2) / f1) + mw - 0.5; | 130 final double dgm = Math.exp((uefd - f2) / f1) + mw - 0.5; |
102 return dgm; | 131 return dgm; |
103 } | 132 } |
104 | |
105 public VegetationZonesCrossSectionProcessor() { | |
106 super(CrossSectionGenerator.I18N_YAXIS_LABEL, HANDLED_FACET_TYPES); | |
107 | |
108 throw new UnsupportedOperationException(); | |
109 } | |
110 | |
111 @Override | |
112 protected String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { | |
113 throw new UnsupportedOperationException(); | |
114 } | |
115 | |
116 } | 133 } |