class project_metricclass

A project granularity metric class.

The project granularity metric classes are managed by project_metricclass_manager .

  • For a manually computed metric, your plug-in should:

You can retrieve metric values with project_metricclass.value(), and examine metric properties with project_metricclass.description(), project_metricclass.tag(), and project_metricclass.flags().

For more information about metrics in CodeSonar, see the Metrics manual page.

project_metricclass Details

class cs.project_metricclass

A project granularity metric class.

__cmp__(other)

Comparison function for project_metricclass , with respect to a stable overall ordering.

Parameters:other (project_metricclass) – The project_metricclass object to compare against.
Return type:int
Returns:An integer N such that:
  • N<0 if self < other
  • N==0 if self == other
  • N>0 if self > other

self and other will only compare equal if they are the same project_metricclass object.

>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm2 = next(projmetrics)
>>> pm2
<cs.metricclass TL>
>>> pm1.__cmp__(pm2)
-1
__eq__(b)

Equality operator for project_metricclass .

Parameters:b (project_metricclass) – The project_metricclass object to compare against.
Return type:bool
Returns:True if self equal to b , False otherwise.
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm2 = next(projmetrics)
>>> pm2
<cs.metricclass TL>
>>> pm1 == pm2
False
__ge__(b)

Greater-than-or-equal operator for project_metricclass .

Parameters:b (project_metricclass) – The project_metricclass object to compare against.
Return type:bool
Returns:True if self >= b , False otherwise.
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm2 = next(projmetrics)
>>> pm2
<cs.metricclass TL>
>>> pm1 >= pm2
False
__gt__(b)

Greater-than operator for project_metricclass .

Parameters:b (project_metricclass) – The project_metricclass object to compare against.
Return type:bool
Returns:True if self > b , False otherwise.
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm2 = next(projmetrics)
>>> pm2
<cs.metricclass TL>
>>> pm1 > pm2
False
__hash__()

Get a hash value for this project_metricclass .

Return type:int
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> hash(pm1)
1823793984
__le__(b)

Less-than-or-equal operator for project_metricclass .

Parameters:b (project_metricclass) – The project_metricclass object to compare against.
Return type:bool
Returns:True if self <= b , False otherwise.
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm2 = next(projmetrics)
>>> pm2
<cs.metricclass TL>
>>> pm1 <= pm2
True
__lt__(b)

Less-than operator for project_metricclass .

Parameters:b (project_metricclass) – The project_metricclass object to compare against.
Return type:bool
Returns:True if self < b , False otherwise.
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm2 = next(projmetrics)
>>> pm2
<cs.metricclass TL>
>>> pm1 < pm2
True
__ne__(b)

Inequality operator for project_metricclass .

Parameters:b (project_metricclass) – The project_metricclass object to compare against.
Return type:bool
Returns:False if self equal to b , True otherwise.
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm2 = next(projmetrics)
>>> pm2
<cs.metricclass TL>
>>> pm1 != pm2
True
__repr__()

Get a representation of a project_metricclass object that includes information useful for debugging.

Return type:str
Returns:The string representation.
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> repr(pm1)
'<cs.metricclass LCom>'
__str__()

Get a simple string representation of a project_metricclass object.

Return type:str
Returns:The string representation.
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> str(pm1)
'LCom'
allowed()

Check: are METRIC_FILTER settings such that reported instances of this metric class will be submitted to the hub?

Return type:bool
Returns:True if reported instances of the class will be submitted to the hub, False otherwise.

If you have defined a custom metric class C in a plug-in, you can use a test based on C.allowed() to avoid unnecessary work in the case where C is ignored.

This is the complement of project_metricclass.always_discarded().

>>> v0 = project_metricclass_manager.metricclasses()
>>> v1 = v0.__next__()
>>> v1.allowed()
True
always_discarded()

Check: are METRIC_FILTER settings such that instances of this metric class will always be ignored?

Return type:bool
Returns:True if all instances of the class are being discarded, False otherwise.

If you have defined a custom metric class C in a plug-in, you can use a test based on C.always_discarded() to avoid unnecessary work in the case where C is ignored.

This is the complement of project_metricclass.allowed().

>>> v0 = project_metricclass_manager.metricclasses()
>>> v1 = v0.__next__()
>>> v1.always_discarded()
False
description()

Get the description (longer, human readable identifier) for a metric class ( project_metricclass ).

Return type:str
Returns:The description, as a string.

For example, CodeSonar ships with built-in project granularity metric class Include file instances.

  • its tag is “InclF”
  • its description is “Include file instances”
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm1.description()
'Lines with Comments'
flags()

Get the metricclass_flags for a project_metricclass .

Return type:metricclass_flags
Returns:The metricclass_flags .
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1.flags()
<cs.metricclass_flags auto>
report(elt, val)

Report a metric value to the hub.

Parameters:
  • elt (project) – The element that the metric value is associated with.
  • val (float) – The value to report.
Return type:

NoneType

Raises:

You do not need to call this method if the metric class was created with a metric function decorator. In that case, CodeSonar will automatically report the values calculated using the decorated function.

>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm1.value(project.current())
1.0
>>> pm1.report(project.current(), 2)
[Mon May 17 12:42:42 2021 15268] Spawning CSPQP_MAIN cs_postq process.
>>> pm1.value(project.current())
2.0
retract(elt)

Retract a metric value.

Parameters:

elt (project) – The element for which the value will be retracted.

Return type:

NoneType

Raises:

In typical usage, project_metricclass.retract() is called during the drop traversal (that is, by a drop visitor).

>>> v0 = project_metricclass_manager.metricclasses()
>>> v1 = v0.next()
>>> v2 = project.current()
>>> v1.retract(v2)
tag()

Get the tag (short string identifier) for a metric class ( project_metricclass ).

Return type:str
Returns:The short tag, as a string.

The tag will usually be only a few characters long. Retrieve the metric class description with project_metricclass.description() for a longer string that is generally more human-readable.

For example, CodeSonar ships with built-in project granularity metric class Include file instances.

  • its tag is “InclF”
  • its description is “Include file instances”
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm1.tag()
'LCom'
value(elt)

Get the value of a metric.

Parameters:

elt (project) – The element for which the metric value is required.

Return type:

float

Returns:

The metric value for elt.

Raises:
>>> projmetrics = project_metricclass_manager.metricclasses()
>>> pm1 = next(projmetrics)
>>> pm1
<cs.metricclass LCom>
>>> pm1.value(project.current())
1.0
>>> pm1.report(project.current(), 2)
[Mon May 17 12:42:42 2021 15268] Spawning CSPQP_MAIN cs_postq process.
>>> pm1.value(project.current())
2.0