core
tit.reporting.core ¶
Core infrastructure for TI-Toolbox reporting system.
This module provides the foundational components for building modular, self-contained HTML reports.
ReportMetadata
dataclass
¶
ReportMetadata(title: str, subject_id: str | None = None, session_id: str | None = None, report_type: str = 'general', generation_time: datetime = now(), software_versions: dict[str, str] = dict(), project_dir: str | None = None, bids_version: str = '1.8.0', dataset_type: str = 'derivative')
Metadata for a generated report.
to_dict ¶
Convert metadata to dictionary.
Source code in tit/reporting/core/protocols.py
ReportSection
dataclass
¶
ReportSection(section_id: str, title: str, reportlets: list[Any] = list(), description: str | None = None, collapsed: bool = False, order: int = 0)
A section within a report containing multiple reportlets.
render_html ¶
render_html() -> str
Render the section and all its reportlets as HTML.
Source code in tit/reporting/core/protocols.py
to_dict ¶
Convert section to dictionary.
Source code in tit/reporting/core/protocols.py
Reportlet ¶
BaseReportlet ¶
BaseReportlet(title: str | None = None)
Bases: ABC
Abstract base class for all reportlets.
Source code in tit/reporting/core/base.py
reportlet_type
abstractmethod
property
¶
reportlet_type: ReportletType
Return the type of this reportlet.
MetadataReportlet ¶
MetadataReportlet(data: dict[str, Any], title: str | None = None, display_mode: str = 'table', columns: int = 2)
Bases: BaseReportlet
Reportlet for displaying metadata as key-value pairs.
Supports two display modes: - 'table': Traditional table layout - 'cards': Modern card grid layout
Source code in tit/reporting/core/base.py
ImageReportlet ¶
ImageReportlet(image_source: str | Path | bytes | Any | None = None, title: str | None = None, caption: str | None = None, alt_text: str | None = None, width: str | None = None, height: str | None = None)
Bases: BaseReportlet
Reportlet for displaying images.
Supports embedding images as base64 or referencing external paths. Images can be loaded from file paths, PIL Images, or raw bytes.
Source code in tit/reporting/core/base.py
set_base64_data ¶
render_html ¶
render_html() -> str
Render image as HTML.
Source code in tit/reporting/core/base.py
TableReportlet ¶
TableReportlet(data: list[dict] | list[list] | Any, title: str | None = None, headers: list[str] | None = None, sortable: bool = False, striped: bool = True, compact: bool = False)
Bases: BaseReportlet
Reportlet for displaying tabular data.
Supports various input formats including lists of dicts, lists of lists, and pandas DataFrames.
Source code in tit/reporting/core/base.py
render_html ¶
render_html() -> str
Render table as HTML.
Source code in tit/reporting/core/base.py
TextReportlet ¶
TextReportlet(content: str, title: str | None = None, content_type: str = 'text', copyable: bool = False, monospace: bool = False)
Bases: BaseReportlet
Reportlet for displaying text content.
Supports plain text, HTML, and markdown-style formatting. Includes optional copy-to-clipboard functionality for boilerplate text.
Source code in tit/reporting/core/base.py
render_html ¶
render_html() -> str
Render text content as HTML.
Source code in tit/reporting/core/base.py
ErrorReportlet ¶
Bases: BaseReportlet
Reportlet for displaying errors and warnings.
Supports different severity levels with appropriate styling.
Source code in tit/reporting/core/base.py
add_message ¶
add_message(message: str, severity: SeverityLevel = ERROR, context: str | None = None, step: str | None = None) -> None
Add an error or warning message.
Source code in tit/reporting/core/base.py
add_error ¶
add_warning ¶
render_html ¶
render_html() -> str
Render errors and warnings as HTML.
Source code in tit/reporting/core/base.py
ReferencesReportlet ¶
Bases: BaseReportlet
Reportlet for displaying citations and references.
Automatically formats references in a consistent style.
Source code in tit/reporting/core/base.py
add_reference ¶
Add a reference.
Source code in tit/reporting/core/base.py
render_html ¶
render_html() -> str
Render references as HTML.
Source code in tit/reporting/core/base.py
ReportAssembler ¶
ReportAssembler(metadata: ReportMetadata | None = None, title: str | None = None)
Assembles reportlets into a complete HTML report.
The assembler manages sections, handles ordering, generates the table of contents, and renders the final HTML document.
Initialize the report assembler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
ReportMetadata | None
|
Report metadata (title, subject, etc.) |
None
|
title
|
str | None
|
Report title (overrides metadata.title if provided) |
None
|
Source code in tit/reporting/core/assembler.py
add_section ¶
add_section(section_id: str, title: str, description: str | None = None, collapsed: bool = False, order: int | None = None) -> ReportSection
Add a new section to the report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_id
|
str
|
Unique identifier for the section |
required |
title
|
str
|
Section title |
required |
description
|
str | None
|
Optional section description |
None
|
collapsed
|
bool
|
Whether section starts collapsed |
False
|
order
|
int | None
|
Sort order (lower = earlier in report) |
None
|
Returns:
| Type | Description |
|---|---|
ReportSection
|
The created ReportSection object |
Source code in tit/reporting/core/assembler.py
get_section ¶
get_section(section_id: str) -> ReportSection | None
Get a section by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_id
|
str
|
The section identifier |
required |
Returns:
| Type | Description |
|---|---|
ReportSection | None
|
The ReportSection or None if not found |
Source code in tit/reporting/core/assembler.py
add_reportlet_to_section ¶
add_reportlet_to_section(section_id: str, reportlet: Any, create_if_missing: bool = True, section_title: str | None = None) -> None
Add a reportlet to a specific section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_id
|
str
|
The section identifier |
required |
reportlet
|
Any
|
The reportlet to add |
required |
create_if_missing
|
bool
|
Create section if it doesn't exist |
True
|
section_title
|
str | None
|
Title for new section (if created) |
None
|
Source code in tit/reporting/core/assembler.py
render_toc ¶
render_toc() -> str
Render the table of contents as HTML.
Returns:
| Type | Description |
|---|---|
str
|
HTML string for the table of contents |
Source code in tit/reporting/core/assembler.py
render_metadata ¶
render_metadata() -> str
Render the header metadata as HTML.
Returns:
| Type | Description |
|---|---|
str
|
HTML string for the header metadata |
Source code in tit/reporting/core/assembler.py
render_sections ¶
render_sections() -> str
Render all sections as HTML.
Returns:
| Type | Description |
|---|---|
str
|
HTML string for all sections |
Source code in tit/reporting/core/assembler.py
render_html ¶
render_html() -> str
Render the complete report as HTML.
Returns:
| Type | Description |
|---|---|
str
|
Complete HTML document as a string |
Source code in tit/reporting/core/assembler.py
save ¶
Save the report to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
str | Path
|
Path to save the HTML file |
required |
create_dirs
|
bool
|
Create parent directories if needed |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the saved file |
Source code in tit/reporting/core/assembler.py
to_dict ¶
from_dict
classmethod
¶
Create a ReportAssembler from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Dictionary containing report data |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Reconstructed ReportAssembler instance |
Note
This reconstructs the structure but not the reportlet instances. Use this for loading report metadata, not for full reconstruction.
Source code in tit/reporting/core/assembler.py
get_html_template ¶
get_html_template(title: str, content: str, toc_html: str = '', metadata_html: str = '', footer_html: str = '', custom_css: str = '', custom_js: str = '') -> str
Generate a complete HTML document with the report content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
The report title |
required |
content
|
str
|
The main HTML content |
required |
toc_html
|
str
|
Table of contents HTML |
''
|
metadata_html
|
str
|
Header metadata HTML |
''
|
footer_html
|
str
|
Footer HTML |
''
|
custom_css
|
str
|
Additional CSS styles |
''
|
custom_js
|
str
|
Additional JavaScript |
''
|
Returns:
| Type | Description |
|---|---|
str
|
Complete HTML document as a string |
Source code in tit/reporting/core/templates.py
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 | |