Skip to content

reporting#

Progress reporting, custom data/figures for generated reports, and unattended report generation.

add_figure #

add_figure(
    key: str,
    figure: Figure | ndarray | bytes | bytearray | str,
    dpi: int = 300,
    width: int | None = None,
    height: int | None = None,
) -> None

Render a figure (matplotlib/plotly/charts/PIL/numpy/PNG bytes) and embed it as {{custom.key}}.

clear_data #

clear_data(key: str | None = None) -> None

Clear the custom data for key, or all custom data if key is None.

figure_to_image #

figure_to_image(
    figure: Figure | ndarray | bytes | bytearray | str,
    dpi: int = 300,
    width: int | None = None,
    height: int | None = None,
) -> str

Render a figure to a data:image/png;base64,... URI and return it.

generate #

generate(
    template_id: str | None = None,
    preset: Literal["compact", "standard", "exhaustive"]
    | None = None,
    scans: Sequence[Scan] | None = None,
    format: ReportFormatType = PDF,
) -> GeneratedReport

Render a report with no one at the screen, and archive it with the project.

The template's own branding (logo, letterhead, organisation) is applied through its placeholders. When the report cannot be made, the failure report is made instead and says why.

Parameters:

Name Type Description Default
template_id str | None

The report template, by id or name; the project's own template when omitted.

None
preset Literal['compact', 'standard', 'exhaustive'] | None

Level of detail; the template's own when omitted.

None
scans Sequence[Scan] | None

The scans the report covers; the loaded scan when omitted.

None
format ReportFormatType

The file format.

PDF

Returns:

Type Description
GeneratedReport

Where the report is, its status, and what the engine could not fill.

Raises:

Type Description
SecurityError

When the project is a review copy, or the project's report is approved and the approval does not cover this report.

ValueError

When preset is unknown, or the report cannot be made and no failure report is available.

get_data #

get_data(key: str | None = None) -> object

Return the stored value for key, all custom data if key is None, or None if unset.

send_estimate #

send_estimate(
    duration: float | None = None,
    unit: Literal[
        "ns", "us", "ms", "s", "m", "h", "d"
    ] = "us",
    step: int | None = None,
    out_of: int | None = None,
) -> None

Send a time-remaining estimate to the frontend; no-op if duration is None.

set_data #

set_data(key: str, value: object) -> None

Store value under key, accessible in report templates as {{custom.key}}.

track_progress #

track_progress(
    iterable: Iterable[T],
    desc: str | None = None,
    total: int | None = None,
    initial_estimate: float | None = None,
    initial_estimate_unit: Literal[
        "ns", "us", "ms", "s", "m", "h", "d"
    ] = "s",
    unit: str = "it",
    disable: bool = False,
    report_estimates: bool = True,
) -> Iterator[T]

Wrap a loop to show a progress bar and live time-remaining estimate; also checks for cancellation.

for item in track_progress(range(100), desc="Processing"): ... ...