ECAT.java [src/java/m/ecat] Revision: default Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package m.ecat;
import csip.Config;
import java.util.List;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import rotation_utils.nodes.Rotation;
import rotation_utils.nodes.weps.WEPSManagement;
import rotation_utils.utils.TranslatorException;
import rotation_utils.utils.Urls;
/**
*
* @author Brad
*/
public class ECAT {
private double acres;
private Fuel fuel;
private WEPSManagement management; // all the calculations and data come from a WEPS db so for now it will be a weps management
public double getAcres() {
return acres;
}
public void setAcres(double acres) {
this.acres = acres;
}
public Fuel getFuel() {
return fuel;
}
public void setFuel(Fuel fuel) {
this.fuel = fuel;
}
public void readManagements(JSONObject jrot) throws TranslatorException, JSONException {
Rotation rot;
Urls urls = new Urls();
urls.setOperations(Config.getString("crlmod31.op", "http://csip.engr.colostate.edu:8083/csip-crlmod/d/operation/3.1"));
urls.setCrops(Config.getString("crlmod31.crop", "http://csip.engr.colostate.edu:8083/csip-crlmod/d/crop/3.1"));
urls.setResidue(Config.getString("crlmod31.residue", "http://csip.engr.colostate.edu:8083/csip-crlmod/d/residue/3.1"));
rot = Rotation.deserializeRot(jrot);
management = rot.translateToWEPS(urls);
}
/**
*
* @return total fuel usage per gallon for specified fuel type.
* @throws m.ecat.ECATException
*/
public Double getTotalFuelUsage() throws ECATException{
if(management == null)
throw new ECATException("Missing management. Read in a management first.");
return management.calculateTotalFuelUsage() * fuel.getConversion() * acres;
}
public double[] getIntervalFuelUsage() throws ECATException{
double[] usage;
List<Double> intervalFuels;
if(management == null)
throw new ECATException("Missing management. Read in a management first.");
intervalFuels = management.calculateFuelUsage();
usage = new double[intervalFuels.size()];
for(int i = 0; i< intervalFuels.size();i++){
usage[i] = intervalFuels.get(i) * fuel.getConversion() * acres;
}
return usage;
}
/**
*
* @return total fuel cost in USD
* @throws ECATException
*/
public Double getTotalFuelCost() throws ECATException{
return getTotalFuelUsage() * fuel.getCost();
}
/**
*
* @return fuel cost per interval in USD
* @throws ECATException
*/
public double[] getIntervalFuelCost() throws ECATException{
double[] costs;
double[] usage;
usage = getIntervalFuelUsage();
costs = new double[usage.length];
for(int i = 0; i< usage.length;i++){
costs[i] = usage[i] * fuel.getConversion() * acres * fuel.getCost();
}
return costs;
}
}