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

Bugfix: Now all RISK calculations are added to result

Added all parameters to result
parent c9c244f6
Branches
Tags
No related merge requests found
/*
* Copyright (c) 2013-2014 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of VIPS/NaerstadModel.
* VIPS/NaerstadModel is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VIPS/NaerstadModel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VIPS/NaerstadModel. If not, see <http://www.gnu.org/licenses/>.
*
*/
package no.bioforsk.vips.model.naerstadmodel;
import java.text.DecimalFormat;
......@@ -65,7 +83,6 @@ public class NaerstadModel extends I18nImpl implements Model{
{
this.calculateNaerstadModellBakgroundData();
this.backgroundData.toString();
List<Result> results = new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.setTime(this.calculationStart);
......@@ -75,33 +92,46 @@ public class NaerstadModel extends I18nImpl implements Model{
*/
cal.add(Calendar.DATE, 1);
DecimalFormat dFormat = new DecimalFormat("###.##");
for(int j=0;j<4;j++)
//System.out.println("RESULTS: " + this.backgroundData.toString());
Date thePresent = cal.getTime();
while(thePresent.compareTo(calculationEnd) <= 0)
{
Date dateStart = cal.getTime();
cal.add(Calendar.DATE, 1);
Date dateEnd = cal.getTime();
Date thePresent = dateStart;
while(thePresent.before(dateEnd))
Result result = new ResultImpl();
result.setResultValidTime(thePresent);
Double RISK = this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.RISK);
// TODO: Find better way of terminating?
if(RISK == null)
{
Result result = new ResultImpl();
result.setResultValidTime(thePresent);
Double RISK = this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.RISK);
// TODO: Find better way of terminating?
if(RISK == null)
{
break;
}
if(this.DEBUG)
System.out.println("RISK(" + thePresent + ")=" + RISK);
result.setValue("RISK", dFormat.format(RISK));
result.setWarningStatus(this.getWarningStatus(RISK));
results.add(result);
// Moving on
cal.setTime(thePresent);
cal.add(Calendar.HOUR_OF_DAY, 1);
thePresent = cal.getTime();
break;
}
if(this.DEBUG)
System.out.println("RISK(" + thePresent + ")=" + RISK);
result.setValue("RISK", dFormat.format(RISK));
result.setValue("TSHH", dFormat.format(this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.TSHH)));
result.setValue("SPH", dFormat.format(this.backgroundData.getParamIntValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.SPH)));
result.setValue("VAS", dFormat.format(this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.VAS)));
result.setValue("VRS", dFormat.format(this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.VRS)));
result.setValue("WHS", dFormat.format(this.backgroundData.getParamIntValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.WHS)));
result.setValue("WD", dFormat.format(this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.WD)));
result.setValue("WH", dFormat.format(this.backgroundData.getParamIntValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.WH)));
result.setValue("IR", dFormat.format(this.backgroundData.getParamIntValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.IR)));
result.setWarningStatus(this.getWarningStatus(RISK));
// Adding weather data
result.setValue("TM", dFormat.format(this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.TM)));
result.setValue("UM", dFormat.format(this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.UM)));
result.setValue("RR", dFormat.format(this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.RR)));
result.setValue("Q0", dFormat.format(this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.Q0)));
result.setValue("BT", dFormat.format(this.backgroundData.getParamDoubleValueForDate(thePresent, NaerstadModelBackgroundDataMatrix.BT)));
results.add(result);
// Moving on
cal.setTime(thePresent);
cal.add(Calendar.HOUR_OF_DAY, 1);
thePresent = cal.getTime();
}
return results;
......@@ -318,6 +348,13 @@ public class NaerstadModel extends I18nImpl implements Model{
for(Integer i=0;i<TMliste.length;i++)
{
// Storing the weather data
this.backgroundData.setParamDoubleValueForDate(TMliste[i].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.TM, TMliste[i].getValue());
this.backgroundData.setParamDoubleValueForDate(TMliste[i].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.UM, UMliste[i].getValue());
this.backgroundData.setParamDoubleValueForDate(TMliste[i].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.RR, RRliste[i].getValue());
this.backgroundData.setParamDoubleValueForDate(TMliste[i].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.Q0, Q0liste[i].getValue());
this.backgroundData.setParamDoubleValueForDate(TMliste[i].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.BT, BTliste[i].getValue());
// Calculating TSHH (Temperature Sum Humid Hours)
Double TSHHLastHour = first ? 0 : this.backgroundData.getParamDoubleValueForDate(TMliste[i-1].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.TSHH);
Double TSHH;
......@@ -464,7 +501,7 @@ public class NaerstadModel extends I18nImpl implements Model{
this.backgroundData.setParamIntValueForDate(TMliste[i].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.IR, IR);
// Calculating RISK.
Double RISK = IR ==1 ? (TSWH/40) * VRS : 0d;
Double RISK = IR==1 ? (TSWH/40) * VRS : 0d;
this.backgroundData.setParamDoubleValueForDate(TMliste[i].getTimeMeasured(), NaerstadModelBackgroundDataMatrix.RISK, RISK);
}
......@@ -562,12 +599,26 @@ public class NaerstadModel extends I18nImpl implements Model{
@Override
public String getLicense() {
return "Open Source. Details will follow.";
return "Copyright (c) 2013 Bioforsk <http://www.bioforsk.no/>. \n" +
" \n" +
" This file is part of VIPS/NaerstadModel \n" +
" VIPS/NaerstadModel is free software: you can redistribute it and/or modify\n" +
" it under the terms of the GNU Affero General Public License as published by\n" +
" the Free Software Foundation, either version 3 of the License, or\n" +
" (at your option) any later version.\n" +
" \n" +
" VIPS/NaerstadModel is distributed in the hope that it will be useful,\n" +
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
" GNU Affero General Public License for more details.\n" +
" \n" +
" You should have received a copy of the GNU Affero General Public License\n" +
" along with VIPS/NaerstadModel. If not, see <http://www.gnu.org/licenses/>.";
}
@Override
public String getCopyright() {
return "(c) 2013 Bioforsk (http://www.bioforsk.no/). Contact: post@bioforsk.no";
return "(c) 2013-2014 Bioforsk (http://www.bioforsk.no/). Contact: post@bioforsk.no";
}
......
/*
* Copyright (c) 2013-2014 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of VIPS/NaerstadModel.
* VIPS/NaerstadModel is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VIPS/NaerstadModel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VIPS/NaerstadModel. If not, see <http://www.gnu.org/licenses/>.
*
*/
package no.bioforsk.vips.model.naerstadmodel;
/**
* Matrix with calculated background data for Naerstad Model
* &copy; 2009 Bioforsk.no
* @copyright 2009-2014 Bioforsk.no
* @author Tor-Einar Skog <tor-einar.skog@bioforsk.no>
*/
public class NaerstadModelBackgroundDataMatrix extends no.bioforsk.vips.util.DateMap{
......@@ -18,6 +36,15 @@ public class NaerstadModelBackgroundDataMatrix extends no.bioforsk.vips.util.Dat
public final static String WH = "WH";
public final static String IR = "IR";
public final static String RISK = "RISK";
// Weather data stored for convenience (putting into result object)
public final static String TM = "TM";
public final static String UM = "UM";
public final static String RR = "RR";
public final static String Q0 = "Q0";
public final static String BT = "BT";
public NaerstadModelBackgroundDataMatrix()
{
......
......@@ -7,11 +7,14 @@ package no.bioforsk.vips.model.naerstadmodel;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import static junit.framework.Assert.fail;
import junit.framework.TestCase;
import no.bioforsk.vips.entity.ModelConfiguration;
import no.bioforsk.vips.entity.Result;
import no.bioforsk.vips.entity.WeatherObservation;
import no.bioforsk.vips.model.ConfigValidationException;
import no.bioforsk.vips.model.ModelExcecutionException;
......@@ -51,11 +54,23 @@ public class NaerstadModelTest extends TestCase {
System.out.println("getResult");
NaerstadModel instance = new NaerstadModel();
instance.setConfiguration(this.getConfiguration());
List result;
result = instance.getResult();
List<Result> results;
results = instance.getResult();
//System.out.println("Result size=" + result.size());
assertTrue(result.size() == 96);
System.out.println("Result size=" + results.size());
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Oslo"));
cal.set(2012, Calendar.AUGUST, 26, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
for(Result res:results)
{
if(res.getResultValidTime().compareTo(cal.getTime()) == 0)
{
assertTrue(res.getAllValues().get("RISK").equals("5.36"));
}
System.out.println("Res[" + res.getResultValidTime() + "]:" + res.getAllValues());
}
assertTrue(results.size() == 209);
} catch (ConfigValidationException | ModelExcecutionException ex) {
fail("Exception: " + ex.getMessage());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment