package exports;

import static org.codelutin.i18n.I18n._;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.Writer;

import org.codelutin.math.matrix.*;

import scripts.ResultName;

import fr.ifremer.isisfish.entities.*;
import fr.ifremer.isisfish.export.Export;
import fr.ifremer.isisfish.types.Date;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.datastore.ResultStorage;

import fr.ifremer.isisfish.util.Doc; // pour pouvoir afficher une aide contextuelle (BUG#1605)

/**
 * VesselMargin.java
 *
 * Created: 23 novembre 2006
 *
 * @author anonymous <anonymous@labs.libre-entreprise.org>
 * @version $Revision: 1.3 $
 *
 * Last update: $Date: 2007-05-24 09:30:07 $
 * by : $Author: bpoussin $
 */
 @Doc(value="do the doc of class VesselMargin")
public class VesselMargin implements Export {

    /** to use log facility, just put in your code: log.info("..."); */
    static private Log log = LogFactory.getLog(VesselMargin.class);

    protected String [] necessaryResult = {
            ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL
    };
    
    public String[] getNecessaryResult() {
        return this.necessaryResult;
    }

    public String getExportFilename() {
        return "BateauProfit";
    }
    
    public String getExtensionFilename() {
        return ".csv";
    }
    
    public String getDescription() {
        return _("cvs out strategy;date;value");
    }

    public void export(SimulationStorage simulation, Writer out) throws Exception {
        MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL);
        for (MatrixIterator i=mat.iterator(); i.hasNext();) {
            i.next();
            Object [] sems = i.getSemanticsCoordinates();
            Date date = (Date)sems[0];
            Strategy str = (Strategy)sems[1];
            
            double val = i.getValue();
            out.write(str.getName() +";"+ date.getDate() +";"+ val +"\n");
        }
            /*
var Parametre=sim.getParametre();
var PDate=Packages.fr.ifremer.nodb.Date;
var finsimu=resultats.getLastDate().getDate();


var result="";
writeln("debut export vesselmargin");
var dateexport=new Packages.java.util.Date();
var formatteur= new Packages.java.text.SimpleDateFormat();
writeln("heure de debut: "+formatteur.format(dateexport));


for (var idate=0;idate<=finsimu;idate++){
	var date=new PDate(idate);
	var matrice=resultats.getMatrix(date, "matriceVesselMarginOverVariableCostsPerStrategyPerVessel");
	for(var iiterateur=matrice.iterator(); iiterateur.next();){
		var coordonnees=iiterateur.getSemanticsCoordinates();
		var str=coordonnees[0];
		result+=str.getName()+";"+idate+";"+iiterateur.getValue()+"\n";
	}
}
writeln("fin export vesselmargin");

return ""+result;
*/
    }

}
