Author: jcouteau Date: 2019-01-24 10:55:28 +0100 (Thu, 24 Jan 2019) New Revision: 57 Url: http://forge.codelutin.com/projects/isis-fish-community/repository/revisions... Log: Update Mortalite exports Modified: trunk/exports/MortalitePecheGroupe.java trunk/exports/MortalitePecheTotale.java Modified: trunk/exports/MortalitePecheGroupe.java =================================================================== --- trunk/exports/MortalitePecheGroupe.java 2018-04-05 08:47:25 UTC (rev 56) +++ trunk/exports/MortalitePecheGroupe.java 2019-01-24 09:55:28 UTC (rev 57) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2018 Ifremer, CodeLutin + * Copyright (C) 2006 - 2013 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 @@ -28,14 +28,12 @@ import org.nuiton.math.matrix.*; -import resultinfos.MatrixAbundance; -import resultinfos.MatrixCatchPerStrategyMetPerZonePop; -import resultinfos.MatrixFishingMortalityPerGroup; - import fr.ifremer.isisfish.entities.*; -import fr.ifremer.isisfish.export.Export; +import fr.ifremer.isisfish.export.ExportStep; import fr.ifremer.isisfish.types.TimeStep; +import fr.ifremer.isisfish.types.Month; import fr.ifremer.isisfish.datastore.SimulationStorage; +import resultinfos.*; /** * FishingMortality.java @@ -47,15 +45,13 @@ * * Last update: $Date: 0000-00-00 00:00:00 $ by : $Author: $ */ -public class MortalitePecheGroupe implements Export { +public class MortalitePecheGroupe implements ExportStep{ /** to use log facility, just put in your code: log.info("..."); */ static private Log log = LogFactory.getLog(MortalitePecheGroupe.class); - protected String[] necessaryResult = { - MatrixFishingMortalityPerGroup.NAME, - MatrixCatchPerStrategyMetPerZonePop.NAME, - MatrixAbundance.NAME + protected String[] necessaryResult = { + MatrixFishingMortalityPerGroup.NAME }; @Override @@ -79,31 +75,28 @@ } @Override - public void export(SimulationStorage simulation, Writer out) - throws Exception { - TimeStep lastStep = simulation.getResultStorage().getLastStep(); - - for (Population pop : simulation.getParameter().getPopulations()) { -// for (PopulationGroup group : pop.getPopulationGroup()) { // Rajouter une boucle sur les groupes ?? - for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step.next()) { - - MatrixND mat = simulation.getResultStorage().getMatrix(step, - pop, MatrixFishingMortalityPerGroup.NAME); // group - - if (mat != null) { // can be null if simulation is stopped before last year simulation - for (MatrixIterator i = mat.iterator(); i.hasNext();) { - i.next(); - Object[] sems = i.getSemanticsCoordinates(); - PopulationGroup group = (PopulationGroup)sems[1]; - double val = i.getValue(); - - out.write(pop.getName() + ";" + step.getStep() + ";" + group.getAge() + ";" + val + "\n"); // + ";" + group.getAge() - } - } - } - //} - } - } - } - - + public void exportBegin(SimulationStorage simulation, Writer out) throws Exception { + out.write("population;step;group;value\n"); + } + + @Override + public void export(SimulationStorage simulation, TimeStep step, Writer out) throws Exception { + if (step.getMonth()== Month.DECEMBER){ // F is calculated for a whole year in december. + for (Population pop : simulation.getParameter().getPopulations()) { + MatrixND mat = simulation.getResultStorage().getMatrix(step,pop, MatrixFishingMortalityPerGroup.NAME); // group + if (mat != null) { // can be null if simulation is stopped before last year simulation + for (MatrixIterator i = mat.iterator(); i.hasNext();) { + i.next(); + Object[] sems = i.getSemanticsCoordinates(); + double val = i.getValue(); + PopulationGroup group = (PopulationGroup)sems[0]; + out.write(pop.getName() + ";" + step.getStep() + ";" + group.getId() + ";" + val + "\n"); + } + } + } + } + } + @Override + public void exportEnd(SimulationStorage simulation, Writer out) throws Exception { + } +} \ No newline at end of file Modified: trunk/exports/MortalitePecheTotale.java =================================================================== --- trunk/exports/MortalitePecheTotale.java 2018-04-05 08:47:25 UTC (rev 56) +++ trunk/exports/MortalitePecheTotale.java 2019-01-24 09:55:28 UTC (rev 57) @@ -1,107 +1,105 @@ -/* - * #%L - * IsisFish data - * %% - * Copyright (C) 2006 - 2018 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 2 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 - * <http://www.gnu.org/licenses/gpl-2.0.html>. - * #L% - */ -package exports; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.io.Writer; - -import org.nuiton.math.matrix.*; - -import resultinfos.MatrixAbundance; -import resultinfos.MatrixCatchPerStrategyMetPerZonePop; -import resultinfos.MatrixFishingMortalityPerGroup; -import resultinfos.MatrixTotalFishingMortality; - -import fr.ifremer.isisfish.entities.*; -import fr.ifremer.isisfish.export.Export; -import fr.ifremer.isisfish.types.TimeStep; -import fr.ifremer.isisfish.datastore.SimulationStorage; - -/** - * FishingMortality.java - * - * Created: 19 Avril 2012 - * - * @author anonymous <anonymous@labs.libre-entreprise.org> - * @version $Revision: 0.1 $ - * - * Last update: $Date: 0000-00-00 00:00:00 $ by : $Author: $ - */ -public class MortalitePecheTotale implements Export { - - /** to use log facility, just put in your code: log.info("..."); */ - static private Log log = LogFactory.getLog(MortalitePecheTotale.class); - - protected String[] necessaryResult = { - MatrixTotalFishingMortality.NAME, - MatrixFishingMortalityPerGroup.NAME, - MatrixCatchPerStrategyMetPerZonePop.NAME, - MatrixAbundance.NAME - }; - - @Override - public String[] getNecessaryResult() { - return this.necessaryResult; - } - - @Override - public String getExportFilename() { - return "MortalitePecheTotale"; - } - - @Override - public String getExtensionFilename() { - return ".csv"; - } - - @Override - public String getDescription() { - return "Exporte la mortalite par peche totale de la simulation par population (Fpop par an calcule en decembre)"; - } - - @Override - public void export(SimulationStorage simulation, Writer out) - throws Exception { - TimeStep lastStep = simulation.getResultStorage().getLastStep(); - - for (Population pop : simulation.getParameter().getPopulations()) { - for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step.next()) { - - MatrixND mat = simulation.getResultStorage().getMatrix(step, - pop, MatrixTotalFishingMortality.NAME); - - if (mat != null) { // can be null if simulation is stopped before last year simulation - for (MatrixIterator i = mat.iterator(); i.hasNext();) { - i.next(); - double val = i.getValue(); - - out.write(pop.getName() + ";" + step.getStep() + ";" + val + "\n"); - } - } - } - } - } -} - - +/* + * #%L + * IsisFish data + * %% + * Copyright (C) 2006 - 2011 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 2 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 + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * #L% + */ +package exports; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.Writer; + +import org.nuiton.math.matrix.*; + +import fr.ifremer.isisfish.entities.*; +import fr.ifremer.isisfish.export.ExportStep; +import fr.ifremer.isisfish.types.TimeStep; +import fr.ifremer.isisfish.types.Month; +import fr.ifremer.isisfish.datastore.SimulationStorage; + +import resultinfos.*; + +/** + * FishingMortality.java + * + * Created: 19 Avril 2012 + * + * @author anonymous <anonymous@labs.libre-entreprise.org> + * @version $Revision: 0.1 $ + * + * Last update: $Date: 0000-00-00 00:00:00 $ by : $Author: $ + */ +public class MortalitePecheTotale implements ExportStep { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory.getLog(MortalitePecheTotale.class); + + protected String[] necessaryResult = { + MatrixTotalFishingMortality.NAME + }; + + @Override + public String[] getNecessaryResult() { + return this.necessaryResult; + } + + @Override + public String getExportFilename() { + return "MortalitePecheTotale"; + } + + @Override + public String getExtensionFilename() { + return ".csv"; + } + + @Override + public String getDescription() { + return "Exporte la mortalite par peche totale de la simulation par population (Fpop par an calcule en decembre)"; + } + + @Override + public void exportBegin(SimulationStorage simulation, Writer out) throws Exception { + out.write("population;step;value\n"); + } + + @Override + public void export(SimulationStorage simulation,TimeStep step, Writer out) throws Exception { + if (step.getMonth()== Month.DECEMBER){ // F is calculated for a whole year in december. + TimeStep lastStep = simulation.getResultStorage().getLastStep(); + for (Population pop : simulation.getParameter().getPopulations()){ + MatrixND mat = simulation.getResultStorage().getMatrix(step,pop, MatrixTotalFishingMortality.NAME); + if (mat != null) { // can be null if simulation is stopped before last year simulation + for (MatrixIterator i = mat.iterator(); i.hasNext();) { + i.next(); + double val = i.getValue(); + out.write(pop.getName() + ";" + step.getStep() + ";" + val + "\n"); + } + } + } + } + } + + @Override + public void exportEnd(SimulationStorage simulation, Writer out) throws Exception { + } +} + +