Skip to content

Refactor stats.py into focused modules #100

Description

@tbrown122387

Problem

src/ertimes/stats.py is 1,173 lines and contains 21 functions spanning unrelated concerns: ranking, capacity scoring, growth analysis, visualization, mental health analysis, duplicate detection, and more. This is a classic god-module problem.

The unresolved merge conflict (see #98) is a direct symptom — large, sprawling files are harder to review, harder to merge, and harder to keep correct.

Impact

High — The module is difficult to navigate, test in isolation, and extend without risk of unintended side effects.

Proposed Refactor

Split stats.py into focused modules:

New Module Responsibility
stats_ranking.py Hospital/county ranking functions
stats_analysis.py Capacity scoring, mismatch detection, growth
stats_visualization.py All plotting/mapping functions
stats_reports.py Report generation, summaries

Keep a thin stats.py that re-exports the public API for backwards compatibility during the transition.

Acceptance Criteria

  • No single module exceeds ~400 lines (rough approx. guess)
  • All existing tests continue to pass
  • Public imports from ertimes are unchanged

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions