Skip to content

Commit

Permalink
Cleanup chain of calling executor.start by ComputationManager
Browse files Browse the repository at this point in the history
  • Loading branch information
yichen88 committed Sep 6, 2017
1 parent 0a8e915 commit 79ac300
Showing 1 changed file with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
Expand Down Expand Up @@ -106,41 +107,42 @@ public void run(TimeHorizon timeHorizon) throws Exception {
throw new RuntimeException("Forecast errors data for " + parameters.getFeAnalysisId() + " analysis and " + timeHorizon.getName() + " time horizon already exists");
}

try (CommandExecutor executor = computationManager.newCommandExecutor(
createEnv(), WORKING_DIR_PREFIX, config.isDebug())) {

final Path workingDir = executor.getWorkingDir();

// get forecast errors historical data from histodb
Path historicalDataCsvFile = workingDir.resolve(FEACSVFILENAME);
FEAHistoDBFacade.historicalDataToCsvFile(histoDbClient,
generatorsIds,
loadsIds,
parameters.getHistoInterval(),
historicalDataCsvFile);

//Path historicalDataCsvFile = Paths.get("/itesla_data/MAT", "forecastsDiff_7nodes.csv");
ForecastErrorsHistoricalData forecastErrorsHistoricalData = new HistoricalDataCreator(network, generatorsIds, loadsIds)
.createForecastErrorsHistoricalData(historicalDataCsvFile);
Path historicalDataMatFile = Paths.get(workingDir.toString(), FEAINPUTFILENAME);
new FEAMatFileWriter(historicalDataMatFile).writeHistoricalData(forecastErrorsHistoricalData);

LOGGER.info("Running forecast errors analysis for {} network, {} time horizon", network.getId(), timeHorizon.getName());
ExecutionReport report = executor.start(new CommandExecution(createMatm1Cmd(historicalDataMatFile), 1, Integer.MAX_VALUE));
report.log();
if (report.getErrors().isEmpty()) {
report = executor.start(new CommandExecution(createMatm2Cmd(), parameters.getnClusters(), Integer.MAX_VALUE));
report.log();
if (report.getErrors().isEmpty()) {
report = executor.start(new CommandExecution(createMatm2reduceCmd(), 1, Integer.MAX_VALUE));
report.log();
if (report.getErrors().isEmpty()) {
report = executor.start(new CommandExecution(createMatm3Cmd(), 1, Integer.MAX_VALUE));
report.log();
}
}
}

ExecutionEnvironment executionEnvironment = new ExecutionEnvironment(createEnv(), WORKING_DIR_PREFIX, config.isDebug());
computationManager.execute(executionEnvironment, new AbstractExecutionHandler<Void>() {
@Override
public List<CommandExecution> before(Path workingDir) throws IOException {
// get forecast errors historical data from histodb
Path historicalDataCsvFile = workingDir.resolve(FEACSVFILENAME);
try {
FEAHistoDBFacade.historicalDataToCsvFile(histoDbClient,
generatorsIds,
loadsIds,
parameters.getHistoInterval(),
historicalDataCsvFile);
} catch (Exception e) {
throw new RuntimeException(e);
}
//Path historicalDataCsvFile = Paths.get("/itesla_data/MAT", "forecastsDiff_7nodes.csv");
ForecastErrorsHistoricalData forecastErrorsHistoricalData = new HistoricalDataCreator(network, generatorsIds, loadsIds)
.createForecastErrorsHistoricalData(historicalDataCsvFile);
Path historicalDataMatFile = Paths.get(workingDir.toString(), FEAINPUTFILENAME);
new FEAMatFileWriter(historicalDataMatFile).writeHistoricalData(forecastErrorsHistoricalData);
return Arrays.asList(new CommandExecution(createMatm1Cmd(historicalDataMatFile), 1, Integer.MAX_VALUE),
new CommandExecution(createMatm2Cmd(), parameters.getnClusters(), Integer.MAX_VALUE),
new CommandExecution(createMatm2reduceCmd(), 1, Integer.MAX_VALUE),
new CommandExecution(createMatm3Cmd(), 1, Integer.MAX_VALUE));
}

@Override
public void onExecutionStart(CommandExecution execution, int executionIndex) {
if (executionIndex == 0) {
LOGGER.info("Running forecast errors analysis for {} network, {} time horizon", network.getId(), timeHorizon.getName());
}
}

@Override
public Void after(Path workingDir, ExecutionReport report) throws IOException {
report.log();
/*
//fake start
//M1OUTPUTFILENAME M0OUTPUTFILENAME M0OUTPUTFILENAMECSV GUIOUTPUTFILENAME
Expand All @@ -156,12 +158,14 @@ public void run(TimeHorizon timeHorizon) throws Exception {
report.log();
//fake end
*/
// store forecast errors data, offline sampling, statistics and uncertainties data for the GUI
forecastErrorsDataStorage.storeForecastErrorsFiles(parameters.getFeAnalysisId(), timeHorizon, workingDir.resolve(FEAOUTPUTFILENAME), workingDir.resolve(FEASAMPLERFILENAME), workingDir.resolve(M0OUTPUTFILENAMECSV), workingDir.resolve(GUIOUTPUTFILENAME));
// store analysis parameters
forecastErrorsDataStorage.storeParameters(parameters.getFeAnalysisId(), timeHorizon, parameters);
}
}
// store forecast errors data, offline sampling, statistics and uncertainties data for the GUI
forecastErrorsDataStorage.storeForecastErrorsFiles(parameters.getFeAnalysisId(), timeHorizon, workingDir.resolve(FEAOUTPUTFILENAME), workingDir.resolve(FEASAMPLERFILENAME), workingDir.resolve(M0OUTPUTFILENAMECSV), workingDir.resolve(GUIOUTPUTFILENAME));
// store analysis parameters
forecastErrorsDataStorage.storeParameters(parameters.getFeAnalysisId(), timeHorizon, parameters);
return null;
}
});
}

//function exitcode=FEA_MODULE1_HELPER(ifile, ofile,natS,ofile_forFPF,ofileGUI, IRs, Ks, s_flagPQ,s_method,tolvar,Nmin_obs_fract,Nmin_obs_interv,outliers,koutlier,imputation_meth,Ngaussians,percentile_historical,check_module0,toleranceS,iterationsS,epsiloS,conditional_samplingS,histo_estremeQs,thresGUIs,s_rng_seed)

Expand Down

0 comments on commit 79ac300

Please sign in to comment.