Metrics

stats() (and PyReprism.stats()) return a CodeStats with line- and token-level metrics, suitable for building code datasets.

Code metrics produced by BaseLanguage.stats() and friends.

class PyReprism.metrics.CodeStats(lines: int, code_lines: int, comment_lines: int, blank_lines: int, characters: int, comment_tokens: int, string_tokens: int, number_tokens: int, keyword_tokens: int, identifier_tokens: int, operator_tokens: int)

Bases: object

Line- and token-level metrics for a source string.

Line counts are mutually exclusive: lines == code_lines + comment_lines + blank_lines. A line with both code and a trailing comment counts as a code line.

as_dict() dict
blank_lines: int
characters: int
code_lines: int
property comment_density: float

Fraction of non-blank lines that are comment-only.

comment_lines: int
property comment_to_code_ratio: float

Comment lines divided by code lines (0.0 when there is no code).

comment_tokens: int
identifier_tokens: int
keyword_tokens: int
lines: int
number_tokens: int
operator_tokens: int
string_tokens: int
class PyReprism.metrics.Halstead(distinct_operators: int, distinct_operands: int, total_operators: int, total_operands: int)

Bases: object

Halstead complexity measures.

Derived from token counts: operators are operator/keyword/punctuation tokens, operands are identifier/number/string tokens.

as_dict() dict
property bugs: float

Estimated delivered bugs (V / 3000).

property difficulty: float
distinct_operands: int
distinct_operators: int
property effort: float
property length: int
property time_seconds: float

Estimated implementation time (Halstead’s E / 18).

total_operands: int
total_operators: int
property vocabulary: int
property volume: float