If your metric suite isn't created using the BaseMetricSuite, you must build the metric definition for date and time tracking on your own.
To build the metric definition for date and time tracking
In the open dialog, select the FormatDate built-in operation which is stored in the UML Standard Profile and click OK.
Make sure you clear the Apply Filter check box in the Select Opaque Behavior dialog. |
In the Body area of the Default Value dialog, select the Date parameter of the FormatDate operation and click The Reset button.
Now you can track the date and time of each instance of the metric suite.
If you need to use the values of a parameter for specifying calculations in a metric definition, you can easily access them with the help of the functionality provided by the StructuredExpression language. Let’s overview the case when you need to use the value of the scope parameter inherited from the BaseMetricSuite to calculate your metrics.
To access the value of the scope parameter inherited from the BaseMetricSuite
In the script operation, refer to the scopes parameter simply by its name as the following Groovy script sample illustrates:
import static com.nomagic.magicdraw.modelmetrics.ScriptHelper.*;
import static com.nomagic.requirements.util.SysMLProfile.*;
getElementsRecursively(scopes)
findAll {el -> isRequirement(el)}
size()
An alternative way to access parameters is calling the getValue() method from MagicDraw Open API on the valueContext globally defined value, as the following Groovy script sample illustrates:
def scopes = valueContext.getValue(“scope”)
Let’s say, you need to calculate the percentage of requirements that are covered by blocks. To do this, you must have the following values:
Let’s say, these values are the results of two already existing metric definitions: requirementsCount and requirementsCoveredByBlocksCount. You need another metric definition, which takes the results of the latter metric definitions and calculates the percentage. To access these values and make sure they are already calculated, we must call the getOneValue() method from MagicDraw Open API on the valueContext globally defined value for both metric definitions, as the following Groovy script sample illustrates:
int all = valueContext.getOneValue(“requirementsCount”);
int covered = valueContext.getOneValue(“requirementsCoveredByBlocksCount”);
com.nomagic.magicdraw.modelmetrics.ScriptHelper.calcPercentage(all, covered)