Serve Best CV match, Closing soon, the language flag and the deadline in the feed, and suggest an agent's languages from its CV
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9960799b96
commit
14076e988d
5 files changed
+313
-34
No files matched your search
+72
-21
@@ -26,7 +26,7 @@ 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, cv_score,
|
||||
language_flag,
|
||||
language_flag, role_languages,
|
||||
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,
|
||||
)
|
||||
@@ -119,6 +119,18 @@ _VOTED_SCORE = ("MIN(1.0, s.score * CASE v.vote WHEN -1 THEN 0.5 "
|
||||
#: nothing, so `vote` and `voted_at` are NULL: one query shape either way.
|
||||
_WITH_VOTES = "LEFT JOIN role_votes v ON v.uid = roles.uid AND v.agent_id = ?"
|
||||
|
||||
#: The agent's `judge` readings beside every role, the same way: `j.cv_score`
|
||||
#: is NULL for a role not judged and with no agent.
|
||||
_WITH_JUDGEMENTS = ("LEFT JOIN role_judgements j ON j.uid = roles.uid AND j.agent_id = ? "
|
||||
"AND j.judged_at IS NOT NULL")
|
||||
|
||||
#: The order of Best CV match: the judged roles by `cv_score`, then the rest
|
||||
#: by score, as `roles` orders them.
|
||||
_BY_CV = "j.cv_score IS NULL, j.cv_score DESC, "
|
||||
|
||||
#: How many days after today the feed's Closing soon filter reaches.
|
||||
CLOSING_DAYS = 4
|
||||
|
||||
#: What `roles_page` reads for `RoleRow.excerpt`: the summary when there is
|
||||
#: one, else the description's opening. A `SUBSTR` of the source column, not
|
||||
#: the column itself, so a big `description` never leaves SQLite whole for a
|
||||
@@ -867,7 +879,8 @@ class Store:
|
||||
|
||||
def role(self, uid: str, agent_id: int | None = None) -> ScoredRole | None:
|
||||
"""One role with its tags, and with `vote`, `voted_at`, `score`,
|
||||
`gated_reason` and `prompt` as `agent_id` judged and scored it; None
|
||||
`gated_reason` and `prompt` as `agent_id` judged and scored it, and
|
||||
its `judgement`, `cv_score` and language flag for that agent; None
|
||||
(unjudged, unscored) without an agent. The score is moved by the vote
|
||||
as `roles` serves it."""
|
||||
row = self._row(
|
||||
@@ -883,6 +896,10 @@ class Store:
|
||||
role.copies = self._copies_of(uid)
|
||||
role.places = self.role_places(uid)
|
||||
role.remote_where = self._remote_where([uid]).get(uid, "")
|
||||
role.judgement = self.judgement(agent_id, uid)
|
||||
role.cv_score = role.judgement.cv_score if role.judgement else None
|
||||
role.lang_flag, role.lang_note = language_flag(role.languages_required,
|
||||
self._languages_of(agent_id))
|
||||
return role
|
||||
|
||||
def _copies_of(self, uid: str) -> list[RoleCopy]:
|
||||
@@ -1059,7 +1076,8 @@ class Store:
|
||||
judged: str | None = None, pay: str | None = None,
|
||||
company_keys: Sequence[str] = (), places: Sequence[str] = (),
|
||||
seniority: Sequence[str] = (), seniority_unknown: bool = True,
|
||||
pay_unknown: bool = False, offset: int = 0) -> list[ScoredRole]:
|
||||
pay_unknown: bool = False, by_cv: bool = False, closing: bool = False,
|
||||
offset: int = 0) -> list[ScoredRole]:
|
||||
"""Newest first by `posted_at`. `company` and `place` are
|
||||
case-insensitive substrings of the columns a board wrote — not the
|
||||
key, so a search does not have to know the exact slug a company folds
|
||||
@@ -1102,6 +1120,13 @@ class Store:
|
||||
rescore. With `by_score` off the order is newest, with the votes and
|
||||
no score.
|
||||
|
||||
With `by_cv` as well, the roles the agent's `judge` read come first
|
||||
by `cv_score`, then the others by score (Best CV match). Every row
|
||||
carries the agent's `cv_score` (None when not judged) and the
|
||||
language flag of its languages against the agent's
|
||||
(`language_flag`). `closing` keeps the roles whose `deadline` falls
|
||||
today or in the next `CLOSING_DAYS` days.
|
||||
|
||||
`offset` skips that many rows of the same order, for the page that
|
||||
loads the next 60 as it is scrolled; `count_roles` is the total.
|
||||
Every returned role carries its tags, read with one extra query for
|
||||
@@ -1111,13 +1136,14 @@ class Store:
|
||||
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
||||
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown)
|
||||
select = "SELECT roles.*, v.vote, v.voted_at"
|
||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
||||
closing=closing)
|
||||
select = "SELECT roles.*, v.vote, v.voted_at, j.cv_score"
|
||||
order = "roles.posted_at DESC, roles.uid"
|
||||
scored = agent is not None and by_score
|
||||
if scored:
|
||||
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt"
|
||||
order = "score DESC, " + order
|
||||
order = (_BY_CV if by_cv else "") + "score DESC, " + order
|
||||
elif open_only:
|
||||
# Newest first, open only: idx_roles_posted covers this exactly
|
||||
# (posted_at DESC, uid, WHERE closed_at IS NULL), so it earns the
|
||||
@@ -1131,11 +1157,18 @@ class Store:
|
||||
f"{select} {sql} ORDER BY {order} LIMIT ? OFFSET ?", [*params, limit, offset])]
|
||||
by_uid = self._tags_by_uid([r.uid for r in found])
|
||||
areas = self._remote_where([r.uid for r in found])
|
||||
mine = self._languages_of(agent)
|
||||
for r in found:
|
||||
r.tags = by_uid.get(r.uid, [])
|
||||
r.remote_where = areas.get(r.uid, "")
|
||||
r.lang_flag, r.lang_note = language_flag(r.languages_required, mine)
|
||||
return found
|
||||
|
||||
def _languages_of(self, agent_id: int | None) -> list[CvLanguage]:
|
||||
"""The languages the agent's CV states, [] with no agent."""
|
||||
found = self.agent(agent_id) if agent_id is not None else None
|
||||
return found.cv_languages if found else []
|
||||
|
||||
def roles_page(self, limit: int = 100, company: str | None = None,
|
||||
place: str | None = None, open_only: bool = True,
|
||||
q: str | None = None, function: str | None = None,
|
||||
@@ -1146,7 +1179,8 @@ class Store:
|
||||
judged: str | None = None, pay: str | None = None,
|
||||
company_keys: Sequence[str] = (), places: Sequence[str] = (),
|
||||
seniority: Sequence[str] = (), seniority_unknown: bool = True,
|
||||
pay_unknown: bool = False, offset: int = 0) -> list[RoleRow]:
|
||||
pay_unknown: bool = False, by_cv: bool = False, closing: bool = False,
|
||||
offset: int = 0) -> list[RoleRow]:
|
||||
"""What `GET /api/roles` serves: the same rows `roles` would, in the
|
||||
same order, with the same filters and paging, but only the fields a
|
||||
row draws (see `RoleRow`) — never `description`, `feed_text`, `raw`
|
||||
@@ -1154,6 +1188,9 @@ class Store:
|
||||
or not a page ever renders them. The reader still gets the whole role
|
||||
by uid, see `role`.
|
||||
|
||||
`lang_flag` and `lang_note` are the role's languages against the
|
||||
agent's (`language_flag`), and `cv_score` its `judge` total.
|
||||
|
||||
`excerpt` is `app.models.excerpt` over a `SUBSTR` of `_EXCERPT_SOURCE`
|
||||
(`_EXCERPT_RAW` characters, trimmed further in Python), so the source
|
||||
column itself never crosses out of SQLite for a list."""
|
||||
@@ -1162,29 +1199,33 @@ class Store:
|
||||
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
||||
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown)
|
||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
||||
closing=closing)
|
||||
select = (
|
||||
"SELECT roles.uid, roles.company_key, roles.company, roles.title, roles.place, "
|
||||
"roles.country, roles.remote, roles.function, roles.seniority, roles.salary_min, "
|
||||
"roles.salary_max, roles.currency, roles.salary_text, roles.original_url, "
|
||||
"roles.posting_url, roles.posted_at, roles.read_at, "
|
||||
"v.vote, v.voted_at, "
|
||||
"roles.posting_url, roles.posted_at, roles.read_at, roles.deadline, "
|
||||
"roles.languages_required, v.vote, v.voted_at, j.cv_score, "
|
||||
f"SUBSTR({_EXCERPT_SOURCE}, 1, {_EXCERPT_RAW}) AS excerpt")
|
||||
order = "roles.posted_at DESC, roles.uid"
|
||||
scored = agent is not None and by_score
|
||||
if scored:
|
||||
select += f", {_VOTED_SCORE} AS score, s.gated_reason, s.prompt"
|
||||
order = "score DESC, " + order
|
||||
order = (_BY_CV if by_cv else "") + "score DESC, " + order
|
||||
elif open_only:
|
||||
# Same reasoning as `roles`: the planner otherwise sorts every
|
||||
# open role before applying LIMIT.
|
||||
sql = sql.replace("FROM roles ", "FROM roles INDEXED BY idx_roles_posted ", 1)
|
||||
rows = self._rows(f"{select} {sql} ORDER BY {order} LIMIT ? OFFSET ?",
|
||||
[*params, limit, offset])
|
||||
mine = self._languages_of(agent)
|
||||
found = []
|
||||
for r in rows:
|
||||
row = dict(r)
|
||||
row["excerpt"] = excerpt(row["excerpt"])
|
||||
row["lang_flag"], row["lang_note"] = language_flag(
|
||||
role_languages(row.pop("languages_required")), mine)
|
||||
found.append(RoleRow.from_row(row))
|
||||
by_uid = self._tags_by_uid([f.uid for f in found])
|
||||
copies = self._copy_counts([f.uid for f in found])
|
||||
@@ -1206,14 +1247,16 @@ class Store:
|
||||
gated: bool = False, judged: str | None = None,
|
||||
pay: str | None = None, company_keys: Sequence[str] = (),
|
||||
places: Sequence[str] = (), seniority: Sequence[str] = (),
|
||||
seniority_unknown: bool = True, pay_unknown: bool = False) -> int:
|
||||
seniority_unknown: bool = True, pay_unknown: bool = False,
|
||||
by_cv: bool = False, closing: bool = False) -> int:
|
||||
"""How many roles `roles` would list with the same filters and no limit."""
|
||||
sql, params = self._roles_from(
|
||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
||||
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown)
|
||||
seniority=seniority, seniority_unknown=seniority_unknown, pay_unknown=pay_unknown,
|
||||
closing=closing)
|
||||
row = self._row(f"SELECT COUNT(*) AS n {sql}", params)
|
||||
return int(row["n"]) if row else 0
|
||||
|
||||
@@ -1227,7 +1270,8 @@ class Store:
|
||||
pay: str | None = None, company_keys: Sequence[str] = (),
|
||||
places: Sequence[str] = (), seniority: Sequence[str] = (),
|
||||
seniority_unknown: bool = True,
|
||||
pay_unknown: bool = False) -> dict[str, list[tuple[str, int]]]:
|
||||
pay_unknown: bool = False, by_cv: bool = False,
|
||||
closing: bool = False) -> dict[str, list[tuple[str, int]]]:
|
||||
"""How many roles `roles` would list at each seniority level and each
|
||||
pay state, each counted with every other filter and its own left
|
||||
out, so the rail can say what a click would add. `seniority` is every
|
||||
@@ -1239,7 +1283,7 @@ class Store:
|
||||
"function": function, "remote": remote, "days": days, "hide_muted": hide_muted,
|
||||
"include_read": include_read, "tags": tags, "tag_mode": tag_mode, "agent": agent,
|
||||
"by_score": by_score, "gated": gated, "judged": judged,
|
||||
"company_keys": company_keys, "places": places}
|
||||
"company_keys": company_keys, "places": places, "closing": closing}
|
||||
by_level, level_params = self._roles_from(
|
||||
**shared, pay=pay, pay_unknown=pay_unknown)
|
||||
by_pay, pay_params = self._roles_from(
|
||||
@@ -1261,12 +1305,15 @@ class Store:
|
||||
pay: str | None = None, company_keys: Sequence[str] = (),
|
||||
places: Sequence[str] = (), seniority: Sequence[str] = (),
|
||||
seniority_unknown: bool = True,
|
||||
pay_unknown: bool = False) -> tuple[str, list[Any]]:
|
||||
pay_unknown: bool = False,
|
||||
closing: bool = False) -> tuple[str, list[Any]]:
|
||||
"""The `FROM ... WHERE ...` that `roles` and `count_roles` share, with
|
||||
its parameters in order. The agent's votes are always joined as `v`
|
||||
(see `_WITH_VOTES`); its scores as `s` only when ordering by them. A
|
||||
copy of another role (`rebuild_dupes`) is never listed: its kept role
|
||||
stands for it and counts its copies."""
|
||||
(see `_WITH_VOTES`) and its judgements as `j` (`_WITH_JUDGEMENTS`);
|
||||
its scores as `s` only when ordering by them. A copy of another role
|
||||
(`rebuild_dupes`) is never listed: its kept role stands for it and
|
||||
counts its copies. `closing` keeps the roles whose deadline is
|
||||
today or within `CLOSING_DAYS` after it."""
|
||||
where: list[str] = ["roles.dup_of IS NULL"]
|
||||
params: list[Any] = []
|
||||
if company:
|
||||
@@ -1312,6 +1359,10 @@ class Store:
|
||||
params.append(agent)
|
||||
if not include_read:
|
||||
where.append("roles.read_at IS NULL")
|
||||
if closing:
|
||||
today = self.clock().date()
|
||||
where.append("roles.deadline BETWEEN ? AND ?")
|
||||
params += [today.isoformat(), (today + timedelta(days=CLOSING_DAYS)).isoformat()]
|
||||
if tags:
|
||||
marks = ", ".join("?" for _ in tags)
|
||||
if tag_mode == "all":
|
||||
@@ -1331,8 +1382,8 @@ class Store:
|
||||
clause, values = _places_sql(places, self.gazetteer(), scope=self._scope(agent))
|
||||
where.append(clause)
|
||||
params += values
|
||||
sql = f"FROM roles {_WITH_VOTES}"
|
||||
joins: list[Any] = [agent]
|
||||
sql = f"FROM roles {_WITH_VOTES} {_WITH_JUDGEMENTS}"
|
||||
joins: list[Any] = [agent, agent]
|
||||
if agent is not None and by_score:
|
||||
sql += " JOIN scores s ON s.uid = roles.uid AND s.agent_id = ?"
|
||||
joins.append(agent)
|
||||
|
||||
Reference in new issue
Block a user