Skip to content

manager

manager

Implementation of class wrapper around report generation process.

ReportManager

Class wrapper around report generation process.

Source code in cssfinder/reports/manager.py
class ReportManager:
    """Class wrapper around report generation process."""

    def __init__(self, project: CSSFProject, task: Task) -> None:
        """Initialize a ReportManager object with a CSSFProject and Task.

        Parameters
        ----------
        project : CSSFProject
            The CSSFProject object associated with the task.
        task : Task
            The Task object for which report will be generated.

        """
        self.project = project
        self.task = task
        self.loader = GilbertIO()

    def prepare(self) -> PreparedReportManager:
        """Prepare the data for generating a report.

        This method loads corrections from a Gilbert output file, generates plots, and
        returns a PreparedReportManager object that can be used to generate a report.

        Returns
        -------
        PreparedReportManager
            A PreparedReportManager object that contains the data and plots needed for
            generating a report.

        """
        corrections = self.loader.load_corrections(self.task.output_corrections_file)

        plots = OrderedDict()

        plotter = Plotter(corrections)

        plots["decay"] = plotter.plot_corrections()
        plots["inverse_decay"] = plotter.plot_corrections_inverse()
        plots["iterations"] = plotter.plot_iteration()

        return PreparedReportManager(
            self.project,
            plotter.slope_props,
            plots,
            self.task,
            corrections,
        )

__init__

__init__(project: CSSFProject, task: Task) -> None

Initialize a ReportManager object with a CSSFProject and Task.

Parameters:

Name Type Description Default
project CSSFProject

The CSSFProject object associated with the task.

required
task Task

The Task object for which report will be generated.

required
Source code in cssfinder/reports/manager.py
def __init__(self, project: CSSFProject, task: Task) -> None:
    """Initialize a ReportManager object with a CSSFProject and Task.

    Parameters
    ----------
    project : CSSFProject
        The CSSFProject object associated with the task.
    task : Task
        The Task object for which report will be generated.

    """
    self.project = project
    self.task = task
    self.loader = GilbertIO()

prepare

prepare() -> PreparedReportManager

Prepare the data for generating a report.

This method loads corrections from a Gilbert output file, generates plots, and returns a PreparedReportManager object that can be used to generate a report.

Returns:

Type Description
PreparedReportManager

A PreparedReportManager object that contains the data and plots needed for generating a report.

Source code in cssfinder/reports/manager.py
def prepare(self) -> PreparedReportManager:
    """Prepare the data for generating a report.

    This method loads corrections from a Gilbert output file, generates plots, and
    returns a PreparedReportManager object that can be used to generate a report.

    Returns
    -------
    PreparedReportManager
        A PreparedReportManager object that contains the data and plots needed for
        generating a report.

    """
    corrections = self.loader.load_corrections(self.task.output_corrections_file)

    plots = OrderedDict()

    plotter = Plotter(corrections)

    plots["decay"] = plotter.plot_corrections()
    plots["inverse_decay"] = plotter.plot_corrections_inverse()
    plots["iterations"] = plotter.plot_iteration()

    return PreparedReportManager(
        self.project,
        plotter.slope_props,
        plots,
        self.task,
        corrections,
    )

PreparedReportManager dataclass

Report manager with calculated report values.

Source code in cssfinder/reports/manager.py
@dataclass
class PreparedReportManager:
    """Report manager with calculated report values."""

    project: CSSFProject
    props: SlopeProperties
    plots: OrderedDict[str, Plot]
    task: Task
    corrections: pd.DataFrame

    RENDERERS: ClassVar[dict[ReportType, Type[Renderer]]] = {}

    @classmethod
    def register_renderer(
        cls,
        renderer_cls: Type[Renderer],
        report_type: ReportType,
    ) -> None:
        """Register renderer for report type."""
        cls.RENDERERS[report_type] = renderer_cls

    def request_report(self, report_type: ReportType | Any) -> Report:
        """Generate report."""
        renderer_cls = self.RENDERERS.get(report_type)

        if renderer_cls is None:
            if isinstance(report_type, ReportType):
                msg = f"Report type {report_type.name} is not supported yet."
                raise NotImplementedError(msg)

            msg = f"Unknown report type {report_type!r}"
            raise KeyError(msg)

        return renderer_cls(
            self.props,
            [p.configure() for p in self.plots.values()],
            self.task,
        ).render()

register_renderer classmethod

register_renderer(
    renderer_cls: Type[Renderer], report_type: ReportType
) -> None

Register renderer for report type.

Source code in cssfinder/reports/manager.py
@classmethod
def register_renderer(
    cls,
    renderer_cls: Type[Renderer],
    report_type: ReportType,
) -> None:
    """Register renderer for report type."""
    cls.RENDERERS[report_type] = renderer_cls

request_report

request_report(report_type: ReportType | Any) -> Report

Generate report.

Source code in cssfinder/reports/manager.py
def request_report(self, report_type: ReportType | Any) -> Report:
    """Generate report."""
    renderer_cls = self.RENDERERS.get(report_type)

    if renderer_cls is None:
        if isinstance(report_type, ReportType):
            msg = f"Report type {report_type.name} is not supported yet."
            raise NotImplementedError(msg)

        msg = f"Unknown report type {report_type!r}"
        raise KeyError(msg)

    return renderer_cls(
        self.props,
        [p.configure() for p in self.plots.values()],
        self.task,
    ).render()