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)

/**
 * EffortsMetier.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 EffortsMetier")
public class EffortsMetier implements Export {

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

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

    public String getExportFilename() {
        return "EffortsMetier";
    }
    
    public String getExtensionFilename() {
        return ".csv";
    }
    
    public String getDescription() {
        return _("retourne un tableau strategie;metier;date;effort");
    }

    public void export(SimulationStorage simulation, Writer out) throws Exception {
        MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
        for (MatrixIterator i=mat.iterator(); i.hasNext();) {
            i.next();
            Object [] sems = i.getSemanticsCoordinates();
            Date date = (Date)sems[0];
            Strategy str = (Strategy)sems[1];
            Metier metier = (Metier)sems[2];
            
            double val = i.getValue();
            out.write(str.getName() +";"+ metier.getName() +";"+ date.getDate() +";"+ val +"\n");
        }        
/*
var PDate=Packages.fr.ifremer.nodb.Date;
writeln("debut de export effort");
var dateexport=new Packages.java.util.Date();
var formatteur= new Packages.java.text.SimpleDateFormat();
writeln("heure de debut: "+formatteur.format(dateexport));

var result="";

var finsimu=resultats.getLastDate().getDate();

for (var idate=0;idate<=finsimu;idate++){
	var date=new PDate(idate);
	var matrice=resultats.getMatrix(date, "matriceEffortPerStrategyMet");
	writeln("on a la matrice");
	for (var iiterateur=temp.iterator();iiterateur.next();){
		var coordonnees=iiterateur.getSemanticsCoordinates();
		var metier=coordonnees[1];
		var strat=coordonnees[0];
		capture=iiterateur.getValue();
		result+=strat.getName()+";"+metier.getNom()+";"+idate+";"+capture+"\n";
	}
}

writeln("fin de EffortMetier");
return ""+result;

*/
    }

}
