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

Refactoring Result Object

parent be97eddc
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,7 @@ import no.bioforsk.vips.model.ConfigValidationException; ...@@ -35,6 +35,7 @@ import no.bioforsk.vips.model.ConfigValidationException;
import no.bioforsk.vips.model.Model; import no.bioforsk.vips.model.Model;
import no.bioforsk.vips.model.ModelExcecutionException; import no.bioforsk.vips.model.ModelExcecutionException;
import no.bioforsk.vips.model.ModelId; import no.bioforsk.vips.model.ModelId;
import no.bioforsk.vips.util.CommonNamespaces;
import no.bioforsk.vips.util.InvalidAggregationTypeException; import no.bioforsk.vips.util.InvalidAggregationTypeException;
import no.bioforsk.vips.util.WeatherElements; import no.bioforsk.vips.util.WeatherElements;
import no.bioforsk.vips.util.WeatherObservationListException; import no.bioforsk.vips.util.WeatherObservationListException;
...@@ -118,19 +119,19 @@ public class AppleScabModel extends I18nImpl implements Model{ ...@@ -118,19 +119,19 @@ public class AppleScabModel extends I18nImpl implements Model{
{ {
Result result = new ResultImpl(); Result result = new ResultImpl();
result.setResultValidTime(timeStamp); result.setResultValidTime(timeStamp);
result.setValue(AppleScabCalculations.ASCOSPORE_MATURITY, this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.ASCOSPORE_MATURITY) != null ? String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.ASCOSPORE_MATURITY)) : ""); result.setValue(this.getModelId().toString(), AppleScabCalculations.ASCOSPORE_MATURITY, this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.ASCOSPORE_MATURITY) != null ? String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.ASCOSPORE_MATURITY)) : "");
result.setValue(AppleScabCalculations.ACCUMULATED_MILLS, String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.ACCUMULATED_MILLS))); result.setValue(this.getModelId().toString(), AppleScabCalculations.ACCUMULATED_MILLS, String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.ACCUMULATED_MILLS)));
result.setValue(AppleScabCalculations.TM, String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.TM))); result.setValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.TM, String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.TM)));
result.setValue(AppleScabCalculations.BT, String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.BT))); result.setValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.BT, String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.BT)));
result.setValue(AppleScabCalculations.RR, String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.RR))); result.setValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.RR, String.valueOf(this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.RR)));
Double accumulatedTemperature = this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.ACCUMULATED_TEMPERATURE); Double accumulatedTemperature = this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.ACCUMULATED_TEMPERATURE);
result.setValue(AppleScabCalculations.ACCUMULATED_TEMPERATURE, accumulatedTemperature != null ? String.valueOf(accumulatedTemperature) : ""); result.setValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.ACCUMULATED_TEMPERATURE, accumulatedTemperature != null ? String.valueOf(accumulatedTemperature) : "");
Double aggregatedLeafWetness = this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.AGGREGATED_LEAF_WETNESS); Double aggregatedLeafWetness = this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.AGGREGATED_LEAF_WETNESS);
result.setValue(AppleScabCalculations.AGGREGATED_LEAF_WETNESS, aggregatedLeafWetness != null ? String.valueOf(aggregatedLeafWetness) : ""); result.setValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.AGGREGATED_LEAF_WETNESS, aggregatedLeafWetness != null ? String.valueOf(aggregatedLeafWetness) : "");
Double aggregatedTemperature = this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.AGGREGATED_TEMPERATURE); Double aggregatedTemperature = this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.AGGREGATED_TEMPERATURE);
result.setValue(AppleScabCalculations.AGGREGATED_TEMPERATURE, aggregatedTemperature != null ? String.valueOf(aggregatedTemperature) : ""); result.setValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.AGGREGATED_TEMPERATURE, aggregatedTemperature != null ? String.valueOf(aggregatedTemperature) : "");
Double aggregatedPrecipitation = this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.AGGREGATED_PRECIPITATION); Double aggregatedPrecipitation = this.calculations.getParamDoubleValueForDate(timeStamp, AppleScabCalculations.AGGREGATED_PRECIPITATION);
result.setValue(AppleScabCalculations.AGGREGATED_PRECIPITATION, aggregatedPrecipitation != null ? String.valueOf(aggregatedPrecipitation) : ""); result.setValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.AGGREGATED_PRECIPITATION, aggregatedPrecipitation != null ? String.valueOf(aggregatedPrecipitation) : "");
// Deciding warning status // Deciding warning status
result.setWarningStatus(this.getWarningStatus(timeStamp)); result.setWarningStatus(this.getWarningStatus(timeStamp));
......
...@@ -24,6 +24,7 @@ import no.bioforsk.vips.entity.Result; ...@@ -24,6 +24,7 @@ import no.bioforsk.vips.entity.Result;
import no.bioforsk.vips.entity.WeatherObservation; import no.bioforsk.vips.entity.WeatherObservation;
import no.bioforsk.vips.model.ConfigValidationException; import no.bioforsk.vips.model.ConfigValidationException;
import no.bioforsk.vips.model.ModelExcecutionException; import no.bioforsk.vips.model.ModelExcecutionException;
import no.bioforsk.vips.util.CommonNamespaces;
import no.bioforsk.vips.util.WeatherObservationListException; import no.bioforsk.vips.util.WeatherObservationListException;
import org.codehaus.jackson.JsonFactory; import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.JsonNode;
...@@ -85,14 +86,14 @@ public class AppleScabModelTest extends TestCase { ...@@ -85,14 +86,14 @@ public class AppleScabModelTest extends TestCase {
); );
for(Result result:results) for(Result result:results)
{ {
if(!result.getValue(AppleScabCalculations.ACCUMULATED_TEMPERATURE).equals("")) if(!result.getValue(instance.getModelId().toString(), AppleScabCalculations.ACCUMULATED_TEMPERATURE).equals(""))
{ {
System.out.println( System.out.println(
format.format(result.getResultValidTime()) + format.format(result.getResultValidTime()) +
"\t" + result.getValue(AppleScabCalculations.ACCUMULATED_TEMPERATURE) + "\t" + result.getValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.ACCUMULATED_TEMPERATURE) +
"\t" + result.getValue(AppleScabCalculations.AGGREGATED_LEAF_WETNESS) + "\t" + result.getValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.AGGREGATED_LEAF_WETNESS) +
"\t" + result.getValue(AppleScabCalculations.AGGREGATED_TEMPERATURE) + "\t" + result.getValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.AGGREGATED_TEMPERATURE) +
"\t" + result.getValue(AppleScabCalculations.AGGREGATED_PRECIPITATION) "\t" + result.getValue(CommonNamespaces.NS_WEATHER, AppleScabCalculations.AGGREGATED_PRECIPITATION)
); );
} }
} }
...@@ -110,11 +111,11 @@ public class AppleScabModelTest extends TestCase { ...@@ -110,11 +111,11 @@ public class AppleScabModelTest extends TestCase {
{ {
System.out.println( System.out.println(
format.format(result.getResultValidTime()) + format.format(result.getResultValidTime()) +
"\t" + result.getValue("AccumulatedMills") + "\t" + result.getValue(instance.getModelId().toString(), "AccumulatedMills") +
"\t" + result.getValue("AscosporeMaturity") + "\t" + result.getValue(instance.getModelId().toString(), "AscosporeMaturity") +
"\t" + result.getValue("TM") + "\t" + result.getValue(CommonNamespaces.NS_WEATHER, "TM") +
"\t" + result.getValue("BT") + "\t" + result.getValue(CommonNamespaces.NS_WEATHER, "BT") +
"\t" + result.getValue("RR") "\t" + result.getValue(CommonNamespaces.NS_WEATHER, "RR")
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment