This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
example_scripts [2019/12/11 09:52] erik |
example_scripts [2019/12/11 09:52] erik |
||
---|---|---|---|
Line 1: | Line 1: | ||
==== Example scripts ==== | ==== Example scripts ==== | ||
- | === Reading results === | + | |
- | **Version:** Ecolego 6.5,7 | + | |
- | + | ||
- | < | + | |
- | import javax.swing.JOptionPane; | + | |
- | + | ||
- | import se.facilia.ecolego.domain.OutputReference; | + | |
- | import se.facilia.ecolego.domain.model.EcolegoProject; | + | |
- | import se.facilia.ecolego.scripts.AbstractEcolegoScript; | + | |
- | import se.facilia.ecolego.simulation.model.ResultModel; | + | |
- | + | ||
- | /** | + | |
- | * This script demonstrates how to read results from the currently selected project. | + | |
- | */ | + | |
- | public class ManageResultsScript extends AbstractEcolegoScript { | + | |
- | @Override | + | |
- | public void launch() throws Exception { | + | |
- | // Retrieve the current project | + | |
- | EcolegoProject 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(" | + | |
- | + | ||
- | // See if there are results | + | |
- | if (!resultModel.contains(ref)) { | + | |
- | JOptionPane.showMessageDialog(null, | + | |
- | return; | + | |
- | } | + | |
- | + | ||
- | // 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, | + | |
- | + | ||
- | // Read all values for a time dependent output for a single iteration | + | |
- | double[] values = resultModel.getForAllTimePoints(ref, | + | |
- | + | ||
- | // 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, | + | |
- | + | ||
- | // Read the std deviation of a time dependent output | + | |
- | double[] stdDev = resultModel.getStdDev(ref, | + | |
- | + | ||
- | // Read a percentile for a time dependent output | + | |
- | double[] perc95 = resultModel.getPercentile(ref, | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + |