From 088cb993bf22b134f780976019e8dec78ccaa892 Mon Sep 17 00:00:00 2001
From: Jussi Nikander <Jussi.Nikander@luke.fi>
Date: Tue, 5 Jun 2018 16:27:40 +0300
Subject: [PATCH] Added weather data to the results.

---
 .../model/cerealmodels/FinnCerealModels.java  | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/fi/luke/vips/model/cerealmodels/FinnCerealModels.java b/src/fi/luke/vips/model/cerealmodels/FinnCerealModels.java
index 8cd9cdb..9cc5c3c 100644
--- a/src/fi/luke/vips/model/cerealmodels/FinnCerealModels.java
+++ b/src/fi/luke/vips/model/cerealmodels/FinnCerealModels.java
@@ -23,6 +23,7 @@ import no.nibio.vips.model.ConfigValidationException;
 import no.nibio.vips.model.Model;
 import no.nibio.vips.model.ModelExcecutionException;
 import no.nibio.vips.model.ModelId;
+import no.nibio.vips.util.CommonNamespaces;
 import no.nibio.vips.util.InvalidAggregationTypeException;
 import no.nibio.vips.util.WeatherElements;
 import no.nibio.vips.util.WeatherObservationListException;
@@ -43,6 +44,7 @@ public class FinnCerealModels implements Model {
 
 	private DiseasePressureModel m;
 	private List<Result> results;
+	private Result parameters;
 	private List<WeatherObservation> dailyTemperature;
 	private List<WeatherObservation> dailyRainfall;
 	private Map<Date, List<Boolean>> leafWetness;
@@ -118,16 +120,19 @@ public class FinnCerealModels implements Model {
 		List<Result> resultList = new ArrayList<>();
 		// reset model
 		Double accumulatedRisk = 0.0;
+		// add model parameters to results
+		resultList.add(parameters);
 		for(int i=0; i < dailyTemperature2.size(); i++) {
 			Date currentDate = dailyTemperature2.get(i).getTimeMeasured();
 			Result r = new ResultImpl();
 			m.setTemperature(dailyTemperature2.get(i).getValue());
-			r.setValue(pathogen, "ATemp", ""+dailyTemperature2.get(i).getValue());
+			r.setValue(CommonNamespaces.NS_WEATHER, "ATemp", ""+dailyTemperature2.get(i).getValue());
 			Date test = dailyRainfall2.get(i).getTimeMeasured();
 			if(!currentDate.equals(test)) {
 				throw new ModelExcecutionException("Temperature and daily rainfall are from different dates!");
 			}
 			m.setPrecipitationRange(dailyRainfall2.get(i).getValue());
+			r.setValue(CommonNamespaces.NS_WEATHER, "Precipitation",""+dailyRainfall2.get(i).getValue());
 			List<Boolean> wetLeaves = leafWetness2.get(currentDate);
 			if(wetLeaves == null) {
 				throw new ModelExcecutionException("Leaf wetness data not found!");				
@@ -138,12 +143,14 @@ public class FinnCerealModels implements Model {
 				throw new ModelExcecutionException("Wind speed data not found!");				
 			}
 			m.setWindSpeed(wind);
+			// XXX horrible hack here
+			r.setValue(CommonNamespaces.NS_WEATHER, "WindSpeed", wind.toString());
 			Double wetHours = leafWetnessHours2.get(currentDate);
 			if(wetHours == null) {
 				throw new ModelExcecutionException("Leaf wetness hours data not found!");								
 			}
 			m.setDailyLeafWetnessDuration(wetHours);
-			r.setValue(pathogen, "LeafWet", "" + wetHours);
+			r.setValue(CommonNamespaces.NS_WEATHER, "LeafWet", "" + wetHours);
 			// TODO does not take into account the disease progress at the moment!
 			r.setValue(pathogen, "BASE_RISK", "" + m.getBaseRisk());
 			r.setValue(pathogen, "DAILY_RISK", ""+ m.getDailyRisk());
@@ -295,10 +302,13 @@ public class FinnCerealModels implements Model {
 				zone = TimeZone.getTimeZone(zoneString);
 			}
 			pathogen = (String)arg0.getConfigParameter("model");
-			m.setPathogen(pathogen);
 			m.setPrecedingCrop(((String)arg0.getConfigParameter("precedingCrop")));
+			parameters = new ResultImpl();
+			parameters.setValue(pathogen, "precedingCrop", (String)arg0.getConfigParameter("precedingCrop"));
 			m.setTillage(((String)arg0.getConfigParameter("tillageMethod")));
+			parameters.setValue(pathogen, "tillageMethod",(String)arg0.getConfigParameter("tillageMethod"));
 			m.setCropSusceptibility(((String)arg0.getConfigParameter("diseaseSusceptibility")));
+			parameters.setValue(pathogen, "diseaseSusceptibility", (String)arg0.getConfigParameter("diseaseSusceptibility"));
 
 			// Optional parameters, will be given default values if not included in the ModelConfiguration
 			Double d = (Double)arg0.getConfigParameter("accumulatedRisk");
@@ -346,7 +356,8 @@ public class FinnCerealModels implements Model {
 			windSpeed = getWindSpeedByDay(windSpeedAll, wu);
 			// for some reason getAggregatedDailyValues returns the days in reverse order. This fixes that.
 			Collections.sort(dailyTemperature);
-			Collections.sort(dailyRainfall);			
+			Collections.sort(dailyRainfall);
+			// weather parameters to Result
 		} catch(ClassCastException e) {
 			e.printStackTrace();
 			throw new ConfigValidationException("incorrect input");
-- 
GitLab