Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelFetcher.java @ 8962:708f210ff242
Fetching year informations for waterlevels used in sinfo
author | gernotbelger |
---|---|
date | Wed, 28 Mar 2018 17:03:11 +0200 |
parents | 86650594f051 |
children | 45f1ad66560e |
comparison
equal
deleted
inserted
replaced
8961:8a1c6e2ad48b | 8962:708f210ff242 |
---|---|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
8 * documentation coming with Dive4Elements River for details. | 8 * documentation coming with Dive4Elements River for details. |
9 */ | 9 */ |
10 package org.dive4elements.river.artifacts.states; | 10 package org.dive4elements.river.artifacts.states; |
11 | 11 |
12 import java.util.Calendar; | |
13 import java.util.Date; | |
12 import java.util.List; | 14 import java.util.List; |
13 | 15 |
14 import org.apache.log4j.Logger; | 16 import org.apache.log4j.Logger; |
15 import org.dive4elements.artifacts.CallContext; | 17 import org.dive4elements.artifacts.CallContext; |
16 import org.dive4elements.river.artifacts.D4EArtifact; | 18 import org.dive4elements.river.artifacts.D4EArtifact; |
22 import org.dive4elements.river.artifacts.model.Calculation; | 24 import org.dive4elements.river.artifacts.model.Calculation; |
23 import org.dive4elements.river.artifacts.model.CalculationResult; | 25 import org.dive4elements.river.artifacts.model.CalculationResult; |
24 import org.dive4elements.river.artifacts.model.Segment; | 26 import org.dive4elements.river.artifacts.model.Segment; |
25 import org.dive4elements.river.artifacts.model.WKms; | 27 import org.dive4elements.river.artifacts.model.WKms; |
26 import org.dive4elements.river.artifacts.model.WQKms; | 28 import org.dive4elements.river.artifacts.model.WQKms; |
29 import org.dive4elements.river.artifacts.model.WstColumnFactory; | |
27 import org.dive4elements.river.artifacts.model.fixings.FixRealizingCalculationExtended; | 30 import org.dive4elements.river.artifacts.model.fixings.FixRealizingCalculationExtended; |
28 import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult; | 31 import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult; |
29 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | 32 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; |
33 import org.dive4elements.river.model.TimeInterval; | |
34 import org.dive4elements.river.model.WstColumn; | |
30 import org.dive4elements.river.utils.RiverUtils; | 35 import org.dive4elements.river.utils.RiverUtils; |
31 | 36 |
32 /** | 37 /** |
33 * Helper class that accesses existing waterlevels (in most cases) from the data-cage. | 38 * Helper class that accesses existing waterlevels (in most cases) from the data-cage. |
34 * This is mainly a refaktoring of org.dive4elements.river.artifacts.states.WDifferencesState.getWKms(String, | 39 * This is mainly a refaktoring of org.dive4elements.river.artifacts.states.WDifferencesState.getWKms(String, |
80 | 85 |
81 log.warn(String.format("Get Waterlevel from %s not implemented! )", d4eArtifact.getClass().getSimpleName())); | 86 log.warn(String.format("Get Waterlevel from %s not implemented! )", d4eArtifact.getClass().getSimpleName())); |
82 return null; | 87 return null; |
83 } | 88 } |
84 | 89 |
85 // REMARK/TODO: instead of several helper methods here this would be a good place for abstraction, in order to push | 90 // REMARK: instead of several helper methods here this would be a good place for abstraction, in order to push |
86 // this logic back to the corresponding artifacts | 91 // this logic back to the corresponding artifacts. However this will most certainly break existing |
92 // artifact-serialization | |
87 | 93 |
88 private WaterlevelData fetchStaticWKmsArtifactWaterlevel(final StaticWKmsArtifact staticWKms, final int idx, | 94 private WaterlevelData fetchStaticWKmsArtifactWaterlevel(final StaticWKmsArtifact staticWKms, final int idx, |
89 final double from, final double to) { | 95 final double from, final double to) { |
90 | 96 |
91 log.debug("WDifferencesState obtain data from StaticWKms"); | 97 log.debug("WDifferencesState obtain data from StaticWKms"); |
92 | 98 |
93 final WKms wkms = staticWKms.getWKms(idx, from, to); | 99 final WKms wkms = staticWKms.getWKms(idx, from, to); |
94 | 100 |
95 if (wkms != null) | 101 if (wkms != null) |
96 { | 102 { |
97 // FIXME: woher bekommen?: eventuell zusammenhang mit tabelle 'time_intervals' | 103 final int year = fetchStaticWKmsYear(staticWKms); |
98 final int year = -1; | |
99 return new WaterlevelData(wkms, year); | 104 return new WaterlevelData(wkms, year); |
100 } | 105 } |
101 | 106 |
102 log.error("No WKms from Static artifact for this range."); | 107 log.error("No WKms from Static artifact for this range."); |
103 return null; | 108 return null; |
110 | 115 |
111 final WQKms wkms = staticWKms.getWQKms(from, to); | 116 final WQKms wkms = staticWKms.getWQKms(from, to); |
112 | 117 |
113 if (wkms != null) | 118 if (wkms != null) |
114 { | 119 { |
115 // FIXME: woher bekommen?: eventuell zusammenhang mit tabelle 'time_intervals' | 120 final int year = fetchStaticWKmsYear(staticWKms); |
116 final int year = -1; | |
117 return new WaterlevelData(wkms, year); | 121 return new WaterlevelData(wkms, year); |
118 } | 122 } |
119 | 123 |
120 log.error("No WKms from Static artifact for this range."); | 124 log.error("No WKms from Static artifact for this range."); |
121 return null; | 125 return null; |
162 // REMARK: same logic as in WaterlevelExporter | 166 // REMARK: same logic as in WaterlevelExporter |
163 final boolean showAllGauges = isFixRealize; | 167 final boolean showAllGauges = isFixRealize; |
164 | 168 |
165 return new WaterlevelData(frR.getWQKms()[idx], year, showAllGauges).filterByRange(from, to); | 169 return new WaterlevelData(frR.getWQKms()[idx], year, showAllGauges).filterByRange(from, to); |
166 } | 170 } |
171 | |
172 /** | |
173 * Fetches the 'year' for a staticXXX-artifact. | |
174 * REMARK: actually this should happen inside the staticWKms artifact and eventually in the WKmsFactory, but the code | |
175 * there is already awful and it will also break the old artifact-serialization... | |
176 */ | |
177 private int fetchStaticWKmsYear(final D4EArtifact staticWKms) { | |
178 | |
179 final int colPos = Integer.parseInt(staticWKms.getDataAsString("col_pos")); | |
180 final int wstId = Integer.parseInt(staticWKms.getDataAsString("wst_id")); | |
181 | |
182 final WstColumn wstColumn = WstColumnFactory.getWstColumn(wstId, colPos); | |
183 final TimeInterval timeInterval = wstColumn.getTimeInterval(); | |
184 if (timeInterval == null) | |
185 return -1; | |
186 | |
187 final Date startTime = timeInterval.getStartTime(); | |
188 if (startTime == null) | |
189 return -1; | |
190 | |
191 // REMARK: the times are stored without timezone in the DB, so it is unclear what hibernate makes of it. | |
192 // We simply use the default timezone here and hope we never get problems... | |
193 // Actually we always have 12:00 as time in the db data, so a smal timeshift due to winter/sommertime or UTC/GMT+1 will | |
194 // no change anything regarding the year. | |
195 final Calendar cal = Calendar.getInstance(); | |
196 cal.setTime(startTime); | |
197 return cal.get(Calendar.YEAR); | |
198 } | |
167 } | 199 } |