72 lines
1.9 KiB
Python
Executable File
72 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import json
|
|
import sqlite3
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
BASE = Path(__file__).resolve().parent
|
|
DB = BASE / 'data' / 'domainhunter.db'
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
print('Usage: import_llm_scores.py <json-file>')
|
|
sys.exit(1)
|
|
|
|
src = Path(sys.argv[1])
|
|
if not src.exists():
|
|
print(f'File not found: {src}')
|
|
sys.exit(2)
|
|
|
|
payload = json.loads(src.read_text(encoding='utf-8'))
|
|
items = payload if isinstance(payload, list) else payload.get('items', [])
|
|
|
|
con = sqlite3.connect(DB)
|
|
cur = con.cursor()
|
|
cur.executescript('''
|
|
CREATE TABLE IF NOT EXISTS llm_scores (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
run_id TEXT,
|
|
domain TEXT,
|
|
llm_score REAL,
|
|
decision TEXT,
|
|
reason TEXT,
|
|
updated_at TEXT,
|
|
UNIQUE(run_id, domain)
|
|
);
|
|
''')
|
|
|
|
run_id = None
|
|
if isinstance(payload, dict):
|
|
run_id = payload.get('runId')
|
|
if not run_id:
|
|
r = cur.execute("SELECT value FROM metadata WHERE key='latest_run_id'").fetchone()
|
|
run_id = (r[0] if r else '')
|
|
|
|
count = 0
|
|
for it in items:
|
|
d = (it.get('domain') or '').strip().lower()
|
|
if not d:
|
|
continue
|
|
score = it.get('llm_score', None)
|
|
dec = (it.get('decision') or '').strip().lower()[:32]
|
|
reason = (it.get('reason') or '').strip()[:500]
|
|
cur.execute('''
|
|
INSERT INTO llm_scores(run_id, domain, llm_score, decision, reason, updated_at)
|
|
VALUES(?,?,?,?,?,datetime('now'))
|
|
ON CONFLICT(run_id, domain) DO UPDATE SET
|
|
llm_score=excluded.llm_score,
|
|
decision=excluded.decision,
|
|
reason=excluded.reason,
|
|
updated_at=excluded.updated_at
|
|
''', (run_id, d, score, dec, reason))
|
|
count += 1
|
|
|
|
con.commit()
|
|
con.close()
|
|
print(f'OK imported llm scores: {count} for run {run_id}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|