Skip to content
Snippets Groups Projects
Commit 6d61bbd0 authored by Bhabesh Bhabani Mukhopadhyay's avatar Bhabesh Bhabani Mukhopadhyay
Browse files

Java Logging

Simple java logging system implement
parent fef127d6
Branches
Tags
No related merge requests found
...@@ -48,6 +48,8 @@ import java.util.Collections; ...@@ -48,6 +48,8 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
import no.nibio.vips.entity.ModelConfiguration; import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.Result; import no.nibio.vips.entity.Result;
import no.nibio.vips.entity.ResultImpl; import no.nibio.vips.entity.ResultImpl;
...@@ -62,12 +64,13 @@ import no.nibio.vips.util.JSONUtil; ...@@ -62,12 +64,13 @@ import no.nibio.vips.util.JSONUtil;
import no.nibio.vips.util.ModelUtil; import no.nibio.vips.util.ModelUtil;
import no.nibio.vips.util.WeatherUtil; import no.nibio.vips.util.WeatherUtil;
/** /**
* *
* @author bhabesh * @author bhabesh
*/ */
public class AlternariaModel extends I18nImpl implements Model{ public class AlternariaModel extends I18nImpl implements Model{
public final static Logger LOGGER = Logger.getLogger(AlternariaModel.class.getName());
public final static String NAME_MODEL_ID = "ALTERNARIA"; public final static String NAME_MODEL_ID = "ALTERNARIA";
public final static ModelId MODEL_ID = new ModelId(NAME_MODEL_ID); public final static ModelId MODEL_ID = new ModelId(NAME_MODEL_ID);
public final static int THRESHOLD_LW = 30; // Threshold for leave wetness public final static int THRESHOLD_LW = 30; // Threshold for leave wetness
...@@ -93,6 +96,7 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -93,6 +96,7 @@ public class AlternariaModel extends I18nImpl implements Model{
@Override @Override
public List<Result> getResult() throws ModelExcecutionException public List<Result> getResult() throws ModelExcecutionException
{ {
/** /**
* method name : getResult * method name : getResult
* @param : * @param :
...@@ -119,7 +123,12 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -119,7 +123,12 @@ public class AlternariaModel extends I18nImpl implements Model{
{ {
Result result = new ResultImpl(); Result result = new ResultImpl();
if(null == dataMatrix.getParamStringValueForDate(currentDate, DataMatrix.SPRAYING_DATE))
{
// DO Nothing -- Consider same accumulatedDSV
}
else
{
if(dataMatrix.getParamStringValueForDate(currentDate, DataMatrix.SPRAYING_DATE).equals(YES)) if(dataMatrix.getParamStringValueForDate(currentDate, DataMatrix.SPRAYING_DATE).equals(YES))
{ {
accumulatedDSV = 0; accumulatedDSV = 0;
...@@ -129,24 +138,28 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -129,24 +138,28 @@ public class AlternariaModel extends I18nImpl implements Model{
{ {
accumulatedDSV = accumulatedDSV + dataMatrix.getParamIntValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE); accumulatedDSV = accumulatedDSV + dataMatrix.getParamIntValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE);
} }
}
result.setValidTimeStart(currentDate); result.setValidTimeStart(currentDate);
result.setWarningStatus(getWarningStatus(accumulatedDSV)); result.setWarningStatus(getWarningStatus(accumulatedDSV));
result.setValue(CommonNamespaces.NS_WEATHER, DataMatrix.TEMPERATURE_MEAN, dFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.TEMPERATURE_MEAN))); result.setValue(CommonNamespaces.NS_WEATHER, DataMatrix.TEMPERATURE_MEAN, dFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.TEMPERATURE_MEAN)));
result.setValue(NAME_MODEL_ID, DataMatrix.WET_HOUR, iFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.LEAF_WETNESS_DURATION))); result.setValue(NAME_MODEL_ID, DataMatrix.WET_HOUR, iFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.LEAF_WETNESS_DURATION)));
result.setValue(NAME_MODEL_ID, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE_SUM, iFormat.format(accumulatedDSV)); result.setValue(NAME_MODEL_ID, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE_SUM, iFormat.format(accumulatedDSV));
result.setValue(NAME_MODEL_ID, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE, iFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE))); result.setValue(NAME_MODEL_ID, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE, iFormat.format(this.dataMatrix.getParamValueForDate(currentDate, DataMatrix.DAILY_DISEASE_SEVERITY_VALUE)));
result.setValue(NAME_MODEL_ID, DataMatrix.THRESHOLD_DSV_BASE, String.valueOf(THRESHOLD_DSV_BASE));
result.setValue(NAME_MODEL_ID, DataMatrix.THRESHOLD_DSV_MAX, String.valueOf(THRESHOLD_DSV_MIN));
results.add(result); results.add(result);
cal.setTime(currentDate); cal.setTime(currentDate);
cal.add(Calendar.DATE, 1); cal.add(Calendar.DATE, 1);
currentDate = cal.getTime(); currentDate = cal.getTime();
} }
// System.out.println("DataMatrix : "+dataMatrix);
//System.out.println("-----------------------------------------------------------------"); //LOGGER.log(Level.INFO, "DataMatrix-Value 03: "+dataMatrix);
return results; return results;
} }
...@@ -389,9 +402,7 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -389,9 +402,7 @@ public class AlternariaModel extends I18nImpl implements Model{
WeatherUtil wUtil = new WeatherUtil(); WeatherUtil wUtil = new WeatherUtil();
// Setting timezone // Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone")); this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
//System.out.println("TimeZone=" + this.timeZone);
sprayingDates = (null == mapper.convertValue(config.getConfigParameter(DataMatrix.SPRAYING_DATES), new TypeReference<List<Date>>(){})) sprayingDates = (null == mapper.convertValue(config.getConfigParameter(DataMatrix.SPRAYING_DATES), new TypeReference<List<Date>>(){}))
? null ? null
: mapper.convertValue(config.getConfigParameter(DataMatrix.SPRAYING_DATES), new TypeReference<List<Date>>(){}); : mapper.convertValue(config.getConfigParameter(DataMatrix.SPRAYING_DATES), new TypeReference<List<Date>>(){});
...@@ -404,7 +415,7 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -404,7 +415,7 @@ public class AlternariaModel extends I18nImpl implements Model{
{ {
weatherObj.setTimeMeasured(wUtil.pragmaticAdjustmentToMidnight(weatherObj.getTimeMeasured(), timeZone)); weatherObj.setTimeMeasured(wUtil.pragmaticAdjustmentToMidnight(weatherObj.getTimeMeasured(), timeZone));
//System.out.println(" weatherObj : "+weatherObj);
Date sprayDate = null; Date sprayDate = null;
switch(weatherObj.getElementMeasurementTypeId()) switch(weatherObj.getElementMeasurementTypeId())
...@@ -538,12 +549,8 @@ public class AlternariaModel extends I18nImpl implements Model{ ...@@ -538,12 +549,8 @@ public class AlternariaModel extends I18nImpl implements Model{
dateHourlyLw_previousDay = dateHourlyLw_currentDay; dateHourlyLw_previousDay = dateHourlyLw_currentDay;
} }
/*
Gson gson = new Gson(); //LOGGER.log(Level.INFO, dataMatrix.toString());
System.out.println("Data matrix in JSON : "+gson.toJson(dataMatrix));
*/
// System.out.println("Data matrix : "+dataMatrix );
} }
......
...@@ -52,5 +52,10 @@ public class DataMatrix extends DateMap{ ...@@ -52,5 +52,10 @@ public class DataMatrix extends DateMap{
public final static String SPRAYING_DATES = "sprayingDates";// Spraying dates public final static String SPRAYING_DATES = "sprayingDates";// Spraying dates
public final static String SPRAYING_DATE = "sprayingDate"; // Spray Date public final static String SPRAYING_DATE = "sprayingDate"; // Spray Date
public final static String THRESHOLD_DSV_BASE = "THRESHOLD_DSV_BASE"; // THRESHOLD_DSV_BASE
public final static String THRESHOLD_DSV_MAX = "THRESHOLD_DSV_MAX"; // THRESHOLD_DSV_MAX
} }
...@@ -61,7 +61,7 @@ public class AlternariaModelTest { ...@@ -61,7 +61,7 @@ public class AlternariaModelTest {
private final String CONST_TEST_DATA_06 = "TEST_DATA_06"; private final String CONST_TEST_DATA_06 = "TEST_DATA_06";
private final String CONST_TEST_DATA_07 = "TEST_DATA_07"; private final String CONST_TEST_DATA_07 = "TEST_DATA_07";
private final String EFFECTED_FILE_WEATHER_TEST_DATA = CONST_TEST_DATA_06; private final String EFFECTED_FILE_WEATHER_TEST_DATA = CONST_TEST_DATA_04;
public AlternariaModelTest() { public AlternariaModelTest() {
} }
...@@ -89,17 +89,19 @@ public class AlternariaModelTest { ...@@ -89,17 +89,19 @@ public class AlternariaModelTest {
public void testGetResult() throws Exception { public void testGetResult() throws Exception {
System.out.println("getResult"); System.out.println("getResult");
ModelConfiguration config = this.getConfiguration(getWeatherDataFile()); ModelConfiguration config = this.getConfiguration(getWeatherDataFile());
config.setConfigParameter("sprayingDates", this.getConfigurationSprayingDates(getResetDataFile())); config.setConfigParameter("sprayingDates", this.getConfigurationSprayingDates(getResetDataFile()));
AlternariaModel instance = new AlternariaModel(); AlternariaModel instance = new AlternariaModel();
instance.setConfiguration(config); instance.setConfiguration(config);
List<Result> result = instance.getResult(); List<Result> result = instance.getResult();
assertNotNull(result); assertNotNull(result);
/*
for(Result res:result) for(Result res:result)
{ {
// LOGGER.log(Level.INFO, res.toString());
System.out.println(res.toString()); System.out.println(res.toString());
} }
*/
} }
...@@ -283,7 +285,7 @@ public class AlternariaModelTest { ...@@ -283,7 +285,7 @@ public class AlternariaModelTest {
config.setModelId(AlternariaModel.MODEL_ID.toString()); config.setModelId(AlternariaModel.MODEL_ID.toString());
config.setConfigParameter("timeZone", "Europe/Helsinki"); config.setConfigParameter("timeZone", "Europe/Oslo");
BufferedInputStream inputStream = new BufferedInputStream(this.getClass().getResourceAsStream(fileName)); BufferedInputStream inputStream = new BufferedInputStream(this.getClass().getResourceAsStream(fileName));
JsonFactory f = new MappingJsonFactory(); JsonFactory f = new MappingJsonFactory();
JsonParser jp = f.createParser(inputStream); JsonParser jp = f.createParser(inputStream);
...@@ -354,26 +356,28 @@ public class AlternariaModelTest { ...@@ -354,26 +356,28 @@ public class AlternariaModelTest {
Date firstDate = null; Date firstDate = null;
Date lastDate = null; Date lastDate = null;
if(all.isArray()) if(null != all)
{ {
for(JsonNode node : all){ if(all.isArray())
{
Date timeMeasuredForSpray = (Date)mapper.convertValue(node, new TypeReference<Date>(){}); for(JsonNode node : all){
//System.out.println("Spraying Date : "+timeMeasuredForSpray);
if(timeMeasuredForSpray != null ) Date timeMeasuredForSpray = (Date)mapper.convertValue(node, new TypeReference<Date>(){});
{ //System.out.println("Spraying Date : "+timeMeasuredForSpray);
sprayingDates.add(timeMeasuredForSpray); if(timeMeasuredForSpray != null )
{
sprayingDates.add(timeMeasuredForSpray);
}
} }
} }
else
} {
else fail("Data input from file is not a JSON array for list of spraying dates");
{ }
fail("Data input from file is not a JSON array for list of spraying dates");
} }
return sprayingDates; return sprayingDates;
} catch (IOException ex) { } catch (IOException ex) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment