The Capsis training online
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 forDataExtractor
: 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 thematchWith (Object referent)
method. This method is the extensions default compatibility system in Capsis. It is given areferent 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 aGModel
instance, then it checks something in theMethodProvider
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
orimplements
) ofcapsis.util.methodprovider.NProvider
, providingpublic double getN (GScene stand, Collection trees)
- to make the Training module compatible with
DETimeN
, add this interface (withimplements
) and this method toTraMethodProvider
- 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