Initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""Snapshot diff logic."""
|
||||
from typing import Any, Optional
|
||||
|
||||
|
||||
def diff_snapshots(
|
||||
previous: Optional[dict[str, Any]],
|
||||
current: dict[str, Any],
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Return list of rate changes between previous and current snapshots.
|
||||
Returns empty list if previous is None (first check)."""
|
||||
if not previous:
|
||||
return []
|
||||
old_groups: dict[str, Any] = previous.get("groups") or {}
|
||||
new_groups: dict[str, Any] = current.get("groups") or {}
|
||||
changes: list[dict[str, Any]] = []
|
||||
for gid, new_g in sorted(new_groups.items()):
|
||||
if not isinstance(new_g, dict):
|
||||
continue
|
||||
old_g = old_groups.get(gid)
|
||||
old_rate = old_g.get("rate") if isinstance(old_g, dict) else None
|
||||
new_rate = new_g.get("rate")
|
||||
if old_rate != new_rate:
|
||||
changes.append({
|
||||
"group_id": gid,
|
||||
"group_name": new_g.get("group_name", ""),
|
||||
"platform": new_g.get("platform", ""),
|
||||
"old_rate": old_rate,
|
||||
"new_rate": new_rate,
|
||||
})
|
||||
for gid, old_g in sorted(old_groups.items()):
|
||||
if gid not in new_groups and isinstance(old_g, dict):
|
||||
changes.append({
|
||||
"group_id": gid,
|
||||
"group_name": old_g.get("group_name", ""),
|
||||
"platform": old_g.get("platform", ""),
|
||||
"old_rate": old_g.get("rate"),
|
||||
"new_rate": None,
|
||||
})
|
||||
return changes
|
||||
Reference in New Issue
Block a user