/*
 * #%L
 * IsisFish data
 * %%
 * Copyright (C) 2014 Ifremer, Code Lutin, Chatellier Eric
 * %%
 * 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 scripts;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import org.nuiton.topia.TopiaException;

import exports.Abundance_ExportEnd;
import exports.Biomasse_ExportEnd;
import exports.MortalitePecheGroupe;
import exports.Landings_ExportEnd;
import exports.GrossValues_ExportEnd;
import exports.Discards_ExportEnd;
import exports.CatchWeightSpStrYear;
import exports.CapturesPoids_exportEnd;
import exports.MortalitePecheTotale;
import exports.Discards_AgeStructure;
import exports.Captures_AgeStructure;
import exports.Landings_AgeStructure;
import exports.Landings_month;
import exports.RegionDefinition;
import exports.Captures_AgeStructure_month;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.simulator.*;
import fr.ifremer.isisfish.export.Export;
import fr.ifremer.isisfish.export.ExportHelper;

/**
 * Ce script sert à rejouer des exports sur un grand nombre de simulation en lisant le
 * ResultStrage et en rejouant les fonctions d'export.
 * 
 * Ce script peut être lancé via l'option "Evaluer" depuis l'interface des scripts d'Isis.
 * 
 * @author Eric Chatellier
 */
public class RunExportOnManySimulationResult {

    // nom des exports a rejouer (à modifier selon le besoin)
    protected List<Export> exports = Arrays.asList(

        //new Discards_AgeStructure(),
        new Captures_AgeStructure()
        //new Landings_AgeStructure()
        //new Landings_month(),
        //new Captures_AgeStructure_month()
        //new RegionDefinition()
    );

    public void doAllExports() throws TopiaException {
        // prefix des noms de simulations (à configurer)
        String simulationPrefix = "sim_DiscardLessRome_2017-03-10-14-57_";//"sim_DiscardLessRome0_2017-02-22-13-06_";
        int simulationCount = 11;

        // parcourt de chaque simualtion
        for (int index = 0; index <= simulationCount; index++) {
            
            // get current simulation
            String currentSimulationName = simulationPrefix + index;
            SimulationStorage currentSimulation = SimulationStorage.getSimulation(currentSimulationName);

            // temp fix for matrix semantics decorations (no opened transaction)
            SimulationContext.get().setSimulationStorage(currentSimulation);

            // run each export for this simulation
            File rootDirectory = currentSimulation.getDirectory();
            File exportDir = SimulationStorage.getResultExportDirectory(rootDirectory);
            ExportHelper.doExport(currentSimulation, exportDir, exports, rootDirectory);
            System.out.println("Exports done on simulation " + currentSimulationName);
            
            // close all
            currentSimulation.closeStorage();
        }
    }

    public static void main(String[] args) throws TopiaException {
        RunExportOnManySimulationResult runExportJob = new RunExportOnManySimulationResult();
        runExportJob.doAllExports();
    }
}
