/* * #%L * IsisFish data * %% * Copyright (C) 2006 - 2016 Ifremer, CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * . * #L% */ package exports; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.entities.Metier; import fr.ifremer.isisfish.entities.Population; import fr.ifremer.isisfish.entities.PopulationGroup; import fr.ifremer.isisfish.entities.Zone; import fr.ifremer.isisfish.export.ExportStep; import fr.ifremer.isisfish.types.TimeStep; import resultinfos.MatrixCatchWeightPerStrategyMetPerZonePop; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.math.matrix.MatrixIterator; import org.nuiton.math.matrix.MatrixND; import java.io.Writer; /** * CatchYear.java * * Export des captures en poids de la forme : * Pas de temps ; Population ; M��tier ; Groupe ; Zone ; Valeur */ public class CatchYear implements ExportStep { /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(CatchYear.class); protected String[] necessaryResult = { MatrixCatchWeightPerStrategyMetPerZonePop.NAME }; @Override public String[] getNecessaryResult() { return this.necessaryResult; } @Override public String getExportFilename() { return "CatchYear"; } @Override public String getExtensionFilename() { return ".csv"; } @Override public String getDescription() { return "Export les captures en poids de la simulation. tableau step;pop;value"; } @Override public void exportBegin(SimulationStorage simulation, Writer out) throws Exception { out.write("step;population;value\n"); } @Override public void export(SimulationStorage simulation, TimeStep step, Writer out) throws Exception { for (Population pop : simulation.getParameter().getPopulations()) { MatrixND mat = simulation.getResultStorage().getMatrix(step, pop, MatrixCatchWeightPerStrategyMetPerZonePop.NAME); mat = mat.sumOverDim(0,12) //sum by year .sumOverDim(1) //sum on strategy .sumOverDim(2) //sum on metier .sumOverDim(3) //sum on groups .sumOverDim(4) //sum on zones .reduce(); for (MatrixIterator i = mat.iterator(); i.hasNext();) { i.next(); Object[] sems = i.getSemanticsCoordinates(); double val = i.getValue(); out.write(step.getStep() + ";" + pop.getName() + ";" + val + "\n"); } } } @Override public void exportEnd(SimulationStorage simulation, Writer out) throws Exception { } }