coco_pipe.report.core ===================== .. py:module:: coco_pipe.report.core .. autoapi-nested-parse:: Core Reporting Classes ====================== Defines the generic reporting primitives and dim-reduction report adapters used to assemble single-file HTML reports. Classes ------- .. autoapisummary:: coco_pipe.report.core.Element coco_pipe.report.core.HtmlElement coco_pipe.report.core.ImageElement coco_pipe.report.core.PlotlyElement coco_pipe.report.core.TableElement coco_pipe.report.core.InteractiveTableElement coco_pipe.report.core.MetricsTableElement coco_pipe.report.core.ContainerElement coco_pipe.report.core.Section coco_pipe.report.core.Report Functions --------- .. autoapisummary:: coco_pipe.report.core._get_reducer_summary coco_pipe.report.core._metrics_summary_table coco_pipe.report.core._trajectory_times Module Contents --------------- .. py:function:: _get_reducer_summary(reducer: Any) -> Dict[str, Any] Collect the strict summary payload from a reduction-like object. .. py:function:: _metrics_summary_table(metrics: Any) -> pandas.DataFrame Reduce metric observations to a method x metric summary table. .. py:function:: _trajectory_times(diagnostics: Dict[str, Any], times: Optional[numpy.ndarray]) -> Optional[numpy.ndarray] Return the explicit trajectory time axis when it aligns with diagnostics. .. py:class:: Element Bases: :py:obj:`abc.ABC` Abstract base class for all report elements. .. py:method:: render() -> str :abstractmethod: Render the element to HTML. .. py:method:: collect_payload(registry: Dict[str, Any]) -> None Collect data to be stored in the global payload. Default implementation does nothing. :param registry: Global dictionary accumulating data. Keyed by UUID. :type registry: Dict[str, Any] .. py:class:: HtmlElement(html: str) Bases: :py:obj:`Element` Wrapper for raw HTML content. :param html: The raw HTML string to include. :type html: str .. rubric:: Examples >>> elem = HtmlElement("
.
.. py:method:: render_children() -> str
Render all child elements concatenated.
.. py:method:: collect_payload(registry: Dict[str, Any]) -> None
Recursively collect payload from children.
.. py:method:: render() -> str
Render the element to HTML.
.. py:class:: Section(title: str, icon: Optional[str] = None, tags: Optional[List[str]] = None, status: str = 'OK', code: Optional[str] = None)
Bases: :py:obj:`ContainerElement`
A logical section of the report.
:param title: The section title.
:type title: str
:param icon: SVG icon or emoji to display next to the title.
:type icon: str, optional
:param tags: Tags for filtering.
:type tags: List[str], optional
:param status: Status string ("OK", "WARN", "FAIL"). Default "OK".
:type status: str, optional
:param code: Source code snippet to reproduce this section.
:type code: str, optional
.. rubric:: Examples
>>> sec = Section("Results", icon="📈", status="OK")
>>> sec.add_element(plotly_element)
>>> rep.add_section(sec)
.. py:attribute:: title
.. py:attribute:: icon
:value: None
.. py:attribute:: tags
.. py:attribute:: status
:value: 'OK'
.. py:attribute:: code
:value: None
.. py:attribute:: findings
:type: List[Dict]
:value: []
.. py:attribute:: id
.. py:method:: add_finding(result: coco_pipe.report.quality.CheckResult) -> None
Add a quality finding and automatically update status.
.. py:method:: render() -> str
Render the element to HTML.
.. py:class:: Report(title: str = 'CoCo Analysis Report', config: Optional[Union[Dict, coco_pipe.report.config.ReportConfig]] = None)
Bases: :py:obj:`ContainerElement`
The main report container.
:param title: The report title.
:type title: str
:param config: Configuration dictionary or ReportConfig object used for the run.
:type config: Union[Dict, ReportConfig], optional
.. py:attribute:: timestamp
.. py:attribute:: title
:value: None
.. py:attribute:: metadata
.. py:method:: add_section(section: Section) -> Report
Syntactic sugar for adding a Section.
.. py:method:: add_figure(fig: Any, caption: Optional[str] = None) -> Report
Add a figure (Matplotlib) or Image.
.. py:method:: add_container(container: Any, name: str = 'Data Overview', show_coords: bool = True, show_dist: bool = True) -> Report
Add a summary section for a DataContainer.
Automatically runs quality checks (Missingness, Constants).
:param container: The data container to summarize.
:type container: DataContainer
:param name: Title for the section.
:type name: str
:param show_coords: If True, shows the table of coordinates.
:type show_coords: bool
:param show_dist: If True, shows the data/class distribution plot.
:type show_dist: bool
.. py:method:: add_reduction(reducer: Any, name: Optional[str] = None, *, X_emb: Optional[numpy.ndarray] = None, labels: Optional[numpy.ndarray] = None, metadata: Optional[Dict[str, Any]] = None, times: Optional[numpy.ndarray] = None) -> Report
Add one scored and optionally interpreted reduction result to the report.
:param reducer: Reduction object implementing ``get_summary()``.
:type reducer: Any
:param name: Section title. Defaults to the reduction method name.
:type name: str, optional
:param X_emb: Explicit embedding to visualize. When omitted, the section renders
scalar summaries, diagnostics, and interpretation outputs only.
:type X_emb: np.ndarray, optional
:param labels: Optional labels aligned with ``X_emb`` for embedding or trajectory
plots.
:type labels: np.ndarray, optional
:param metadata: Optional column-oriented metadata aligned with the sample axis of a
2D embedding.
:type metadata: dict, optional
:param times: Optional explicit time axis aligned with the time dimension of a 3D
trajectory tensor.
:type times: np.ndarray, optional
:returns: The report instance for fluent chaining.
:rtype: Report
:raises ValueError: If the supplied embedding or aligned plotting metadata are invalid.
:raises TypeError: If ``reducer`` does not implement the strict summary contract.
.. seealso:: :obj:`coco_pipe.dim_reduction.core.DimReduction.get_summary`, :obj:`coco_pipe.viz.plotly_utils.plot_embedding_interactive`, :obj:`coco_pipe.viz.plotly_utils.plot_interpretation_interactive`
.. py:method:: add_raw_preview(data: Any, name: str = 'Raw Data Inspector') -> Report
Add an interactive scroller for raw data.
Automatically checks for flatlines and outliers.
:param data: The data to visualize.
:type data: DataContainer or np.ndarray
:param name: Section title.
:type name: str
.. py:method:: add_comparison(metrics_df: Any, name: str = 'Method Comparison') -> Report
Add a comparison section for multiple reduction methods.
:param metrics_df: Wide/tidy metric data or an object exposing ``to_frame()``.
:type metrics_df: DataFrame or MethodSelector-like
:param name: Section title.
:type name: str
:returns: The report instance for fluent chaining.
:rtype: Report
:raises ValueError: If no comparison metrics are available after normalization.
.. seealso:: :obj:`coco_pipe.viz.plotly_utils.plot_metric_details`, :obj:`coco_pipe.dim_reduction.evaluation.core.MethodSelector`
.. py:method:: render() -> str
Render the full HTML report.
Collates payloads, compresses data, and passes to template.
.. py:method:: save(filename: str) -> None
Render and save the report to a file.
:param filename: Path to save the HTML file.
:type filename: str