demopkg.utils
Helpers that operate on reports.
Everything here is a plain function; the module has no __all__, so the public
surface comes from the is_public heuristics (no leading underscore, not
imported).
Attributes
| Name | Description |
|---|---|
SECTION_STYLES | How each section of a rendered report is presented. |
Functions
| Name | Description |
|---|---|
describe | Summarise a report in one line. |
iter_sections | Walk the sections of a report in render order. |
merge_scores | Combine the scores of two reports. |
SECTION_STYLESattributemodule attribute#
SECTION_STYLES: dict[str, dict[str, str]] = {
'summary': {'colour': '#1b1f2a', 'marker': '*', 'caption': 'Summary, at a glance'},
'detail': {'colour': '#2a334e', 'marker': '-', 'caption': 'Detail (one row per metric)'},
'appendix': {
'colour': '#f2c641',
'marker': '+',
'caption': 'Appendix [optional, omitted by default]'
},
'footer': {'colour': '#aab2c4', 'marker': '.', 'caption': 'Footer, with the generated-at stamp'}
}How each section of a rendered report is presented.
Deliberately long: it is the fixture for a signature whose value is broken across lines at its brackets and then folded behind a toggle. The captions hold brackets, commas and quotes so the line-breaker has string literals to step over.
describefunction#
def describe(report: Report, **extra: Any) -> strSummarise a report in one line.
Parameters
Returns
str- A single line of plain text.
iter_sectionsfunction#
def iter_sections(report: Report) -> Iterator[str]Walk the sections of a report in render order.
Parameters
| Name | Type | Description |
|---|---|---|
report | Report | The report to walk. |
Yields
str- Section names, uppercased.
Examples
>>> list(iter_sections(Report("weekly")))[]merge_scoresfunction#
def merge_scores(left: Report, right: Report) -> dict[str, float]Combine the scores of two reports.
Parameters
Raises
ReportError- If the two reports disagree on a metric.
TypeError- If either argument is not a report.
ValueError- If either report has no scores.