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)

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

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

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

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

    public void export(SimulationStorage simulation, Writer out) throws Exception {
        MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_NO_ACTIVITY);
        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 nonActivite");
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, "nonActivite");
	if (matrice==null){
		matrice=MatrixFactory.create(resultats.getMatrix(new PDate(0),"nonActivite"));
		matrice.mults(0);
	}
	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 nonActivite");
return ""+result;
*/
    }

}
