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

First commit

parents
Branches
Tags
No related merge requests found
target/
classes/
*~
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.license>default_1</netbeans.hint.license>
</properties>
</project-shared-configuration>
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>no.bioforsk.vips</groupId>
<artifactId>GrassDryingModel</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>no.bioforsk.vips.common</groupId>
<artifactId>VIPSCommon</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
/*
* Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of GrassDryingModel.
* GrassDryingModel 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.
*
* GrassDryingModel 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 GrassDryingModel. If not, see <http://www.gnu.org/licenses/>.
*
*/
package no.bioforsk.vips.model.grassdryingmodel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import no.bioforsk.vips.entity.ModelConfiguration;
import no.bioforsk.vips.entity.Result;
import no.bioforsk.vips.entity.ResultImpl;
import no.bioforsk.vips.entity.WeatherObservation;
import no.bioforsk.vips.i18n.I18nImpl;
import no.bioforsk.vips.model.ConfigValidationException;
import no.bioforsk.vips.model.Model;
import no.bioforsk.vips.model.ModelExcecutionException;
import no.bioforsk.vips.model.ModelId;
import no.bioforsk.vips.util.WeatherElements;
import no.bioforsk.vips.util.WeatherObservationListException;
import no.bioforsk.vips.util.WeatherUtil;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
/**
* @copyright 2014 <a href="http://www.bioforsk.no/">Bioforsk</a>
* @author Tor-Einar Skog <tor-einar.skog@bioforsk.no>
*/
public class GrassDryingModel extends I18nImpl implements Model{
/**
* The unique identifier for this model
*/
public final static ModelId MODEL_ID = new ModelId("GRASSDRYMO");
// Weather data collections
private List<WeatherObservation> TM; // Mean temperature
private List<WeatherObservation> RR; // Rainfall
private List<WeatherObservation> Q0; // Global radiation
private List<WeatherObservation> FM2; // Wind speed 2m above ground (m/s)
private List<WeatherObservation> UM; // Relative humidity
// Other configuration values
private TimeZone timeZone;
private Double yield; // Kgs? Tons?? Per hectar?
// 1 = weak, 2 = strong, 3 = crushed
private Integer conditioning;
private Double stringWidth;
public GrassDryingModel()
{
// Setting the file name of the resource bundle
super("no.bioforsk.vips.model.grassdryingmodel.texts");
}
@Override
public List<Result> getResult() throws ModelExcecutionException {
// Calculate rewetting
Map<Date, Double> rewet = this.calculateRewet(this.RR);
List<Result> results = new ArrayList<>();
// Using weather data for time keeping
Collections.sort(this.TM);
Double sigma_E = 0.0;
for(int i=0;i<this.TM.size();i++)
{
Date currentTime = this.TM.get(i).getTimeMeasured();
Result result = new ResultImpl();
sigma_E = sigma_E + this.calculateE(this.TM.get(i).getValue(), this.UM.get(i).getValue(), this.Q0.get(i).getValue(), this.FM2.get(i).getValue());
Double dryMatter = this.calculateTS(
this.calculateMCWB(
this.calculateM(
this.calculateMe(this.UM.get(i).getValue()),
sigma_E,
this.calculateR_a(this.stringWidth, this.RR.get(i).getValue()),
this.calculateKorr_DRC(),
rewet.get(currentTime)
)
)
);
result.setResultValidTime(currentTime);
result.setValue(this.getModelId().toString(), "DRY_MATTER", dryMatter.toString());
results.add(result);
}
return results;
}
@Override
public ModelId getModelId() {
return GrassDryingModel.MODEL_ID;
}
@Override
public String getModelName() {
return this.getModelName(Model.DEFAULT_LANGUAGE);
}
@Override
public String getModelName(String language) {
return this.getText("name", language);
}
@Override
public String getLicense() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getCopyright() {
return "(c) 2014 Bioforsk (http://www.bioforsk.no/). Contact: post@bioforsk.no";
}
@Override
public String getModelDescription() {
return this.getModelDescription(Model.DEFAULT_LANGUAGE);
}
@Override
public String getModelDescription(String language) {
return this.getText("description", language);
}
@Override
public String getModelUsage() {
return this.getModelUsage(Model.DEFAULT_LANGUAGE);
}
@Override
public String getModelUsage(String language) {
return this.getText("usage", language);
}
@Override
public String getSampleConfig() {
return "{\n" +
"\t\"loginInfo\":{\n" +
"\t\t\"username\":\"example\",\n" +
"\t\t\"password\":\"example\"\n" +
"\t},\n" +
"\t\"modelId\":\"" + MODEL_ID.toString() + "\",\n" +
"\t\"configParameters\":{\n" +
"\t\t\"timeZone\":\"Europe/Oslo\",\n" +
"\t\t\"yield\":750.0,\n" +
"\t\t\"conditioning\":2,\n" +
"\t\t\"stringWidth\":3.0,\n" +
"\t\t\"observations\":[\n" +
"\t\t{\n" +
"\t\t\t\t\"timeMeasured\": \"2014-06-25T00:00:00+02:00\",\n" +
"\t\t\t\t\"elementMeasurementTypeId\":\"TM\",\n" +
"\t\t\t\t\"logIntervalId\":1,\n" +
"\t\t\t\t\"value\":2.937\n" +
"\t\t},\n" +
"\t\t{\n" +
"\t\t\t\t\"timeMeasured\": \"2014-06-25T00:00:00+02:00\",\n" +
"\t\t\t\t\"elementMeasurementTypeId\":\"RR\",\n" +
"\t\t\t\t\"logIntervalId\":1,\n" +
"\t\t\t\t\"value\":0\n" +
"\t\t},\n" +
"\t\t{\n" +
"\t\t\t\t\"timeMeasured\": \"2014-06-25T00:00:00+02:00\",\n" +
"\t\t\t\t\"elementMeasurementTypeId\":\"UM\",\n" +
"\t\t\t\t\"logIntervalId\":1,\n" +
"\t\t\t\t\"value\":0\n" +
"\t\t},\n" +
"\t\t{\n" +
"\t\t\t\t\"timeMeasured\": \"2014-06-25T00:00:00+02:00\",\n" +
"\t\t\t\t\"elementMeasurementTypeId\":\"FM2\",\n" +
"\t\t\t\t\"logIntervalId\":1,\n" +
"\t\t\t\t\"value\":0\n" +
"\t\t},\n" +
"\t\t{\n" +
"\t\t\t\t\"timeMeasured\": \"2014-06-25T00:00:00+02:00\",\n" +
"\t\t\t\t\"elementMeasurementTypeId\":\"Q0\",\n" +
"\t\t\t\t\"logIntervalId\":1,\n" +
"\t\t\t\t\"value\":0\n" +
"\t\t}\n" +
"\t\t]\n" +
"\t}\n" +
"}\n";
}
@Override
public void setConfiguration(ModelConfiguration config) throws ConfigValidationException {
this.initCollections();
ObjectMapper mapper = new ObjectMapper();
// Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
this.yield = (Double) config.getConfigParameter("yield");
// 1 = weak, 2 = strong, 3 = crushed
this.conditioning = (Integer) config.getConfigParameter("conditioning");
if(!this.conditioning.equals(1) && !this.conditioning.equals(2) && !this.conditioning.equals(3))
{
throw new ConfigValidationException("Conditioning may only have values [1,2,3], not " + this.conditioning);
}
this.stringWidth = (Double) config.getConfigParameter("stringWidth");
// private Double yield; // Kgs? Tons?? Per hectar?
// ############ Weather data ##############
// Getting weather data, validating
List<WeatherObservation> observations = mapper.convertValue(config.getConfigParameter("observations"), new TypeReference<List<WeatherObservation>>(){});
for(WeatherObservation o:observations)
{
switch(o.getElementMeasurementTypeId())
{
case WeatherElements.TEMPERATURE_MEAN:
this.TM.add(o);
break;
case WeatherElements.PRECIPITATION:
this.RR.add(o);
break;
case WeatherElements.WIND_SPEED_2M:
this.FM2.add(o);
break;
case WeatherElements.RELATIVE_HUMIDITY:
this.UM.add(o);
break;
case WeatherElements.GLOBAL_RADIATION:
this.Q0.add(o);
break;
default:
// Let it pass in silence
break;
}
}
WeatherUtil wUtil = new WeatherUtil();
try
{
wUtil.isHomogenousTimeSeries(this.TM,this.RR,this.FM2,this.UM,this.Q0);
}
catch(WeatherObservationListException ex)
{
throw new ConfigValidationException(ex.getMessage());
}
}
/**
* Sets up the collections
*/
private void initCollections(){
this.RR = new ArrayList();
this.TM = new ArrayList();
this.UM = new ArrayList();
this.Q0 = new ArrayList();
this.FM2 = new ArrayList();
}
public Map<Date,Double> calculateRewet(List<WeatherObservation> precipitation)
{
Collections.sort(precipitation);
Map<Date,Double> retVal = new HashMap<>();
// Constants
Double Ms_max = 1.5;
Double Mr_max = 0.9; // maximum loosely held surface moisture content
Double Ma_max = 5.0; // maximum absorbed moisture content
Double Gamma = 0.5; // swath areal density of dry matter (0.5-1.0)
Double Ta = 2.8; // Time constant
Double T3 = 1.4; // Time constant for run off of loosely held surface moisture
// Retained values from last iteration
Double previous_q_1 = null,
previous_q_2 = null,
previous_q_3 = null,
previous_Ms = null,
previous_Ma = null,
previous_qr_2 = null,
previous_qr_3 = null,
previous_Mr = null;
for(int i=0;i<precipitation.size();i++)
{
// Calculations
Double I = precipitation.get(i).getValue() * (Mr_max / Ms_max); // Specific rainfall
Double F = 1 - Math.pow(0.4, Gamma / 0.14); // Fraction of rainfall intercepted
Double qr_1 = (1 - F) * I; // Flowrate of non-intercepted
Double q_1 = F * I; // Flowrate of rainwater onto plant
Double Dist = I - q_1 - qr_1; // Not in use, not explained??
Double Ms = i == 0 ? 0 : previous_q_1 - previous_q_2 - previous_q_3 + previous_Ms; //adhered surface moisture content
Double Ma = i == 0 ? 0 : previous_q_3 + previous_Ma;
Double Mr = i == 0 ? 0 : previous_q_2 - previous_qr_2 - previous_qr_3 + previous_Mr;
Double q_2 = Ms < Ms_max ? q_1 : 0;
Double q_3 = Ms > 0 ? Ta * (Ma_max - Ma) : 0;
Double Fr = Mr < Mr_max ? q_2 : 0; //Fraction of rainwater retained as loosely held surface water
Double qr_2 = (1 - Fr) * q_2; // Flowrate of unretained rainwater
Double qr_3 = Mr / T3; // runoff rate of loosely held surface water
Double M_rewet = Ms + Ma + Mr;
retVal.put(precipitation.get(i).getTimeMeasured(), M_rewet);
// Keeping values for next iteration
previous_q_1 = q_1;
previous_q_2 = q_2;
previous_q_3 = q_3;
previous_Ms = Ms;
previous_Ma = Ma;
previous_qr_2 = qr_2;
previous_qr_3 = qr_3;
previous_Mr = Mr;
//System.out.println("[" + i + "/"+precipitation.get(i).getTimeMeasured()+"] RR="+precipitation.get(i).getValue()+",I="+I+",F="+F);
}
return retVal;
}
public Double calculateTS(Double MCWB)
{
return (1-MCWB) * 100;
}
public Double calculateMCWB(Double M)
{
return M / (1 + M);
}
public Double calculateM(Double Me, Double sigma_E, Double R_a, Double Korr_DRC, Double rewet)
{
// Constants
Double MCWBinit = 0.823;
Double M_0 = MCWBinit/(1-MCWBinit);
Double rainWaterEpoFactor = 0.0;
return (M_0 - Me) * Math.exp(-Korr_DRC * (sigma_E - rainWaterEpoFactor * R_a)) + Me + rewet;
}
public Double calculateMe(Double relativeHumidity)
{
return 0.033 + 0.095 * Math.pow(-Math.log(1 - 0.01 * relativeHumidity), 1.5);
}
public Double calculateR_a(Double stringWidth, Double precipitation)
{
return stringWidth * precipitation;
}
public Double calculateE(Double temperature, Double relativeHumidity, Double globalRadiation, Double wind)
{
Double X = (19.8374 * temperature - 0.00831 * Math.pow(temperature, 2)) / (temperature + 273.16);
//System.out.println("X=" + X);
Double Es = 6.1078 * Math.exp(X);
//System.out.println("Es=" + Es);
Double vapourPressure = Es - (Es * relativeHumidity / 100);
//System.out.println("VP=" + vapourPressure);
Double DELTA = 0.443 + 0.0295 * temperature + 0.000665 * Math.pow(temperature, 2) + 0.0000188 * Math.pow(temperature, 3);
//System.out.println("DELTA=" + DELTA);
Double Rn = -20 + 0.63 * globalRadiation;
//System.out.println("Rn=" + Rn);
Double E = (0.0015 * Rn * DELTA + 0.0072 * (1 + 0.54 * wind) * vapourPressure) / (DELTA + 0.66);
return E;
}
public Double calculateKorr_DRC()
{
Double dryingRateCoefficient =
this.conditioning == 1 ? 0.095 :
this.conditioning == 2 ? 0.11 : 0.19;
Double correctionFactor = 44.939 * Math.pow(this.yield, -0.537);
return dryingRateCoefficient * correctionFactor;
}
}
# Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.
#
# This file is part of GrassDryingModel.
# GrassDryingModel 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.
#
# GrassDryingModel 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 GrassDryingModel. If not, see <http://www.gnu.org/licenses/>.
#
description=TODO: Need description
name=Grass drying model
usage=TODO: Add usage
# Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.
#
# This file is part of GrassDryingModel.
# GrassDryingModel 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.
#
# GrassDryingModel 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 GrassDryingModel. If not, see <http://www.gnu.org/licenses/>.
#
description=TODO: Trenger beskrivelse
name=T\u00f8rkefartmodellen
usage=TODO: Legg til bruksanvisning
/*
* Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of GrassDryingModel.
* GrassDryingModel 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.
*
* GrassDryingModel 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 GrassDryingModel. If not, see <http://www.gnu.org/licenses/>.
*
*/
package no.bioforsk.vips.model.grassdryingmodel;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import static junit.framework.Assert.fail;
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;
import no.bioforsk.vips.util.WeatherElements;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.MappingJsonFactory;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
*
* @author Tor-Einar Skog <tor-einar.skog@bioforsk.no>
*/
public class GrassDryingModelTest {
public GrassDryingModelTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
// @Test
// public void hello() {}
@Test
public void testAcceptance()
{
System.out.println("testAcceptance");
try
{
GrassDryingModel instance = new GrassDryingModel();
ModelConfiguration config = this.getConfiguration("/weatherData.json");
config.setConfigParameter("yield", 750.0);
config.setConfigParameter("conditioning", 2);
config.setConfigParameter("stringWidth", 3.0);
instance.setConfiguration(config);
List<Result> results = instance.getResult();
assertEquals(18.01757902,Double.valueOf(results.get(0).getValue(GrassDryingModel.MODEL_ID.toString(), "DRY_MATTER")), 0.0001);
assertEquals(19.16504279,Double.valueOf(results.get(16).getValue(GrassDryingModel.MODEL_ID.toString(), "DRY_MATTER")), 0.0001);
}
catch(ConfigValidationException | ModelExcecutionException ex)
{
fail("Exception: " + ex.getMessage());
}
}
@Test
public void testCalculateE()
{
System.out.println("testCalculateE");
GrassDryingModel instance = new GrassDryingModel();
Double temp = 15.1;
Double relHum = 57.9;
Double wind = 5.8;
Double globRad = 91.3;
double E = instance.calculateE(temp, relHum, globRad, wind);
assertEquals(0.15696349, E, 0.0000001);
}
@Test
public void testCalculateR_a()
{
System.out.println("testCalculateR_a");
GrassDryingModel instance = new GrassDryingModel();
Double prec = 0.0;
Double stringW = 3.0;
assertEquals(0, instance.calculateR_a(stringW, prec), 0.0001);
prec = 0.1;
assertEquals(0.3, instance.calculateR_a(stringW, prec), 0.0001);
}
@Test
public void testCalculateMe()
{
System.out.println("testCalculateMe");
GrassDryingModel instance = new GrassDryingModel();
Double relHum = 57.9;
assertEquals(0.1094434, instance.calculateMe(relHum), 0.001);
}
@Test
public void testCalculateRewet()
{
System.out.println("testCalculateRewet");
GrassDryingModel instance = new GrassDryingModel();
ModelConfiguration config = this.getConfiguration("/weatherData.json");
ObjectMapper mapper = new ObjectMapper();
List<WeatherObservation> observations = mapper.convertValue(config.getConfigParameter("observations"), new TypeReference<List<WeatherObservation>>(){});
List<WeatherObservation> RR = new ArrayList<>();
for(WeatherObservation o:observations)
{
switch(o.getElementMeasurementTypeId())
{
case WeatherElements.PRECIPITATION:
RR.add(o);
break;
default:
// Let it pass in silence
break;
}
}
Collections.sort(RR);
Map<Date, Double> rewet = instance.calculateRewet(RR);
// A couple of random checks
Date testDate = RR.get(4).getTimeMeasured();
Double result = rewet.get(testDate);
assertEquals(0.33417231, result, 0.0000001);
testDate = RR.get(15).getTimeMeasured();
result = rewet.get(testDate);
assertEquals(0.003333411, result, 0.0000001);
}
@Test
public void testCalculateM()
{
System.out.println("testCalculateM");
GrassDryingModel instance = new GrassDryingModel();
Double sigma_E = instance.calculateE(15.1, 57.9, 91.3, 5.8);
Double result = instance.calculateM(instance.calculateMe(57.9), sigma_E, instance.calculateR_a(3.0, 0.0), 0.141288948, 0.0);
assertEquals(4.550135226, result,0.00001);
}
@Test
public void testCalculateTS()
{
System.out.println("testCalculateTS");
GrassDryingModel instance = new GrassDryingModel();
Double result = instance.calculateTS(instance.calculateMCWB(4.468072743));
assertEquals(18.28797909, result, 0.0001);
}
private ModelConfiguration getConfiguration(String fileName)
{
try {
ModelConfiguration config = new ModelConfiguration();
config.setModelId(GrassDryingModel.MODEL_ID.toString());
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Oslo"));
cal.set(2012, Calendar.MARCH, 25, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
//config.setConfigParameter("startDateAscosporeMaturity", cal.getTime());
config.setConfigParameter("timeZone", cal.getTimeZone().getID());
BufferedInputStream inputStream = new BufferedInputStream(this.getClass().getResourceAsStream(fileName));
JsonFactory f = new MappingJsonFactory();
JsonParser jp = f.createJsonParser(inputStream);
JsonNode all = jp.readValueAsTree();
List<WeatherObservation> observations = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
Date firstDate = null;
Date lastDate = null;
if(all.isArray())
{
for(JsonNode node : all){
Date timeMeasured = (Date)mapper.convertValue(node.get("timeMeasured").getTextValue(), new TypeReference<Date>(){});
if(firstDate == null || firstDate.compareTo(timeMeasured) > 0)
{
firstDate = timeMeasured;
}
if(lastDate == null || lastDate.compareTo(timeMeasured) < 0)
{
lastDate = timeMeasured;
}
//System.out.println(node.toString());
WeatherObservation observation = new WeatherObservation();
observation.setTimeMeasured(timeMeasured);
observation.setLogIntervalId(node.get("logIntervalId").getIntValue());
observation.setElementMeasurementTypeId(node.get("elementMeasurementTypeId").getTextValue());
observation.setValue(node.get("value").getDoubleValue());
observations.add(observation);
}
}
else
{
fail("Data input from file is not a JSON array");
}
config.setConfigParameter("observations", observations);
return config;
} catch (IOException ex) {
return null;
}
}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment