Skip to content
Snippets Groups Projects
Commit 76811814 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Added check for missing weather data

parent 0efe2bbe
No related branches found
No related tags found
No related merge requests found
......@@ -356,7 +356,8 @@ public class DeliaRadicumModel extends I18nImpl implements Model{
* @param inputParameterName the parameter to sum
* @param outputParameterName the result
*/
private void calculateTemperatureSum(String inputParameterName, String outputParameterName) {
private void calculateTemperatureSum(String inputParameterName, String outputParameterName) throws ModelExcecutionException {
//System.out.println("input=" + inputParameterName + ", ouput=" +outputParameterName);
Date today = this.dataMatrix.getFirstDateWithParameterValue(inputParameterName);
Date lastDate = this.dataMatrix.getLastDateWithValues();
Calendar cal = Calendar.getInstance(this.timeZone);
......@@ -365,6 +366,11 @@ public class DeliaRadicumModel extends I18nImpl implements Model{
while(today.compareTo(lastDate) < 0)
{
WeatherObservation todayTemp = (WeatherObservation)this.dataMatrix.getParamValueForDate(today, inputParameterName);
if(todayTemp == null)
{
throw new ModelExcecutionException("Missing weather data at " + today + ": " + inputParameterName);
}
//System.out.println("today=" + today + ",todayTemp=" + todayTemp);
sum += Math.max(0.0, todayTemp.getValue() - this.dayDegreeBaseTemp);
this.dataMatrix.setParamDoubleValueForDate(today, outputParameterName, sum);
cal.setTime(today);
......
......@@ -157,6 +157,37 @@ public class DeliaRadicumModelTest {
}
}
}
@Test
public void testWithSwedishData() throws Exception{
DeliaRadicumModel instance = new DeliaRadicumModel();
ModelConfiguration config = this.getConfiguration("/weatherdata_fjalkinge_sweden.json");
instance.setConfiguration(config);
List<Result> results = instance.getResult();
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Oslo"));
cal.set(2015, Calendar.MAY, 15, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
Date lastGreen = cal.getTime();
cal.set(2015, Calendar.MAY,18,0,0,0);
Date lastYellow = cal.getTime();
for(Result result:results)
{
System.out.println(result.getResultValidTime() + ": " + result.getWarningStatus());
if(result.getResultValidTime().compareTo(lastGreen) <= 0)
{
assertEquals(Result.WARNING_STATUS_NO_RISK, result.getWarningStatus());
}
else if(result.getResultValidTime().compareTo(lastYellow) <= 0)
{
assertEquals(Result.WARNING_STATUS_MINOR_RISK, result.getWarningStatus());
}
else
{
assertEquals(Result.WARNING_STATUS_HIGH_RISK, result.getWarningStatus());
}
}
}
/**
* Test of getModelId method, of class DeliaRadicumModel.
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment