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

json with multiple species with types/varieties supported by phenology preprocessor

Phenology model preprocessor can support many to many species varieties/types and their related phase information i.e. Phase Name and Heat Requirement
parent 9c5d10a3
No related branches found
No related tags found
No related merge requests found
...@@ -44,21 +44,32 @@ import no.nibio.vips.util.weather.WeatherDataSourceUtil; ...@@ -44,21 +44,32 @@ import no.nibio.vips.util.weather.WeatherDataSourceUtil;
public class PhenologyModelPreprocessor extends ModelRunPreprocessor{ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
public final Logger LOGGER = Logger.getLogger(this.getClass().getName()); public final Logger LOGGER = Logger.getLogger(this.getClass().getName());
private final boolean DEBUG = false; private final boolean DEBUG = false;
private final static String MODEL_ID = "PHENOLOGYM"; private final static String MODEL_ID = "PHENOLOGYM";
private final static String TYPE_NAME = "typeName"; private final static String SPECIES_NAME = "speciesName";
private final static String SOWING_DATE = "sowingDate"; private final static String TYPE_NAME = "typeName";
private final static String SOWING_DATE = "sowingDate";
//private final static String SOWING_DATA = "sowingData"; private final static String PLANTATION_DATA = "plantationData";
private final static String PLANTATION_DATA = "plantationData"; private final static String FILE_PLANTATION = "/dataset/plantationData.json";
private final static String FILE_PLANTATION = "/dataset/plantationData.json";
private final static String NODE_SPECIES = "species";
private final static String NODE_SPECIES_LATIN_NAME = "speciesLatinName";
private final static String NODE_BASE_TEMP = "baseTemp";
private final static String NODE_TYPE_NAMES = "typeNames";
private final static String NODE_TYPE_NAME = "typeName";
private final static String NODE_PHASE_INFO = "phaseInfo";
private final static String NODE_PHASE_NAME = "phaseName";
private final static String NODE_HEAT_REQ = "heatReq";
@Override @Override
public ModelConfiguration getModelConfiguration(ForecastConfiguration configuration) throws PreprocessorException { public ModelConfiguration getModelConfiguration(ForecastConfiguration configuration) throws PreprocessorException {
String PHENOLOGY_SPECIES_NAME = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName(MODEL_ID, SPECIES_NAME);
String PHENOLOGY_TYPE_NAME = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName(MODEL_ID, TYPE_NAME); String PHENOLOGY_TYPE_NAME = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName(MODEL_ID, TYPE_NAME);
String PHENOLOGY_SOWING_DATE = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName(MODEL_ID, SOWING_DATE); String PHENOLOGY_SOWING_DATE = SessionControllerGetter.getForecastBean().getDeCamelizedFieldName(MODEL_ID, SOWING_DATE);
String paramPhenologySpeciesName = null;
String paramPhenologyTypeName = null; String paramPhenologyTypeName = null;
Date paramSowingDate = null; Date paramSowingDate = null;
...@@ -99,6 +110,8 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{ ...@@ -99,6 +110,8 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
List<WeatherObservation> observations = null; List<WeatherObservation> observations = null;
try { try {
observations = wdsUtil.getWeatherObservations( observations = wdsUtil.getWeatherObservations(
weatherStation weatherStation
...@@ -117,10 +130,8 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{ ...@@ -117,10 +130,8 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
throw new PreprocessorException(ex.getMessage()); throw new PreprocessorException(ex.getMessage());
} }
paramPhenologySpeciesName = configuration.getForecastModelConfigurationValue(PHENOLOGY_SPECIES_NAME);
paramPhenologyTypeName = configuration.getForecastModelConfigurationValue(PHENOLOGY_TYPE_NAME);
paramPhenologyTypeName = configuration.getForecastModelConfigurationValue(PHENOLOGY_TYPE_NAME);
Collections.sort(observations); Collections.sort(observations);
...@@ -157,33 +168,18 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{ ...@@ -157,33 +168,18 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
LOGGER.log(Level.CONFIG, "Observations=" + observations.toString()); LOGGER.log(Level.CONFIG, "Observations=" + observations.toString());
} }
Plant plantDBData = getConfigurationPlantation(FILE_PLANTATION,paramPhenologyTypeName); Plant plantDBData = getConfigurationPlantation(FILE_PLANTATION,paramPhenologySpeciesName,paramPhenologyTypeName);
if(!plantDBData.getPlantations().isEmpty())
{
plant = plantDBData;
plant.setStartDate(paramSowingDate);
} if(!plantDBData.getPlantations().isEmpty())
/*
if(plantDBData.getTypeName().equals(paramPhenologyTypeName))
{ {
plant = plantDBData; plant = plantDBData;
plant.setStartDate(paramSowingDate); plant.setStartDate(paramSowingDate);
} }
*/
//plant.setTypeName(paramPhenologyTypeName);
//plant.setStartDate(paramSowingDate);
retVal.setModelId(this.getModelId()); retVal.setModelId(this.getModelId());
retVal.setConfigParameter("timeZone", timeZone.getID()); retVal.setConfigParameter("timeZone", timeZone.getID());
retVal.setConfigParameter("observations", observations); retVal.setConfigParameter("observations", observations);
//retVal.setConfigParameter(SOWING_DATA, plant);
retVal.setConfigParameter(PLANTATION_DATA, plant); retVal.setConfigParameter(PLANTATION_DATA, plant);
return retVal; return retVal;
} }
...@@ -315,81 +311,75 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{ ...@@ -315,81 +311,75 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{
return retVal; return retVal;
} }
private Plant getConfigurationPlantation(String fileName, String strParamTypeName) private Plant getConfigurationPlantation(String fileName,String strParamSpeciesName, String strParamTypeName)
{ {
Plant plant = new Plant(); Plant plant = new Plant();
List<Plantation> plantations = new ArrayList<Plantation>(); List<Plantation> plantations = new ArrayList<Plantation>();
try { try {
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);
JsonNode nodeSpecies = jp.readValueAsTree();
JsonNode nodeTypeNames = nodeSpecies.path("typeNames");
plant.setSpeciesLatinName(nodeSpecies.get("speciesLatinName").asText()); JsonNode all = jp.readValueAsTree();
plant.setBaseTemp(nodeSpecies.get("baseTemp").asDouble());
JsonNode nodeAllSpecies = all.path(NODE_SPECIES);
if(nodeTypeNames.isArray()) if(nodeAllSpecies.isArray())
{ {
for(JsonNode nodeTypeName : nodeTypeNames) for(JsonNode nodeSpecies : nodeAllSpecies)
{ {
if(nodeTypeName.get("typeName").asText().trim().equalsIgnoreCase(strParamTypeName)) if(nodeSpecies.get(NODE_SPECIES_LATIN_NAME).asText().trim().equalsIgnoreCase(strParamSpeciesName))
{ {
plant.setTypeName(strParamTypeName); plant.setSpeciesLatinName(nodeSpecies.get(NODE_SPECIES_LATIN_NAME).asText());
if(null != nodeTypeName.get("baseTemp").asText()) if(null != nodeSpecies.get(NODE_BASE_TEMP).asText())
{ {
plant.setBaseTemp(nodeTypeName.get("baseTemp").asDouble()); plant.setBaseTemp(nodeSpecies.get(NODE_BASE_TEMP).asDouble());
} }
JsonNode nodeTypeNames = nodeSpecies.path(NODE_TYPE_NAMES);
JsonNode nodeAllPhaseInfo = nodeTypeName.path("phaseInfo");
if(nodeAllPhaseInfo.isArray()) if(nodeTypeNames.isArray())
{ {
for(JsonNode nodePhaseInfo : nodeAllPhaseInfo) for(JsonNode nodeTypeName : nodeTypeNames)
{ {
Plantation plantation = new Plantation(); if(nodeTypeName.get(NODE_TYPE_NAME).asText().trim().equalsIgnoreCase(strParamTypeName))
plantation.setTypeName(nodeTypeName.get("typeName").asText()); {
plant.setTypeName(strParamTypeName);
if(null != nodeTypeName.get(NODE_BASE_TEMP).asText())
{
plant.setBaseTemp(nodeTypeName.get(NODE_BASE_TEMP).asDouble());
}
JsonNode nodeAllPhaseInfo = nodeTypeName.path(NODE_PHASE_INFO);
if(nodeAllPhaseInfo.isArray())
{
for(JsonNode nodePhaseInfo : nodeAllPhaseInfo)
{
Plantation plantation = new Plantation();
plantation.setTypeName(nodeTypeName.get(NODE_TYPE_NAME).asText());
plantation.setPhaseName(nodePhaseInfo.get("phaseName").asText());
plantation.setHeatReq(nodePhaseInfo.get("heatReq").asDouble());
plantations.add(plantation);
}
} plantation.setPhaseName(nodePhaseInfo.get(NODE_PHASE_NAME).asText());
plantation.setHeatReq(nodePhaseInfo.get(NODE_HEAT_REQ).asDouble());
}
plantations.add(plantation);
} }
} }
}
/* }
JsonNode nodePhaseInfo = nodeSpecies.path("phaseInfo");
plant.setSpeciesLatinName(nodeSpecies.get("speciesLatinName").asText()); }
plant.setTypeName(nodeSpecies.get("typeName").asText());
plant.setBaseTemp(nodeSpecies.get("baseTemp").asDouble());
}
if(nodePhaseInfo.isArray())
{
for(JsonNode node : nodePhaseInfo)
{
Plantation plantation = new Plantation
( nodeSpecies.get("typeName").asText()
, node.get("phaseName").asText()
, node.get("heatReq").asDouble()
);
plantations.add(plantation);
} }
} }
*/
plant.setPlantations(plantations); plant.setPlantations(plantations);
......
...@@ -56,5 +56,10 @@ public class Plant { ...@@ -56,5 +56,10 @@ public class Plant {
public void setPlantations(List<Plantation> plantations) { public void setPlantations(List<Plantation> plantations) {
this.plantations = plantations; this.plantations = plantations;
} }
@Override
public String toString() {
return "Plant{" + "speciesLatinName=" + speciesLatinName + ", typeName=" + typeName + ", baseTemp=" + baseTemp + ", startDate=" + startDate + ", plantations=" + plantations + '}';
}
} }
...@@ -12,9 +12,7 @@ import java.util.Date; ...@@ -12,9 +12,7 @@ import java.util.Date;
public class Plantation { public class Plantation {
private String typeName; private String typeName;
private String phaseName; private String phaseName;
//private String baseTemp;
private Double heatReq; private Double heatReq;
//private Date startDate;
public Plantation() { public Plantation() {
} }
......
{ {
"speciesLatinName" : "Zea mays", "species":
"baseTemp" : "10",
"typeNames" :
[
{
"typeName" : "TESTVARIETY 2",
"baseTemp" : "10",
"phaseInfo":
[ [
{ {
"phaseName": "VE", "speciesLatinName" : "Zea mays",
"heatReq" : "66.67" "baseTemp" : "10",
}, "typeNames" :
{ [
"phaseName": "V2", {
"heatReq" : "111.11" "typeName" : "TESTVARIETY 2",
}, "baseTemp" : "10",
{ "phaseInfo" :
"phaseName": "V3", [
"heatReq" : "194.44" {
}, "phaseName": "VE",
{ "heatReq" : "66.67"
"phaseName": "V4-V6", },
"heatReq" : "263.89" {
}, "phaseName": "V2",
{ "heatReq" : "111.11"
"phaseName": "V7-V9", },
"heatReq" : "338.89" {
}, "phaseName": "V3",
{ "heatReq" : "194.44"
"phaseName": "V10", },
"heatReq" : "411.11" {
}, "phaseName": "V4-V6",
{ "heatReq" : "263.89"
"phaseName": "VT", },
"heatReq" : "630.55" {
}, "phaseName": "V7-V9",
{ "heatReq" : "338.89"
"phaseName": "R2", },
"heatReq" : "922.22" {
}, "phaseName": "V10",
{ "heatReq" : "411.11"
"phaseName": "R5", },
"heatReq" : "1361.11" {
}, "phaseName": "VT",
{ "heatReq" : "630.55"
"phaseName": "R6", },
"heatReq" : "1500" {
"phaseName": "R2",
"heatReq" : "922.22"
},
{
"phaseName": "R5",
"heatReq" : "1361.11"
},
{
"phaseName": "R6",
"heatReq" : "1500"
}
]
}
]
} }
] ]
}
]
} }
\ No newline at end of file
...@@ -497,3 +497,5 @@ sprayingDate04=Spraying Date 04 ...@@ -497,3 +497,5 @@ sprayingDate04=Spraying Date 04
PHENOLOGYM=Phenology Model PHENOLOGYM=Phenology Model
maizeVarity=Maize Variety maizeVarity=Maize Variety
sowingDate=Sowing Date sowingDate=Sowing Date
speciesName=Species Name
typeName=Type/Variety Name
\ No newline at end of file
...@@ -495,3 +495,5 @@ sprayingDate01=Dato for spr\u00f8yting #1 ...@@ -495,3 +495,5 @@ sprayingDate01=Dato for spr\u00f8yting #1
sprayingDate02=Dato for spr\u00f8yting #2 sprayingDate02=Dato for spr\u00f8yting #2
sprayingDate03=Dato for spr\u00f8yting #3 sprayingDate03=Dato for spr\u00f8yting #3
sprayingDate04=Dato for spr\u00f8yting #4 sprayingDate04=Dato for spr\u00f8yting #4
speciesName=Species Name
typeName=Type/Variety Name
\ No newline at end of file
...@@ -18,6 +18,16 @@ ...@@ -18,6 +18,16 @@
], ],
"_comment" : "Structure of the specific fields for FAWPHENOLO", "_comment" : "Structure of the specific fields for FAWPHENOLO",
"fields": [ "fields": [
{
"name" : "speciesName",
"dataType" : "STRING",
"fieldType" : "SELECT_SINGLE",
"required" : false,
"required" : true,
"selectOptions": [
{"value":"Zea mays", "label":{"en":"Zea mays","nb":"Zea mays"}, "selected":"true"}
]
},
{ {
"name" : "typeName", "name" : "typeName",
"dataType" : "STRING", "dataType" : "STRING",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment