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