Extract as the afterburner for the level: model verdict with stated and title hints, best rank first, agreement per host
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3adafd8950
commit
7ca1f02e26
4 files changed
+194
-23
No files matched your search
+47
-12
@@ -51,10 +51,14 @@ _EXTRACT_TEXT = ("place", "country", "remote", "currency", "permit")
|
||||
#: never answers is otherwise paid for on every pull for as long as it exists.
|
||||
GIVE_UP_AFTER = 3
|
||||
|
||||
#: A role `extract` has yet to read: never answered, still open, no copy of
|
||||
#: another (`rebuild_dupes`), not given up.
|
||||
_EXTRACT_WAITING = (f"extracted_at IS NULL AND closed_at IS NULL AND dup_of IS NULL "
|
||||
f"AND extract_tries < {GIVE_UP_AFTER}")
|
||||
#: A role `extract` has yet to read: still open, no copy of another
|
||||
#: (`rebuild_dupes`), not given up, and either never answered or without a
|
||||
#: model level. The second half makes `extract` the afterburner for the level:
|
||||
#: a role read before the level was asked for is read again, and only fills
|
||||
#: what is still empty (`set_extracted`). A reply that names no level leaves
|
||||
#: the role waiting and is charged a try (`extract.apply_batch`), so it ends.
|
||||
_EXTRACT_WAITING = (f"(extracted_at IS NULL OR seniority_model = '') AND closed_at IS NULL "
|
||||
f"AND dup_of IS NULL AND extract_tries < {GIVE_UP_AFTER}")
|
||||
|
||||
#: What a vote may be: 1 like, 0 neither way, -1 pass, None unjudged.
|
||||
VOTES = (-1, 0, 1, None)
|
||||
@@ -1217,7 +1221,8 @@ class Store:
|
||||
otherwise only the roles in `_top_scope`."""
|
||||
where = [_EXTRACT_WAITING.replace("extracted_at", "r.extracted_at")
|
||||
.replace("closed_at", "r.closed_at").replace("extract_tries", "r.extract_tries")
|
||||
.replace("dup_of", "r.dup_of")]
|
||||
.replace("dup_of", "r.dup_of")
|
||||
.replace("seniority_model", "r.seniority_model")]
|
||||
if uids is not None:
|
||||
where.append("r.uid IN (SELECT value FROM json_each(?))")
|
||||
return " AND ".join(where), [json.dumps(list(uids))]
|
||||
@@ -1230,15 +1235,26 @@ class Store:
|
||||
return int(row["n"]) if row else 0
|
||||
|
||||
def extract_waiting(self, limit: int, uids: Sequence[str] | None = None) -> list[Role]:
|
||||
"""Roles `extract` has yet to read, newest first: the best of every
|
||||
enabled agent's scores, as deep and as low as that agent's own
|
||||
`limits` say, so the backlog follows the rankings rather than the
|
||||
boards. Given `uids`, only those of them still waiting, whatever
|
||||
their rank."""
|
||||
"""Roles `extract` has yet to read: the best of every enabled agent's
|
||||
scores, as deep and as low as that agent's own `limits` say, so the
|
||||
backlog follows the rankings rather than the boards. Ordered by the
|
||||
best rank any agent gives the role (each agent's first, then each
|
||||
agent's second ...), then by its score, so every agent's top comes
|
||||
before anyone's tail whatever limits cut the batch. Given `uids`,
|
||||
only those of them still waiting, whatever their rank; a role no agent
|
||||
ranks comes last."""
|
||||
where, params = self._extract_scope(uids)
|
||||
return [Role.from_row(r) for r in self._rows(
|
||||
f"SELECT r.* FROM roles r WHERE {where} "
|
||||
"ORDER BY r.first_seen DESC, r.uid LIMIT ?", [*params, limit])]
|
||||
"SELECT r.* FROM roles r LEFT JOIN ("
|
||||
" SELECT uid, MIN(n) AS best_rank, MAX(score) AS best_score FROM ("
|
||||
" SELECT s.uid, s.score, ROW_NUMBER() OVER ("
|
||||
" PARTITION BY s.agent_id ORDER BY s.score DESC, s.uid) AS n"
|
||||
" FROM scores s"
|
||||
" JOIN agents a ON a.id = s.agent_id AND a.enabled = 1"
|
||||
" WHERE s.gated_reason = '') GROUP BY uid) k ON k.uid = r.uid "
|
||||
f"WHERE {where} "
|
||||
"ORDER BY k.best_rank IS NULL, k.best_rank, k.best_score DESC, "
|
||||
"r.first_seen DESC, r.uid LIMIT ?", [*params, limit])]
|
||||
|
||||
def set_extracted(self, uid: str, fields: dict[str, Any]) -> int | None:
|
||||
"""Write what `extract` read for one role and stamp `extracted_at`.
|
||||
@@ -1308,6 +1324,25 @@ class Store:
|
||||
f"WHERE {where}", (wanted,))
|
||||
return int(crossed)
|
||||
|
||||
def seniority_agreement(self) -> list[dict[str, Any]]:
|
||||
"""How far each host's stated level matches the model's, over the
|
||||
open roles that have both: `host`, `compared`, `agreed` and `rate`
|
||||
(agreed / compared), the least trusted host first. `stated_only`
|
||||
counts the roles that state a level and have no model value yet, so
|
||||
a small `compared` can be told from a host that states nothing."""
|
||||
rows = self._rows(
|
||||
f"SELECT {_HOST} AS host, "
|
||||
"SUM(seniority_stated <> '' AND seniority_model <> '') AS compared, "
|
||||
"SUM(seniority_stated <> '' AND seniority_stated = seniority_model) AS agreed, "
|
||||
"SUM(seniority_stated <> '' AND seniority_model = '') AS stated_only "
|
||||
"FROM roles WHERE closed_at IS NULL AND dup_of IS NULL "
|
||||
"GROUP BY host HAVING compared > 0 OR stated_only > 0")
|
||||
found = [{"host": r["host"], "compared": int(r["compared"]),
|
||||
"agreed": int(r["agreed"]), "stated_only": int(r["stated_only"]),
|
||||
"rate": round(r["agreed"] / r["compared"], 3) if r["compared"] else None}
|
||||
for r in rows]
|
||||
return sorted(found, key=lambda h: (h["rate"] is None, h["rate"] or 0, h["host"]))
|
||||
|
||||
# ------------------------------------------------------------ summarise
|
||||
|
||||
#: The `state` key counting replies that left a role without a summary.
|
||||
|
||||
Reference in new issue
Block a user