style(harness): ruff format batching.py + log.py
This commit is contained in:
@@ -139,9 +139,7 @@ def _select_mixed_by_task_type(
|
||||
n_correct = round(len(errs) * correct_ratio / (1 - correct_ratio))
|
||||
available = correct_by_type.get(task_type, [])
|
||||
sampled = (
|
||||
list(available)
|
||||
if len(available) <= n_correct
|
||||
else rng.sample(available, n_correct)
|
||||
list(available) if len(available) <= n_correct else rng.sample(available, n_correct)
|
||||
)
|
||||
grouped[task_type] = errs + sampled
|
||||
|
||||
|
||||
+7
-21
@@ -68,9 +68,7 @@ class HarnessLog:
|
||||
self._conn.execute("PRAGMA journal_mode=WAL")
|
||||
self._init_fixed_tables()
|
||||
resolved_sha = git_sha or _get_git_sha()
|
||||
config_json = (
|
||||
json.dumps(config_snapshot, ensure_ascii=False) if config_snapshot else None
|
||||
)
|
||||
config_json = json.dumps(config_snapshot, ensure_ascii=False) if config_snapshot else None
|
||||
self._conn.execute(
|
||||
"INSERT OR IGNORE INTO _runs"
|
||||
" (run_id, git_sha, started_at, config, status)"
|
||||
@@ -143,18 +141,14 @@ class HarnessLog:
|
||||
col_names = ", ".join(cols)
|
||||
values = [enriched[c] for c in cols]
|
||||
if mode == "upsert":
|
||||
sql = (
|
||||
f"INSERT OR REPLACE INTO {table} ({col_names}) VALUES ({placeholders})"
|
||||
)
|
||||
sql = f"INSERT OR REPLACE INTO {table} ({col_names}) VALUES ({placeholders})"
|
||||
else:
|
||||
sql = f"INSERT INTO {table} ({col_names}) VALUES ({placeholders})"
|
||||
with self._lock:
|
||||
self._conn.execute(sql, values)
|
||||
self._conn.commit()
|
||||
|
||||
def insert_many(
|
||||
self, table: str, records: list[dict[str, Any]], mode: str = "append"
|
||||
) -> None:
|
||||
def insert_many(self, table: str, records: list[dict[str, Any]], mode: str = "append") -> None:
|
||||
"""批量插入多条记录。
|
||||
|
||||
参数:
|
||||
@@ -192,9 +186,7 @@ class HarnessLog:
|
||||
with self._lock:
|
||||
cursor = self._conn.execute(sql, params)
|
||||
columns = [desc[0] for desc in cursor.description]
|
||||
return [
|
||||
dict(zip(columns, row, strict=True)) for row in cursor.fetchall()
|
||||
]
|
||||
return [dict(zip(columns, row, strict=True)) for row in cursor.fetchall()]
|
||||
|
||||
def log_event(self, event_type: str, payload: dict[str, Any]) -> None:
|
||||
"""向 _events 表写入一条事件。
|
||||
@@ -205,8 +197,7 @@ class HarnessLog:
|
||||
"""
|
||||
with self._lock:
|
||||
self._conn.execute(
|
||||
"INSERT INTO _events (run_id, timestamp, event_type, payload)"
|
||||
" VALUES (?, ?, ?, ?)",
|
||||
"INSERT INTO _events (run_id, timestamp, event_type, payload) VALUES (?, ?, ?, ?)",
|
||||
(
|
||||
self._run_id,
|
||||
_now_iso(),
|
||||
@@ -280,15 +271,10 @@ def _read_table(
|
||||
|
||||
if question_ids is not None:
|
||||
placeholders = ", ".join(["?"] * len(question_ids))
|
||||
sql = (
|
||||
f"SELECT * FROM {table}"
|
||||
f" WHERE run_id = ? AND question_id IN ({placeholders})"
|
||||
)
|
||||
sql = f"SELECT * FROM {table} WHERE run_id = ? AND question_id IN ({placeholders})"
|
||||
rows = conn.execute(sql, (run_id, *question_ids)).fetchall()
|
||||
else:
|
||||
rows = conn.execute(
|
||||
f"SELECT * FROM {table} WHERE run_id = ?", (run_id,)
|
||||
).fetchall()
|
||||
rows = conn.execute(f"SELECT * FROM {table} WHERE run_id = ?", (run_id,)).fetchall()
|
||||
|
||||
return [dict(r) for r in rows]
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user