v1: executing-plans 模式生成,54 文件 1320 行 Python
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from .bundle import TestDataBundle
|
||||
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@dataclass
|
||||
class TestDataBundle:
|
||||
base_path: Path
|
||||
format: str = "json"
|
||||
|
||||
def cobol_input(self) -> Path:
|
||||
return self.base_path / "cobol" / "input.bin"
|
||||
|
||||
def spark_input_dir(self) -> Path:
|
||||
return self.base_path / "spark" / "input"
|
||||
|
||||
def native_input(self) -> Path:
|
||||
return self.base_path / "native" / "input.json"
|
||||
|
||||
def ensure_dirs(self):
|
||||
for d in [self.base_path / "cobol",
|
||||
self.base_path / "spark" / "input",
|
||||
self.base_path / "native"]:
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
from tempfile import TemporaryDirectory
|
||||
_tmp = TemporaryDirectory()
|
||||
_b = TestDataBundle(base_path=Path(_tmp.name))
|
||||
assert _b.cobol_input().name == "input.bin"
|
||||
assert _b.spark_input_dir().name == "input"
|
||||
assert _b.native_input().name == "input.json"
|
||||
_b.ensure_dirs()
|
||||
assert _b.cobol_input().parent.exists()
|
||||
_tmp.cleanup()
|
||||
@@ -0,0 +1,40 @@
|
||||
import json, hashlib
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class DiskCache:
|
||||
def __init__(self, cache_dir: str = ".cache"):
|
||||
self.cache_dir = Path(cache_dir)
|
||||
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def _key_path(self, key: str) -> Path:
|
||||
h = hashlib.sha256(key.encode()).hexdigest()
|
||||
return self.cache_dir / f"{h}.json"
|
||||
|
||||
def get(self, key: str):
|
||||
path = self._key_path(key)
|
||||
if path.exists():
|
||||
return json.loads(path.read_text())
|
||||
return None
|
||||
|
||||
def set(self, key: str, value):
|
||||
self._key_path(key).write_text(json.dumps(value))
|
||||
|
||||
def invalidate(self, key: str):
|
||||
p = self._key_path(key)
|
||||
if p.exists():
|
||||
p.unlink()
|
||||
|
||||
|
||||
class ReportStore:
|
||||
def __init__(self, base_dir: str = "./reports"):
|
||||
self.base_dir = Path(base_dir)
|
||||
|
||||
def save_history(self, program: str, status: str, matched: int, duration: float):
|
||||
trend = self.base_dir / "trends" / f"{program}.jsonl"
|
||||
trend.parent.mkdir(parents=True, exist_ok=True)
|
||||
import datetime
|
||||
entry = {"ts": datetime.datetime.now().isoformat(), "status": status,
|
||||
"fields_matched": matched, "duration_s": duration}
|
||||
with open(trend, "a") as f:
|
||||
f.write(json.dumps(entry) + "\n")
|
||||
Reference in New Issue
Block a user