Version: AFRY Intelligent Scenario Modelling 8.5 or higher
This is a simple script to ilustrate how to read values from the results.
Copy the code bellow and save it as ManageResultsScript.java. You can try this script with the model created in the Tutorial 5.
import javax.swing.JOptionPane;
import se.facilia.ism.domain.OutputReference;
import se.facilia.ism.domain.model.ISMProject;
import se.facilia.ism.scripts.AbstractISMScript;
import se.facilia.ism.simulation.model.ResultModel;
/**
* This script demonstrates how to read results from the currently selected project.
*
*/
public class ManageResultsScript extends AbstractISMScript {
@Override
public void launch() throws Exception {
// Retrieve the current project
ISMProject project = getSelectedProject();
// The ResultsModel is a facade used to access simulation results
ResultModel resultModel = project.getSimulationModel().getResultModel();
/*
* An OutputReference represents a simulation result for one output and one
* set of dependencies (indices).
*/
OutputReference ref = OutputReference.create("Doses.Conc_Soil[Cs-137]");
// See if there are results for this output
if (!resultModel.contains(ref)) {
JOptionPane.showMessageDialog(null, "There are no results for " + ref);
return;
} else {
// Read all values for a time dependent output for a single iteration (0)
double[] values = resultModel.getForAllTimePoints(ref, 0);
JOptionPane.showMessageDialog(null, "There are " + values.length + " result values for " + ref);
}
//Other methods in the ResultModel class.
// Read the time vector for the latest simulation
double[] timeVector = resultModel.getTime();
/*
* Read a single value for a single time point and a single iteration.
* The time point is given as an index of the time vector.
*/
int t = 0;
int iteration = 0;
double d = resultModel.get(ref, t, iteration);
// Read all values for a time dependent output for a single iteration
double[] values = resultModel.getForAllTimePoints(ref, iteration);
// Find the number of iterations of a probabilistic simulation
int noIterations = resultModel.getNumberOfSimulations(ref.getContextId());
// Read the mean values of a time dependent output
double[] mean = resultModel.getMean(ref, timeVector);
// Read the std deviation of a time dependent output
double[] stdDev = resultModel.getStdDev(ref, timeVector);
// Read a percentile for a time dependent output
double[] perc95 = resultModel.getPercentile(ref, timeVector, 95.0);
}
}