Report Job

Creating an HTML Report using Numerous

In this guide, we'll walk through the steps to create an HTML report using the numerous.sdk and nuemrous html report generator. You can access the complete example here (opens in a new tab). The code demonstrates the creation of a simple report with a bar chart figure and a table.

Initial Setup:

Import the necessary modules:

from pathlib import Path
import os, logging
import pandas as pd
from numerous.image_tools.job import NumerousBaseJob, ExitCode
from numerous.html_report_generator import Report, Section, GoFigure, DataFrameTable
from numerous.image_tools.app import run_job

Define a logger for output messages:

logger = logging.getLogger('MyHTMLReportJob')

Define Base Report Job Class:

This class is a template that offers a general structure for the report generation job.

NumerousReportJob:

  • run_job(): Generates and saves the report in the current directory.
  • make_report(): This method is intended to be overridden by child classes to define the actual content of the report.
class NumerousReportJob(NumerousBaseJob):
 
    def run_job(self) -> ExitCode:
        # ...
        self.make_report(report)
        # ...
 
    def make_report(self, report: Report):
        raise NotImplementedError("Please implement the make_report method in your report job class")

Customize Report Job:

This class inherits from the base class NumerousReportJob and is where we specify the content of our report.

MyHTMLReportJob:

  • make_report(): Here, we define the actual content of our report, such as figures and tables.
class MyHTMLReportJob(NumerousReportJob):
 
    def make_report(self, report: Report):
        # Add info for the header and title page
        # ...
        # Add a section
        # ...
        # create a figure and table
        # ...
        # Add the section to the report
        # ...

Run the Report Job:

Define a method run_example() to run the report generation job:

def run_example():
    run_job(numerous_job=MyHTMLReportJob(), appname="MyHTMLReportJob", model_folder=".")

Execution:

Finally, run the report generation job using the following code:

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    run_example()

By executing the code, an HTML report will be generated in the current directory with a bar chart and a table, based on the content specified in the MyHTMLReportJob class.

That's it! You can now customize and expand upon this framework to create complex and dynamic HTML reports using the Numerous package.