Reporting

Classes for handling reporting - adding customizable pieces of information to an HTML experiement run report.

This is handled through a base Reportable class, and each reporter class extends it.

Classes:

HTMLReporter(html_string[, name, group])

Adds the raw string of HTML passed to it to the report.

Reportable([name, group])

The base reporter class, any custom reporter should extend this.

class curifactory.experimental.reporting.HTMLReporter(html_string, name=None, group=None)

Adds the raw string of HTML passed to it to the report.

Parameters:
  • html_string (str) – The raw string of HTML to include.

  • name (str)

  • group (str)

Example

@stage(...)
def report_hello(record: Record ,...):
    record.report(HTMLReporter("<h1>Hello world!</h1>"))

Methods:

get_html()

When a report is created, the html() function for every reportable is called and appended to the report.

Attributes:

html_string

The raw string of HTML to include.

get_html()

When a report is created, the html() function for every reportable is called and appended to the report. This function should either return a single string of html, or can return a list of lines of html.

Note

Any subclass is required to implement this.

Return type:

str | list[str]

group: str

If specified, reports group all reportables with the same group value together.

html_string

The raw string of HTML to include.

name: str

if a custom reportable is saving anything in a render function, don’t use just name in the path. self.qualified_name should be preferred, as it is the fully prefixed name.

Type:

The suffix to title the reportable with. NOTE

path: str

Set internally by reporting functions, this variable holds a valid path where a reportable can save files (e.g. images) as needed. This is available to access both in render() and html()

qualified_name: str

The full prefixed name including the stage name and aggregate indicator. This is set by the record when a report() is called.

rendered: bool

A flag indicating whether this reportable’s render() has been called yet or not.

class curifactory.experimental.reporting.Reportable(name=None, group=None)

The base reporter class, any custom reporter should extend this.

Parameters:
  • name (str) – A (optional) reference name to give this piece of reported info, it is used as the title string suffix. If None is supplied, it will be suffixed with the number of the reportable.

  • group (str) – An optional string to use for grouping multiple related reportables together in the report. By default, all reportables are ordered by record. This will create a separate entry on the TOC and put them next to each other in the report.

Note

When subclassing a reportable, html() must be overriden, and render() optionally may be depending on the nature of the reportable. If a reportable relies on some form of external file, such as an image or figure, implement render() to save it (using this class’s path variable as the directory), and then reference it in the output from html(). The internal reporting mechanisms handle calling both of these functions as needed.

A simplified example of the FigureReporter is shown here:

class FigureReporter(Reportable):
    def __init__(self, fig, name=None, group=None):
        self.fig = fig
        super().__init__(name=name, group=group)

    def render(self):
        self.fig.savefig(os.path.join(self.path, f"{self.qualified_name}.png"))

    def html(self):
        return f"<img src='{self.path}/{self.qualified_name}.png'>"

Methods:

get_html()

When a report is created, the html() function for every reportable is called and appended to the report.

render()

Any file outputs or calculations that should only run once go here.

Attributes:

group

If specified, reports group all reportables with the same group value together.

html

name

if a custom reportable is saving anything in a render function, don't use just name in the path.

path

Set internally by reporting functions, this variable holds a valid path where a reportable can save files (e.g. images) as needed.

qualified_name

The full prefixed name including the stage name and aggregate indicator.

rendered

A flag indicating whether this reportable's render() has been called yet or not.

get_html()

When a report is created, the html() function for every reportable is called and appended to the report. This function should either return a single string of html, or can return a list of lines of html.

Note

Any subclass is required to implement this.

Return type:

str | list[str]

group: str

If specified, reports group all reportables with the same group value together.

property html
name: str

if a custom reportable is saving anything in a render function, don’t use just name in the path. self.qualified_name should be preferred, as it is the fully prefixed name.

Type:

The suffix to title the reportable with. NOTE

path: str

Set internally by reporting functions, this variable holds a valid path where a reportable can save files (e.g. images) as needed. This is available to access both in render() and html()

qualified_name: str

The full prefixed name including the stage name and aggregate indicator. This is set by the record when a report() is called.

render()

Any file outputs or calculations that should only run once go here.

rendered: bool

A flag indicating whether this reportable’s render() has been called yet or not.