Judge each agent's best roles against its CV as skills, experience and career, a stage after summarise
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4fc474c437
commit
9960799b96
14 files changed
+866
-44
No files matched your search
+86
-1
@@ -25,7 +25,7 @@ from app import dupes, places
|
||||
from app.models import (
|
||||
AFFINITY, HAND_REASONS, LEVELS, STATUSES, Agent, Application,
|
||||
ApplicationEvent, Candidate, Company, CvLanguage, Gate, Judgement, Limits, Prompt, Role,
|
||||
RoleCopy, RolePlace, RoleRow, ScoredRole, cv_languages as normal_languages,
|
||||
RoleCopy, RolePlace, RoleRow, ScoredRole, cv_languages as normal_languages, cv_score,
|
||||
language_flag,
|
||||
Subscription, Weights, check_prompts, company_fold, company_key, country_of, excerpt, place_key,
|
||||
fetch_terms as normal_terms, host_word, iso_day, posted_at, posted_host, remote_of, title_key,
|
||||
@@ -1772,6 +1772,91 @@ class Store:
|
||||
"AND CAST(value AS INTEGER) = ?", (json.dumps(keys), GIVE_UP_AFTER)).fetchone()[0]
|
||||
return int(crossed)
|
||||
|
||||
# ---------------------------------------------------------------- judge
|
||||
|
||||
def judge_rows(self, agent: Agent, uids: Sequence[str] | None = None) -> list[sqlite3.Row]:
|
||||
"""What `judge` may read for one agent: its best ungated scores of
|
||||
open roles that are no copy, as deep and as low as its `limits` say
|
||||
(`judge_top`, `judge_min`), best first, each with some text
|
||||
(`article_text` or `description`). Given `uids`, those of them with
|
||||
text, whatever their rank or state. Each row carries `uid`,
|
||||
`title`, `company`, `place`, `article_text`, `description`, and the
|
||||
stored judgement's `input_key`, `judged_at` and `tries` (NULL, NULL
|
||||
and 0 without one), and `given_up` once `tries` reached
|
||||
`GIVE_UP_AFTER`."""
|
||||
text = "(TRIM(r.article_text) <> '' OR TRIM(r.description) <> '')"
|
||||
select = ("SELECT r.uid, r.title, r.company, r.place, r.article_text, r.description, "
|
||||
"j.input_key, j.judged_at, COALESCE(j.tries, 0) AS tries, "
|
||||
f"COALESCE(j.tries, 0) >= {GIVE_UP_AFTER} AS given_up FROM ")
|
||||
joined = "LEFT JOIN role_judgements j ON j.uid = r.uid AND j.agent_id = ?"
|
||||
if uids is not None:
|
||||
return self._rows(
|
||||
f"{select} roles r {joined} WHERE r.uid IN (SELECT value FROM json_each(?)) "
|
||||
f"AND {text} ORDER BY r.uid", (agent.id, json.dumps(list(uids))))
|
||||
return self._rows(
|
||||
f"""{select} (SELECT s.uid, s.score FROM scores s
|
||||
JOIN roles top ON top.uid = s.uid AND top.closed_at IS NULL
|
||||
AND top.dup_of IS NULL
|
||||
WHERE s.agent_id = ? AND s.gated_reason = ''
|
||||
ORDER BY s.score DESC, top.posted_at DESC, s.uid LIMIT ?) best
|
||||
JOIN roles r ON r.uid = best.uid {joined}
|
||||
WHERE best.score >= ? AND {text}
|
||||
ORDER BY best.score DESC, r.posted_at DESC, r.uid""",
|
||||
(agent.id, agent.limits.judge_top, agent.id, agent.limits.judge_min))
|
||||
|
||||
def set_judgement(self, agent_id: int, uid: str, input_key: str, skills: int,
|
||||
experience: int, career: int, strengths: Sequence[str],
|
||||
gaps: Sequence[str]) -> bool:
|
||||
"""Store `judge`'s reading of one role for one agent, replacing the
|
||||
one before, with `cv_score` (`app.models.cv_score`) and its tries
|
||||
back at 0. False for an unknown role or agent."""
|
||||
try:
|
||||
with self.transaction() as conn:
|
||||
conn.execute(
|
||||
"""INSERT INTO role_judgements (uid, agent_id, skills, experience, career,
|
||||
cv_score, strengths, gaps, input_key, tries,
|
||||
judged_at)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,0,?)
|
||||
ON CONFLICT(uid, agent_id) DO UPDATE SET
|
||||
skills=excluded.skills, experience=excluded.experience,
|
||||
career=excluded.career, cv_score=excluded.cv_score,
|
||||
strengths=excluded.strengths, gaps=excluded.gaps,
|
||||
input_key=excluded.input_key, tries=0, judged_at=excluded.judged_at""",
|
||||
(uid, agent_id, skills, experience, career,
|
||||
cv_score(skills, experience, career),
|
||||
json.dumps(list(strengths), ensure_ascii=False),
|
||||
json.dumps(list(gaps), ensure_ascii=False), input_key, self.now()))
|
||||
except sqlite3.IntegrityError:
|
||||
return False
|
||||
return True
|
||||
|
||||
def judge_missed(self, pairs: Sequence[tuple[int, str]]) -> int:
|
||||
"""One reply that left these `(agent_id, uid)` without a judgement:
|
||||
each is charged a try, a row of tries alone made for one never
|
||||
judged. Returns how many this pushed to `GIVE_UP_AFTER`. The caller
|
||||
passes only the pairs still waiting."""
|
||||
if not pairs:
|
||||
return 0
|
||||
with self.transaction() as conn:
|
||||
conn.executemany(
|
||||
"""INSERT INTO role_judgements (uid, agent_id, tries)
|
||||
SELECT ?, ?, 1 WHERE EXISTS (SELECT 1 FROM roles WHERE uid = ?)
|
||||
ON CONFLICT(uid, agent_id) DO UPDATE SET tries = tries + 1""",
|
||||
[(uid, agent_id, uid) for agent_id, uid in pairs])
|
||||
crossed = sum(conn.execute(
|
||||
"SELECT COUNT(*) FROM role_judgements WHERE uid = ? AND agent_id = ? "
|
||||
"AND tries = ?", (uid, agent_id, GIVE_UP_AFTER)).fetchone()[0]
|
||||
for agent_id, uid in pairs)
|
||||
return int(crossed)
|
||||
|
||||
def judgement(self, agent_id: int | None, uid: str) -> Judgement | None:
|
||||
"""The agent's judgement of one role, None when it has none."""
|
||||
if agent_id is None:
|
||||
return None
|
||||
row = self._row("SELECT * FROM role_judgements WHERE agent_id = ? AND uid = ? "
|
||||
"AND judged_at IS NOT NULL", (agent_id, uid))
|
||||
return Judgement.from_row(row) if row else None
|
||||
|
||||
def set_article_text(self, uid: str, text: str) -> Role | None:
|
||||
"""Store the posting page as plain text and stamp `article_at`. The
|
||||
role as it now stands, or None for an unknown uid."""
|
||||
|
||||
Reference in new issue
Block a user