User Tools

Site Tools


solution_of_14._make_a_graph:n:time

The Capsis training online

Back to the table of contents

Solution 14. Make a graph: N / Time

Try to work with the helping elements before looking at the solution…

Helping elements

  • the graph already exists: capsis.extension.dataextractor.DETimeN, and you have nothing to change in it
  • it is a generic extension in Capsis, i.e. compatible with several modules, that's why it is in the capsis.extension package
  • the starting DE is for DataExtractor: a tool extracting data series from a simulation, on a given step or from the root step to a given step
  • open DETimeN in your editor and look at the matchWith (Object referent) method. This method is the extensions default compatibility system in Capsis. It is given a referent object and returns true if it can work with it
  • DataExtractors.matchWith () methods are given an instance of the model class linked to the project of the step they are opened on
  • DETimeN checks it is a GModel instance, then it checks something in the MethodProvider of the model object

What is a Capsis MethodProvider ?

All model classes in Capsis (e.g. TraModel extends GModel) can return an instance (never null) of MethodProvider (here, TraMethodProvider implements MethodProvider)

The MethodProvider of a module is specific to the module and can access every detail in the module data structure (knows TraScene, TraTree, etc.).

It contains methods to calculate values, e.g. stand basal area, stand dominant height… for a given GScene (and optionally for a list of individuals for the individual based models).

These methods are normalized in java interfaces, e.g. GProvider for getG(), HDomProvider for getHDom(), in the capsis.util.methodprovider package and can be detected by tools to check the compatibility with a module.

The TraMethodProvider will be called only for Training projects and its method will always be passed an instance of TraScene (and possibly a list of TraTree instances for the methods accepting a list of individuals)

  • DETimeN.matchWith () checks if the methodProvider is an instance (extends or implements) of capsis.util.methodprovider.NProvider, providing public double getN (GScene stand, Collection trees)
  • to make the Training module compatible with DETimeN, add this interface (with implements) and this method to TraMethodProvider
  • implement the new method by analogy with an existing method, e.g. getDg() to make the same tests at the beginning, copy code to count the trees and manage correctly the possible exceptions

A possible solution

Code elements to adapt the TraMethodProvider to make Training compatible with DETimeN A possible result in the DETimeN graph after few years of simulation

Back to the table of contents

solution_of_14._make_a_graph/n/time.txt · Last modified: 2021/12/13 09:28 by 127.0.0.1