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

Refactoring Result object

parent 30872ede
No related branches found
No related tags found
No related merge requests found
......@@ -96,6 +96,11 @@
<artifactId>renjin-script-engine</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
</dependency>
</dependencies>
<repositories>
<repository>
......
/*
* Copyright (c) 2017 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSCommon.
* VIPSCommon is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* VIPSCommon 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
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with VIPSCommon. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.entity;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import no.nibio.vips.gis.SimpleWGS84Coordinate;
/**
* @copyright 2017 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class MultiPointWeatherObservationList {
private SimpleWGS84Coordinate coordinate;
private List<WeatherObservation> observations;
@JsonCreator
public MultiPointWeatherObservationList(
@JsonProperty("coordinate") SimpleWGS84Coordinate coordinate,
@JsonProperty("observations") List<WeatherObservation> observations
)
{
this.coordinate = coordinate;
this.observations = observations;
}
/**
* @return the coordinate
*/
public SimpleWGS84Coordinate getCoordinate() {
return coordinate;
}
/**
* @param coordinate the coordinate to set
*/
public void setCoordinate(SimpleWGS84Coordinate coordinate) {
this.coordinate = coordinate;
}
/**
* @return the observations
*/
public List<WeatherObservation> getObservations() {
return observations;
}
/**
* @param observations the observations to set
*/
public void setObservations(List<WeatherObservation> observations) {
this.observations = observations;
}
}
......@@ -23,6 +23,7 @@ import java.util.Date;
import java.util.Map;
import java.util.Set;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.vividsolutions.jts.geom.Geometry;
/**
......@@ -40,11 +41,16 @@ public interface Result extends Comparable{
public final static Integer WARNING_STATUS_HIGH_RISK = 4;
/* Time for which these results are valid */
public void setResultValidTime(Date time);
public Date getResultValidTime();
public void setValidTimeStart(Date time);
public Date getValidTimeStart();
public void setValidTimeEnd(Date time);
public Date getValidTimeEnd();
// Spatial validity
public void setValidGeometry(Geometry geometry);
public Geometry getValidGeometry();
/* The result parameters in this Result object */
public void setKeys(Set<String> keys);
public Set<String> getKeys();
/* Setting and getting values */
......
/*
* Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
* Copyright (c) 2017 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSCommon.
* VIPSCommon is free software: you can redistribute it and/or modify
......@@ -19,6 +19,7 @@
package no.nibio.vips.entity;
import com.vividsolutions.jts.geom.Geometry;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
......@@ -29,33 +30,28 @@ import java.util.TimeZone;
/**
* Represents a result
* @copyright 2013 <a href="http://www.nibio.no">NIBIO</a>
* @copyright 2013-2017 <a href="http://www.nibio.no">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class ResultImpl implements Result{
private Date resultValidTime;
private Set<String> keys;
private Date validTimeStart, validTimeEnd;
private Geometry validGeometry;
private Map<String, String> values;
private Integer warningStatus;
@Override
public void setResultValidTime(Date time) {
this.resultValidTime = time;
public void setValidTimeStart(Date time) {
this.validTimeStart = time;
}
@Override
public Date getResultValidTime() {
return this.resultValidTime;
}
@Override
public void setKeys(Set<String> keys) {
this.keys = keys;
public Date getValidTimeStart() {
return this.validTimeStart;
}
@Override
public Set<String> getKeys() {
return this.values != null ? this.values.keySet() : new HashSet<String>();
return this.values != null ? this.values.keySet() : new HashSet<>();
}
@Override
......@@ -73,7 +69,7 @@ public class ResultImpl implements Result{
@Override
public Map<String, String> getAllValues() {
return this.values != null ? this.values : new HashMap<String,String>();
return this.values != null ? this.values : new HashMap<>();
}
@Override
......@@ -88,7 +84,7 @@ public class ResultImpl implements Result{
*/
@Override
public int compareTo(Object t) {
return this.getResultValidTime().compareTo(((Result) t).getResultValidTime());
return this.getValidTimeStart().compareTo(((Result) t).getValidTimeStart());
}
@Override
......@@ -105,7 +101,7 @@ public class ResultImpl implements Result{
public String toString(){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
String retVal = "[" + format.format(resultValidTime) + "], WARNING_STATUS=" + this.getWarningStatus() + ", ";
String retVal = "[" + format.format(validTimeStart) + "], WARNING_STATUS=" + this.getWarningStatus() + ", ";
if(this.getKeys() != null)
{
for(String key: this.getKeys())
......@@ -119,4 +115,36 @@ public class ResultImpl implements Result{
}
return retVal;
}
/**
* @return the validTimeEnd
*/
@Override
public Date getValidTimeEnd() {
return validTimeEnd != null ? this.validTimeEnd : this.validTimeStart;
}
/**
* @param validTimeEnd the validTimeEnd to set
*/
@Override
public void setValidTimeEnd(Date validTimeEnd) {
this.validTimeEnd = validTimeEnd;
}
/**
* @return the validGeometry
*/
@Override
public Geometry getValidGeometry() {
return validGeometry;
}
/**
* @param validGeometry the validGeometry to set
*/
@Override
public void setValidGeometry(Geometry validGeometry) {
this.validGeometry = validGeometry;
}
}
/*
* Copyright (c) 2017 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSCommon.
* VIPSCommon is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* VIPSCommon 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
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with VIPSCommon. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.gis;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* This is for multi point data serialization purposes
* @copyright 2017 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class SimpleWGS84Coordinate {
private Double latitude, longitude, altitude;
@JsonCreator
public SimpleWGS84Coordinate(
@JsonProperty("latitude") Double latitude,
@JsonProperty("longitude") Double longitude,
@JsonProperty("altitude") Double altitude
)
{
this.latitude = latitude;
this.longitude = longitude;
this.altitude = altitude;
}
public SimpleWGS84Coordinate(Double latitude, Double longitude)
{
this(latitude, longitude, null);
}
/**
* @return the latitude
*/
public Double getLatitude() {
return latitude;
}
/**
* @param latitude the latitude to set
*/
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
/**
* @return the longitude
*/
public Double getLongitude() {
return longitude;
}
/**
* @param longitude the longitude to set
*/
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
/**
* @return the altitude
*/
public Double getAltitude() {
return altitude;
}
/**
* @param altitude the altitude to set
*/
public void setAltitude(Double altitude) {
this.altitude = altitude;
}
@Override
public String toString()
{
return this.getClass().getName() + " lat=" + this.getLatitude() + ", lon=" + this.getLongitude() + ", alt=" + this.getAltitude();
}
}
......@@ -19,9 +19,9 @@
package no.nibio.vips.model;
import no.nibio.vips.entity.Result;
import java.util.List;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.Result;
/**
* All models must implement this interface
......
......@@ -27,11 +27,11 @@ import com.fasterxml.jackson.databind.MappingJsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.MultiPointWeatherObservationList;
import no.nibio.vips.entity.WeatherObservation;
import no.nibio.vips.model.ConfigValidationException;
......@@ -98,4 +98,34 @@ public class WeatherDataFileReader {
throw new ConfigValidationException(ex.getMessage());
}
}
/**
*
*
* @param weatherDataFileName filename and path on classpath
* @param modelId 10 chars ID of model
* @return A Model Configuration with weather data. Can be filled with other configuration data
* @throws ConfigValidationException
*/
public ModelConfiguration getModelConfigurationWithMultiPointWeatherObservationList(String weatherDataFileName, String modelId) throws ConfigValidationException
{
try {
ModelConfiguration config = new ModelConfiguration();
config.setModelId(modelId);
BufferedInputStream inputStream = new BufferedInputStream(this.getClass().getResourceAsStream(weatherDataFileName));
JsonFactory f = new MappingJsonFactory();
JsonParser jp = f.createParser(inputStream);
JsonNode all = jp.readValueAsTree();
List<WeatherObservation> observations = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
List<MultiPointWeatherObservationList> theList = mapper.convertValue(all, new TypeReference<List<MultiPointWeatherObservationList>>(){});
config.setConfigParameter("multiPointWeatherObservations", theList);
return config;
} catch (IOException ex) {
ex.printStackTrace();
throw new ConfigValidationException(ex.getMessage());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment