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:
|
Adds the raw string of HTML passed to it to the report. |
|
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:
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
groupvalue 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_nameshould 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()andhtml()
- 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
Noneis 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, andrender()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, implementrender()to save it (using this class’spathvariable as the directory), and then reference it in the output fromhtml(). The internal reporting mechanisms handle calling both of these functions as needed.A simplified example of the
FigureReporteris 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:
If specified, reports group all reportables with the same
groupvalue together.if a custom reportable is saving anything in a render function, don't use just name in the path.
Set internally by reporting functions, this variable holds a valid path where a reportable can save files (e.g. images) as needed.
The full prefixed name including the stage name and aggregate indicator.
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
groupvalue 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_nameshould 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()andhtml()
- 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.