Salut les lutins

pourriez vous regarder et corriger le script EffortNominalMetiersYear.java pour qu'il somme correctement les efforts sur la premiere dimension sur les 12 mois de chaque année ?

Actuellement ce codefait une somme cumulée sur les mois de chaque année et rajoute des valeurs ( une ligne par pas de temps simulé avec la valeur cumulee sur le dernier mois).

Merci

Bon we

Stephanie

Le 11/09/2024 à 12:38, P.-Y. Hernvann a écrit :
Hello
Sigrid et moi voulons récupérer les séries temporelles d'effort nominal total annuel par stratégie et métier.
On a ce script d'export collé ci-dessous, qui devrait nous retourner une ligne par an/strategie/metier mais nous en genere un fichier (1) avec autant de lignes qu'il y a de mois et (2) dont la somme des valeurs sur l'annee n'est pas coherent avec ce qu'on trouve dans la table MatrixEffortNominalPerStrategyMet (une fois somme sur l'annee realisee par strategie/metier realisee).
Une idee ?
PY

code:

/*
 * Copyright (C) 2024 pyhernva
 *
 * 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
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 */
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.*;

import fr.ifremer.isisfish.annotations.Doc;
import fr.ifremer.isisfish.entities.*;
import fr.ifremer.isisfish.export.ExportStep;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.simulator.ResultManager;
import fr.ifremer.isisfish.types.TimeStep;

/**
 * EffortNominalMetiersYear.java
 */
public class EffortNominalMetiersYear implements ExportStep {

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

    protected String [] necessaryResult = {
        MatrixEffortNominalPerStrategyMet.NAME
    };

    @Override
    public String[] getNecessaryResult() {
        return this.necessaryResult;
    }

    @Override
    public String getExportFilename() {
        return "EffortsNominalMetierYear";
    }

    @Override
    public String getExtensionFilename() {
        return ".csv";
    }

    @Override
    public String getDescription() {
        return "retourne un tableau year;strategie;metier;effort";
    }

    /*@Override
    public void export(SimulationStorage simulation, Writer out) throws Exception {
        MatrixND mat = simulation.getResultStorage().getMatrix(MatrixEffortPerStrategyMet.NAME);
        for (MatrixIterator i = mat.iterator(); i.hasNext();) {
            i.next();
            Object [] sems = i.getSemanticsCoordinates();
            TimeStep step = (TimeStep)sems[0];
            Strategy str = (Strategy)sems[1];
            Metier metier = (Metier)sems[2];

            double val = i.getValue();
            out.write(str.getName() +";"+ metier.getName() +";"+ step.getStep() +";"+ val +"\n");
        }
    }*/

    @Override
    public void exportBegin(SimulationStorage simulation, Writer out) throws Exception {
        out.write("year;strategy;metier;value\n");
    }

    @Override
    public void export(SimulationStorage simulation, TimeStep step, Writer out) throws Exception {
        MatrixND mat = simulation.getResultStorage().getMatrix(MatrixEffortNominalPerStrategyMet.NAME);

        if (mat != null) {

            mat = mat.sumOverDim(0,12); //sum per year

            for (MatrixIterator i = mat.iterator(); i.hasNext();) {

                i.next();
                Object [] sems = i.getSemanticsCoordinates();
                int year = (int) sems[0];
                Strategy str = (Strategy)sems[1];
                Metier metier = (Metier)sems[2];

                double val = i.getValue();
                if(val!=0){
                out.write(year +";" + str.getName() + ";" + metier.getName() + ";" + val + "\n");
                }
            }
       }
    }

    @Override
    public void exportEnd(SimulationStorage simulation, Writer out) throws Exception {

    }
}



-- 
......................................................................
Stephanie MAHEVAS
UMR DECOD (Dynamique et durabilité des écosystèmes : de la source à l'océan)
IFREMER/HALGO/EMH (Ecologie et Modèles pour l'Halieutique)  
https://annuaire.ifremer.fr/cv/16343/

 Tel: (33) 2 40 37 41 81 - 06 75 83 59 33

    o   \ o /  _ o         __|    \ /     |__        o _  \ o /   o
   /|\    |     /\   ___\o   \o    |    o/    o/__   /\     |    /|\
   / \   / \   | \  /)  |    ( \  /o\  / )    |  (\  / |   / \   / \
......................................................................