Data Manager#

class DataManager(disable_cache: bool = False)[source]#

Caches patch data on disk and (de)serializes it between DataFrames and PatchTitle objects.

The DataManager class owns persistence for patch reports: caching snapshots on disk and converting between DataFrames and PatchTitle objects. Report rendering lives in Exporter.

Data caching can be disabled by setting disable_cache to True at runtime.

Parameters:

disable_cache (bool) – Whether caching functionality should be disabled.

property cache_off: bool[source]#

True if caching is disabled.

property titles: list[PatchTitle][source]#

Retrieve and validate the current list of PatchTitle objects.

If titles are not already loaded, they are fetched from the latest available dataset.

Returns:

The validated list of PatchTitle objects.

Return type:

list[PatchTitle]

Raises:

PatcherError – If validation fails.

build_and_cache(patch_titles: list[PatchTitle]) DataFrame[source]#

Build the canonical DataFrame from patch_titles and cache it to disk.

The full-fidelity frame (every column) is what gets cached; callers that render reports drop presentation-excluded columns downstream. Caching is a no-op when the cache is disabled.

Parameters:

patch_titles (list[PatchTitle]) – Titles to serialize and snapshot.

Returns:

The canonical DataFrame built from the titles.

Return type:

pandas.DataFrame

static snapshot_label(path: Path) str[source]#

Human-readable label for a cached snapshot file (mtime-derived).

Parameters:

path (Path)

Return type:

str

static closest_snapshot(snapshots: list[Path], target: date) Path[source]#

Pick the snapshot whose mtime is closest to target.

Parameters:
Return type:

Path

sorted_cached_files() list[Path][source]#

Return cached snapshot files sorted oldest → newest by mtime.

Return type:

list[Path]

static select_baseline(cached: list[Path], *, since: timedelta | None = None, all_time: bool = False, default: Path) Path[source]#

Pick the baseline (from) snapshot from a sorted cache list.

all_time selects the earliest snapshot ever cached; since selects the earliest within the trailing window; otherwise default is used.

Raises:

PatcherError – When since is set but no snapshot falls in the window.

Parameters:
Return type:

Path

reset_cache() bool[source]#

Removes all cached files from Cache directory. See reset.

Returns:

True if all files were able to be removed, False otherwise.

Return type:

bool

get_cached_files() list[Path][source]#

Paths of all cached snapshot files.

Return type:

list[Path]

get_latest_dataset() Path | None[source]#

Retrieves the most recent dataset of patch reports and returns the path.

If a tracked Excel file is available, it is preferred. Otherwise, searches the cache directory.

Returns:

Path to the latest dataset (Excel or pickle file), or None if no dataset is found.

Return type:

Path | None