pdstools.reports.GlobalExplanations.scripts.generate_report

Pre-render script for the GlobalExplanations Quarto website project.

This script is executed by Quarto as a pre-render step (configured in _quarto.yml) before the website is built. It reads .qmd templates from assets/templates/, substitutes parameter placeholders (e.g. {TOP_N}, {SORT_BY_TYPE}) with values from params.yml, and writes the final .qmd files that Quarto then renders into the website.

Templates are located in: assets/templates/ Generated .qmd files are written to the project root for Quarto to render.

Attributes

Classes

ReportGenerator

Quarto pre-render generator for the GlobalExplanations website project.

Module Contents

logger
ENCODING = 'utf-8'
CONTEXT_FOLDER = 'by-model-context'
TOP_N = 20
TOP_K = 20
FROM_DATE_DEFAULT = 'N/A'
TO_DATE_DEFAULT = 'N/A'
SORT_BY_DEFAULT = 'contribution_abs'
SORT_BY_TEXT_DEFAULT = 'absolute average contribution'
DISPLAY_BY_DEFAULT = 'contribution'
DISPLAY_BY_TEXT_DEFAULT = 'average contribution'
DATA_FOLDER = 'aggregated_data'
UNIQUE_CONTEXTS_FILENAME = 'unique_contexts.json'
PLOTS_FOR_BATCH = 'plots_for_batch'
PARAMS_FILENAME = 'params.yml'
TEMPLATES_FOLDER = './assets/templates'
INTRODUCTION_FILENAME = 'getting-started.qmd'
OVERVIEW_FILENAME = 'overview.qmd'
ALL_CONTEXT_HEADER_TEMPLATE = 'all_context_header.qmd'
ALL_CONTEXT_CONTENT_TEMPLATE = 'all_context_content.qmd'
SINGLE_CONTEXT_TEMPLATE = 'context.qmd'
class ReportGenerator

Quarto pre-render generator for the GlobalExplanations website project. Reads .qmd templates from assets/templates/, substitutes parameter placeholders with values from params.yml, and writes the rendered .qmd files for Quarto to build. Shared configuration (front matter, theme, branding) is inherited from _quarto.yml; templates only contain page-specific content and code cells.

report_folder
root_dir = ''
data_folder = ''
top_n = None
top_k = None
from_date = None
to_date = None
sort_by = None
sort_by_text = None
display_by = None
display_by_text = None
model_context_limit
by_context_folder = 'Uninferable/by-model-context'
plots_for_batch_filepath = 'Uninferable/by-model-context/plots_for_batch'
contexts = None
_log_params()
_read_params()
static _get_context_dict(context_info: str) dict
Parameters:

context_info (str)

Return type:

dict

_get_context_string(context_info: str) str
Parameters:

context_info (str)

Return type:

str

static _read_template(template_filename: str) str

Read a template file and return its content.

Templates contain placeholder strings (e.g., {ROOT_DIR}, {TOP_N}) that will be substituted with actual values during report generation.

Parameters:

template_filename (str) – Name of the template file in the templates folder

Returns:

Template content with placeholders intact

Return type:

str

_write_single_context_file(embed_path_for_batch: str, filename: str, template: str, context_str: str, context_label: str)
Parameters:
  • embed_path_for_batch (str)

  • filename (str)

  • template (str)

  • context_str (str)

  • context_label (str)

_write_header_to_file(file_batch_nb: str, filename: str)
Parameters:
  • file_batch_nb (str)

  • filename (str)

_append_content_to_file(filename: str, template: str, context_dict: dict, context_label: str)
Parameters:
  • filename (str)

  • template (str)

  • context_dict (dict)

  • context_label (str)

_get_unique_contexts()
_generate_by_context_qmds()
_generate_overview_qmd()
_generate_introduction_qmd()
run()

Main method to generate the report files.

generator