metricengine.calculations.ratios
Ratio and percentage calculations.
This module contains calculations for ratios, percentages, and related mathematical operations. All calculations use the Collection namespace for proper organization.
- metricengine.calculations.ratios.ratio(numerator, denominator)[source]
Simple ratio = numerator / denominator.
- Return type:
- Default behavior:
If denominator == 0 → return None (unless policy.arithmetic_strict, then raise).
None inputs propagate to None.
- metricengine.calculations.ratios.percentage_of_total(part, total)[source]
Percentage of total = (part / total), returned as Percent.
Business rule: if total <= 0 → return 0% (not None).
- Return type:
- metricengine.calculations.ratios.ratio_to_percentage(ratio)[source]
Convert a ratio (0..1) to percent representation.
- Return type:
- metricengine.calculations.ratios.percentage_to_ratio(percentage)[source]
Convert a percent value to a ratio (e.g., 25% -> 0.25).
- Return type:
- metricengine.calculations.ratios.cap_percentage(percentage, max_percentage)[source]
Cap a percentage at a maximum value.
Returns None if either input is None.
- Return type: