Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelFetcher.java Wed Mar 28 14:35:01 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelFetcher.java Wed Mar 28 17:03:11 2018 +0200 @@ -9,6 +9,8 @@ */ package org.dive4elements.river.artifacts.states; +import java.util.Calendar; +import java.util.Date; import java.util.List; import org.apache.log4j.Logger; @@ -24,9 +26,12 @@ import org.dive4elements.river.artifacts.model.Segment; import org.dive4elements.river.artifacts.model.WKms; import org.dive4elements.river.artifacts.model.WQKms; +import org.dive4elements.river.artifacts.model.WstColumnFactory; import org.dive4elements.river.artifacts.model.fixings.FixRealizingCalculationExtended; import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult; import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; +import org.dive4elements.river.model.TimeInterval; +import org.dive4elements.river.model.WstColumn; import org.dive4elements.river.utils.RiverUtils; /** @@ -82,8 +87,9 @@ return null; } - // REMARK/TODO: instead of several helper methods here this would be a good place for abstraction, in order to push - // this logic back to the corresponding artifacts + // REMARK: instead of several helper methods here this would be a good place for abstraction, in order to push + // this logic back to the corresponding artifacts. However this will most certainly break existing + // artifact-serialization private WaterlevelData fetchStaticWKmsArtifactWaterlevel(final StaticWKmsArtifact staticWKms, final int idx, final double from, final double to) { @@ -94,8 +100,7 @@ if (wkms != null) { - // FIXME: woher bekommen?: eventuell zusammenhang mit tabelle 'time_intervals' - final int year = -1; + final int year = fetchStaticWKmsYear(staticWKms); return new WaterlevelData(wkms, year); } @@ -112,8 +117,7 @@ if (wkms != null) { - // FIXME: woher bekommen?: eventuell zusammenhang mit tabelle 'time_intervals' - final int year = -1; + final int year = fetchStaticWKmsYear(staticWKms); return new WaterlevelData(wkms, year); } @@ -164,4 +168,32 @@ return new WaterlevelData(frR.getWQKms()[idx], year, showAllGauges).filterByRange(from, to); } + + /** + * Fetches the 'year' for a staticXXX-artifact. + * REMARK: actually this should happen inside the staticWKms artifact and eventually in the WKmsFactory, but the code + * there is already awful and it will also break the old artifact-serialization... + */ + private int fetchStaticWKmsYear(final D4EArtifact staticWKms) { + + final int colPos = Integer.parseInt(staticWKms.getDataAsString("col_pos")); + final int wstId = Integer.parseInt(staticWKms.getDataAsString("wst_id")); + + final WstColumn wstColumn = WstColumnFactory.getWstColumn(wstId, colPos); + final TimeInterval timeInterval = wstColumn.getTimeInterval(); + if (timeInterval == null) + return -1; + + final Date startTime = timeInterval.getStartTime(); + if (startTime == null) + return -1; + + // REMARK: the times are stored without timezone in the DB, so it is unclear what hibernate makes of it. + // We simply use the default timezone here and hope we never get problems... + // 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 + // no change anything regarding the year. + final Calendar cal = Calendar.getInstance(); + cal.setTime(startTime); + return cal.get(Calendar.YEAR); + } } \ No newline at end of file