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

Refactoring, more input handling

parent 97280c9b
Branches
Tags
No related merge requests found
target/ target/
classes/ classes/
modules/
*~ *~
...@@ -28,25 +28,44 @@ import java.util.Date; ...@@ -28,25 +28,44 @@ import java.util.Date;
public class OptimizationObservation implements Comparable{ public class OptimizationObservation implements Comparable{
private Date date; private Date date;
private float hoyde; private Double height;
private float utviklingstrinn; private Double MSC;
private float NDF; private Double NDF;
private float INDF; private Double INDF;
private float raaprotein; private Double rawProtein;
private float FEm; private Double FEm;
public OptimizationObservation() public OptimizationObservation()
{ {
} }
public OptimizationObservation(
Date date,
Double height,
Double MSC,
Double NDF,
Double INDF,
Double rawProtein,
Double FEm
)
{
this.date = date;
this.height = height;
this.MSC = MSC;
this.NDF = NDF;
this.INDF = INDF;
this.rawProtein = rawProtein;
this.FEm = FEm;
}
/** /**
* Bruker formelen Avling (kg TS/daa) = 34.86 * 0.017h<sup>2</sup> + 10.21h * Bruker formelen Avling (kg TS/daa) = 34.86 * 0.017h<sup>2</sup> + 10.21h
* @return * @return
*/ */
public float getAvling() public Double getAvling()
{ {
return 34.86f + 0.017f * (float) Math.pow(this.getHoyde(), 2) + 10.21f * this.getHoyde(); return 34.86f + 0.017f * (Double) Math.pow(this.getHeight(), 2) + 10.21f * this.getHeight();
} }
@Override @Override
...@@ -77,86 +96,86 @@ public class OptimizationObservation implements Comparable{ ...@@ -77,86 +96,86 @@ public class OptimizationObservation implements Comparable{
} }
/** /**
* @return the hoyde * @return the height
*/ */
public float getHoyde() { public Double getHeight() {
return hoyde; return height;
} }
/** /**
* @param hoyde the hoyde to set * @param height the height to set
*/ */
public void setHoyde(float hoyde) { public void setHeight(Double height) {
this.hoyde = hoyde; this.height = height;
} }
/** /**
* @return the utviklingstrinn * @return the MSC
*/ */
public float getUtviklingstrinn() { public Double getMSC() {
return utviklingstrinn; return MSC;
} }
/** /**
* @param utviklingstrinn the utviklingstrinn to set * @param MSC the MSC to set
*/ */
public void setUtviklingstrinn(float utviklingstrinn) { public void setMSC(Double MSC) {
this.utviklingstrinn = utviklingstrinn; this.MSC = MSC;
} }
/** /**
* @return the NDF * @return the NDF
*/ */
public float getNDF() { public Double getNDF() {
return NDF; return NDF;
} }
/** /**
* @param NDF the NDF to set * @param NDF the NDF to set
*/ */
public void setNDF(float NDF) { public void setNDF(Double NDF) {
this.NDF = NDF; this.NDF = NDF;
} }
/** /**
* @return the INDF * @return the INDF
*/ */
public float getINDF() { public Double getINDF() {
return INDF; return INDF;
} }
/** /**
* @param INDF the INDF to set * @param INDF the INDF to set
*/ */
public void setINDF(float INDF) { public void setINDF(Double INDF) {
this.INDF = INDF; this.INDF = INDF;
} }
/** /**
* @return the raaprotein * @return the rawProtein
*/ */
public float getRaaprotein() { public Double getRawProtein() {
return raaprotein; return rawProtein;
} }
/** /**
* @param raaprotein the raaprotein to set * @param rawProtein the rawProtein to set
*/ */
public void setRaaprotein(float raaprotein) { public void setRawProtein(Double rawProtein) {
this.raaprotein = raaprotein; this.rawProtein = rawProtein;
} }
/** /**
* @return the FEm * @return the FEm
*/ */
public float getFEm() { public Double getFEm() {
return FEm; return FEm;
} }
/** /**
* @param FEm the FEm to set * @param FEm the FEm to set
*/ */
public void setFEm(float FEm) { public void setFEm(Double FEm) {
this.FEm = FEm; this.FEm = FEm;
} }
......
...@@ -21,6 +21,8 @@ package no.bioforsk.vips.model.roughagenutritionmodel; ...@@ -21,6 +21,8 @@ package no.bioforsk.vips.model.roughagenutritionmodel;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
...@@ -80,7 +82,19 @@ public class RoughageNutritionModel implements Model { ...@@ -80,7 +82,19 @@ public class RoughageNutritionModel implements Model {
@Override @Override
public List<Result> getResult() throws ModelExcecutionException { public List<Result> getResult() throws ModelExcecutionException {
RoughageNutritionModelImpl impl = new RoughageNutritionModelImpl(); RoughageNutritionModelImpl impl = new RoughageNutritionModelImpl();
ResultMatrix resultMatrix = impl.beregnModell(TMD, TJM10D, RRD, EPPD, Q0D, firstHarvest, secondHarvest, soilType, cloverShare, optimizationObservations, timeZone); ResultMatrix resultMatrix = impl.beregnModell(
TMD,
TJM10D,
RRD,
EPPD,
Q0D,
firstHarvest,
secondHarvest,
soilType,
cloverShare,
optimizationObservations,
timeZone
);
List<Result> results = new ArrayList<>(); List<Result> results = new ArrayList<>();
...@@ -283,9 +297,10 @@ public class RoughageNutritionModel implements Model { ...@@ -283,9 +297,10 @@ public class RoughageNutritionModel implements Model {
{ {
this.cloverShare = mapper.convertValue(config.getConfigParameter("cloverShare"), Integer.class); this.cloverShare = mapper.convertValue(config.getConfigParameter("cloverShare"), Integer.class);
} }
if(config.getConfigParameter("optimizationObsevations") != null) if(config.getConfigParameter("optimizationInfo") != null)
{ {
this.optimizationObservations = mapper.convertValue(config.getConfigParameter("optimizatioObservations"), new TypeReference<List<OptimizationObservation>>(){}); List<String> optimizationInfo = mapper.convertValue(config.getConfigParameter("optimizationInfo"), new TypeReference<List<String>>(){});
this.optimizationObservations = this.parseOptimizationInfo(optimizationInfo, this.timeZone);
} }
...@@ -437,4 +452,29 @@ public class RoughageNutritionModel implements Model { ...@@ -437,4 +452,29 @@ public class RoughageNutritionModel implements Model {
} }
} }
private List<OptimizationObservation> parseOptimizationInfo(List<String> optimizationInfo, TimeZone timeZone) {
List<OptimizationObservation> retVal = new ArrayList<>();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(timeZone);
for(String line:optimizationInfo)
{
String[] parts = line.split(",");
try
{
OptimizationObservation optObs = new OptimizationObservation(
format.parse(parts[0]), // Date
Double.parseDouble(parts[1]), // Height
Double.parseDouble(parts[2]), // MSC
Double.parseDouble(parts[3]), // FEm
Double.parseDouble(parts[4]), // NDF
Double.parseDouble(parts[5]), // INDF
Double.parseDouble(parts[6]) // Raw protein
);
retVal.add(optObs);
}
catch(ArrayIndexOutOfBoundsException | ParseException ex) {}
}
return retVal;
}
} }
...@@ -2064,7 +2064,7 @@ public class RoughageNutritionModelImpl implements CostFunction{ ...@@ -2064,7 +2064,7 @@ public class RoughageNutritionModelImpl implements CostFunction{
{ {
try { try {
OptimizationObservation observasjon = i.next(); OptimizationObservation observasjon = i.next();
maaltUtviklingstrinn = observasjon.getUtviklingstrinn(); maaltUtviklingstrinn = observasjon.getMSC();
// Tar høyde for at observasjonen ikke inneholder måling av utviklingstrinn // Tar høyde for at observasjonen ikke inneholder måling av utviklingstrinn
if(maaltUtviklingstrinn < 0) if(maaltUtviklingstrinn < 0)
continue; continue;
...@@ -2558,10 +2558,10 @@ public class RoughageNutritionModelImpl implements CostFunction{ ...@@ -2558,10 +2558,10 @@ public class RoughageNutritionModelImpl implements CostFunction{
for(ListIterator<OptimizationObservation> i=this.observasjoner.listIterator();i.hasNext();) for(ListIterator<OptimizationObservation> i=this.observasjoner.listIterator();i.hasNext();)
{ {
OptimizationObservation observasjon = i.next(); OptimizationObservation observasjon = i.next();
if(observasjon.getRaaprotein() > 0 && this.getRaaprotein(observasjon.getDate(), this.jordtype) > 0) if(observasjon.getRawProtein() > 0 && this.getRaaprotein(observasjon.getDate(), this.jordtype) > 0)
{ {
double beregnetNMengde = this.getNMengdeFraRaaprotein(this.getRaaprotein(observasjon.getDate(), this.jordtype), observasjon.getDate(), this.jordtype); double beregnetNMengde = this.getNMengdeFraRaaprotein(this.getRaaprotein(observasjon.getDate(), this.jordtype), observasjon.getDate(), this.jordtype);
double maaltNMengde = this.getNMengdeFraRaaprotein(observasjon.getRaaprotein(), observasjon.getDate(), this.jordtype); double maaltNMengde = this.getNMengdeFraRaaprotein(observasjon.getRawProtein(), observasjon.getDate(), this.jordtype);
differanseMellomMaaltOgSimulertNMengde = maaltNMengde - beregnetNMengde; differanseMellomMaaltOgSimulertNMengde = maaltNMengde - beregnetNMengde;
...@@ -2570,7 +2570,7 @@ public class RoughageNutritionModelImpl implements CostFunction{ ...@@ -2570,7 +2570,7 @@ public class RoughageNutritionModelImpl implements CostFunction{
while(i.hasNext() && grenseDato == null) while(i.hasNext() && grenseDato == null)
{ {
OptimizationObservation tmp = i.next(); OptimizationObservation tmp = i.next();
if(tmp.getRaaprotein() > 0 && this.getRaaprotein(tmp.getDate(), this.jordtype) > 0) if(tmp.getRawProtein() > 0 && this.getRaaprotein(tmp.getDate(), this.jordtype) > 0)
grenseDato = tmp.getDate(); grenseDato = tmp.getDate();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment