pr_stats_graphs#

Graph helpers for the moa.commands.pr_stats command.

moa.commands.pr_stats_graphs.compute_moving_average(values: list[float], window: int = 10) list[float | None]#

Computes a simple moving average sequence.

Parameters:
  • values – Ordered numeric values to average.

  • window – Number of points per averaging window.

Returns:

A list the same length as values, with None for entries before enough values are available to fill one full window.

moa.commands.pr_stats_graphs.save_bar_graph(path: Path, values: dict[str, int], title: str, x_axis_label: str | None = None, y_axis_label: str | None = None, bar_labels: dict[str, str] | None = None, horizontal: bool = False) None#

Saves a themed SVG bar chart.

Parameters:
  • path – Destination SVG path.

  • values – Mapping of category label to numeric value.

  • title – Graph title.

  • x_axis_label – Optional x-axis label.

  • y_axis_label – Optional y-axis label.

  • bar_labels – Optional secondary labels rendered near each bar.

  • horizontal – When True, renders a horizontal bar chart; otherwise renders a vertical bar chart.

moa.commands.pr_stats_graphs.save_graphs_html_report(path: Path, repo: str, graphs: list[tuple[str, Path]]) None#

Builds an HTML report that embeds SVG graph files inline.

Parameters:
  • path – Destination HTML file.

  • repo – Repository label displayed in the page title.

  • graphs – Ordered (title, svg_path) pairs to include as sections.

moa.commands.pr_stats_graphs.save_job_duration_line_graph(path: Path, series: list[dict[str, Any]], title: str, moving_avg_window: int = 10, x_axis_label: str = 'Completion date', y_axis_label: str = 'Duration (minutes)') None#

Saves a job-duration SVG line chart.

The chart plots one point per entry in series using duration_seconds converted to minutes and uses the completed_at date portion for x-axis labels. When enough values are available, a moving-average line (moving_avg_window) is rendered in addition to the raw series.

moa.commands.pr_stats_graphs.week_label_first_day(value: str) str#

Returns the Monday date for an ISO week label.

The function expects a label formatted as YYYY-Www and returns the corresponding first day of that week in YYYY-MM-DD format. If value does not match the expected format or cannot be converted, the input value is returned unchanged.