package net.sf.cannagrower.adviser.plantation;
import java.util.Vector;
import net.sf.cannagrower.data.Event;
import net.sf.cannagrower.data.Plantation;
import net.sf.cannagrower.data.event.EnvironmentMediumState;
import net.sf.cannagrower.adviser.Advice;
import net.sf.cannagrower.adviser.Adviser;
import net.sf.cannagrower.i18n.Messages;
import net.sf.orexio.lopf.container.Container;
public class PlantationAdviserSubstrat implements Adviser<Plantation> {
private static double ecMax=2.6;
private static double phMax=6.0;
public Vector<Advice> getAdvices(Plantation plantation) {
Vector<Advice> advices=new Vector<Advice>();
boolean ecTooHigh=false;
boolean phTooHigh=false;
for(Container container:plantation.getEvents()){
Event event=null;
try{event=(Event)container.getData();}
catch(ClassNotFoundException e){Messages.showException(e);}
catch(java.io.IOException e){Messages.showException(e);}
if(event instanceof EnvironmentMediumState){
double ec=Double.valueOf(event.getProperties().getProperty(Messages.eventMediumEc));
double ph=Double.valueOf(event.getProperties().getProperty(Messages.eventMediumPh));
if(ec>=ecMax){ecTooHigh=true;}
if(ph>=phMax){phTooHigh=true;}
if(ecTooHigh && phTooHigh){break;}
}
}
if(ecTooHigh){
Advice advice=new Advice();
advice.setStatus(Advice.statusCritical);
advice.setTitle("ecTooHigh");
advices.add(advice);
}
if(phTooHigh){
Advice advice=new Advice();
advice.setStatus(Advice.statusCritical);
advice.setTitle("phTooHigh");
advices.add(advice);
}
return advices;
}
}