From 263e8c329b9af84caa86b3205646f6a8efd1000e Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@bioforsk.no> Date: Fri, 3 Jun 2016 13:40:39 +0200 Subject: [PATCH] Weather data handling for negative prognosis model --- .../NegativePrognosisModelPreprocessor.java | 13 ++++++++----- .../vips/util/weather/WeatherDataSourceUtil.java | 1 + .../util/weather/YrWeatherForecastProvider.java | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NegativePrognosisModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NegativePrognosisModelPreprocessor.java index d9399a86..60402e5b 100644 --- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NegativePrognosisModelPreprocessor.java +++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/NegativePrognosisModelPreprocessor.java @@ -30,6 +30,8 @@ import no.nibio.vips.logic.entity.PointOfInterestWeatherStation; import no.nibio.vips.logic.scheduling.model.ModelRunPreprocessor; import no.nibio.vips.logic.scheduling.model.PreprocessorException; import no.nibio.vips.util.WeatherElements; +import no.nibio.vips.util.WeatherObservationListException; +import no.nibio.vips.util.WeatherUtil; import no.nibio.vips.util.weather.WeatherDataSourceException; import no.nibio.vips.util.weather.WeatherDataSourceUtil; @@ -45,13 +47,14 @@ public class NegativePrognosisModelPreprocessor extends ModelRunPreprocessor{ TimeZone timeZone = TimeZone.getTimeZone(weatherStation.getTimeZone()); WeatherDataSourceUtil wdsUtil = new WeatherDataSourceUtil(); + WeatherUtil wUtil = new WeatherUtil(); List<WeatherObservation> observations; try { observations = wdsUtil.getWeatherObservations( - weatherStation.getDataFetchUri(), + weatherStation, WeatherObservation.LOG_INTERVAL_ID_1H, new String[]{ WeatherElements.TEMPERATURE_MEAN, @@ -59,12 +62,12 @@ public class NegativePrognosisModelPreprocessor extends ModelRunPreprocessor{ WeatherElements.RELATIVE_HUMIDITY_MEAN }, configuration.getDateStartInTimeZone(), - configuration.getDateEndInTimeZone(), - timeZone); - } catch (WeatherDataSourceException ex) { + configuration.getDateEndInTimeZone()); + observations = wUtil.checkForAndFixHourlyTimeSeriesHolesMultiParameter(observations); + } catch (WeatherDataSourceException | WeatherObservationListException ex) { throw new PreprocessorException(ex.getMessage()); } - + ModelConfiguration retVal = new ModelConfiguration(); retVal.setModelId(this.getModelId()); retVal.setConfigParameter("timeZone", weatherStation.getTimeZone()); diff --git a/src/main/java/no/nibio/vips/util/weather/WeatherDataSourceUtil.java b/src/main/java/no/nibio/vips/util/weather/WeatherDataSourceUtil.java index 47ffee78..c10ac808 100644 --- a/src/main/java/no/nibio/vips/util/weather/WeatherDataSourceUtil.java +++ b/src/main/java/no/nibio/vips/util/weather/WeatherDataSourceUtil.java @@ -86,6 +86,7 @@ public class WeatherDataSourceUtil { continue; } Collections.sort(paramObs); + //System.out.println("elementMeasurementType " + elementMeasurementType + " first date = " + paramObs.get(0).getTimeMeasured()); latestCommonDate = latestCommonDate == null ? paramObs.get(paramObs.size() - 1).getTimeMeasured() : new Date(Math.min(latestCommonDate.getTime(), paramObs.get(paramObs.size() - 1).getTimeMeasured().getTime())); } Integer previousObsSize = null; diff --git a/src/main/java/no/nibio/vips/util/weather/YrWeatherForecastProvider.java b/src/main/java/no/nibio/vips/util/weather/YrWeatherForecastProvider.java index 407deffe..f1f31091 100644 --- a/src/main/java/no/nibio/vips/util/weather/YrWeatherForecastProvider.java +++ b/src/main/java/no/nibio/vips/util/weather/YrWeatherForecastProvider.java @@ -152,6 +152,7 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{ } catch(IOException | ParserConfigurationException | SAXException | ParseException ex) { + ex.printStackTrace(); throw new ParseWeatherDataException(ex.getClass().getName() + ": " + ex.getMessage()); } return this.createHourlyDataFromYr(yrValues); -- GitLab