MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / FileRouteStatsStorage

Class FileRouteStatsStorage

uncommon_route/stats.py:184–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182
183
184class FileRouteStatsStorage(RouteStatsStorage):
185 def __init__(self, path: Path | None = None) -> None:
186 self._path = path or (_DATA_DIR / "stats.json")
187
188 def load(self) -> list[dict[str, Any]]:
189 try:
190 if self._path.exists():
191 data = json.loads(self._path.read_text())
192 if isinstance(data, list):
193 return data
194 except Exception:
195 pass
196 return []
197
198 def save(self, records: list[dict[str, Any]]) -> None:
199 try:
200 self._path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
201 self._path.write_text(json.dumps(records, default=str))
202 self._path.chmod(0o600)
203 except Exception as exc:
204 import sys
205 print(f"[UncommonRoute] Failed to save stats: {exc}", file=sys.stderr)
206
207
208class InMemoryRouteStatsStorage(RouteStatsStorage):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected