File size: 1,180 Bytes
8e3a425
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""core/proof_system.py — Journal des améliorations prouvées"""
import json, time, os
from typing import Dict
from pathlib import Path


class ProofSystem:
    def __init__(self, storage_path: str = "/tmp/vortex_data/proofs.json"):
        self.path = Path(storage_path)
        self.path.parent.mkdir(parents=True, exist_ok=True)
        self.proofs = []
        if self.path.exists():
            try:
                self.proofs = json.loads(self.path.read_text())
            except:
                pass

    def register_improvement(self, version: str, before: float, after: float, benchmark: str) -> Dict:
        proof = {
            "version": version, "benchmark": benchmark,
            "before": before, "after": after,
            "delta": after - before, "ts": time.time()
        }
        self.proofs.append(proof)
        self.path.write_text(json.dumps(self.proofs, indent=2))
        return proof

    def should_rollback(self, version: str, new_score: float, threshold: float = 0.05) -> bool:
        for p in reversed(self.proofs):
            if p["version"] == version:
                return (p["before"] - new_score) > threshold
        return False