With an agent named, the rail's tag, company and place counts, Remote included, cover the roles that agent's feed shows, past its fetch gate; and the affinity note names the order What I'm looking for.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-10-05 09:35:32 +02:00
1 parent 0b92f19f4d
commit 8c3c51dd9f
4 files changed
+106 -35

No files matched your search

+50 -24
View File
@@ -84,6 +84,15 @@ _EXTRACT_WAITING = ("(extracted_at IS NULL OR seniority_model = '' OR remote_whe
_IN_CUT = ("r.uid IN (SELECT s.uid FROM scores s JOIN agents a ON a.id = s.agent_id "
"AND a.enabled = 1 WHERE s.cut <> '')")
#: A role one agent's feed shows, as a `WHERE` on `r` taking the agent's id
#: twice: its fetch gate let the role through (`_roles_from` with
#: `fetch_gate`), and the company is not one it hid. With the open and kept
#: copy test, what the rail's counts for that agent cover.
_SHOWN = ("EXISTS (SELECT 1 FROM scores s WHERE s.uid = r.uid AND s.agent_id = ? "
"AND s.gated_reason = '') "
"AND r.company_key NOT IN (SELECT company_key FROM agent_companies "
"WHERE agent_id = ? AND affinity = -1)")
#: The order within one agent's cut, over its scores as `s`: in by fit, best
#: fit first, then in by CV closeness, closest first, then kept.
_CUT_ORDER = ("CASE s.cut WHEN 'fit' THEN 0 WHEN 'cv' THEN 1 ELSE 2 END, "
@@ -1521,14 +1530,19 @@ class Store:
return [g for g in found.gates if g.field == "country" and g.mode == "require"] \
if found is not None else []
def tag_counts(self, agent_id: int | None = None) -> list[tuple[str, int, int]]:
def tag_counts(self, agent_id: int | None = None,
fetch_gate: bool = False) -> list[tuple[str, int, int]]:
"""`(tag, open_count, unread_count)` over open roles, most-used tag
first and then alphabetically. What `/api/filters` serves; the
companies `agent_id` hid are left out, as in `roles`, and with no
agent nothing is hidden."""
agent nothing is hidden. With `fetch_gate`, only the roles the
agent's feed shows count (`_SHOWN`)."""
where = "r.closed_at IS NULL AND r.dup_of IS NULL"
params: list[Any] = []
if agent_id is not None:
if agent_id is not None and fetch_gate:
where += f" AND {_SHOWN}"
params += [agent_id, agent_id]
elif agent_id is not None:
where += (" AND r.company_key NOT IN (SELECT company_key FROM agent_companies "
"WHERE agent_id = ? AND affinity = -1)")
params.append(agent_id)
@@ -2624,25 +2638,30 @@ class Store:
"SELECT company_key, COUNT(*) AS n FROM roles "
"WHERE closed_at IS NULL AND dup_of IS NULL GROUP BY company_key")}
def open_companies(self, agent_id: int | None = None
def open_companies(self, agent_id: int | None = None, fetch_gate: bool = False
) -> list[tuple[str, list[str], int, int]]:
"""`(company_key, names, open roles, affinity)` for every company with
an open role, what the Company field suggests from. `names` are the
company row's name and then every spelling its roles carry, commonest
first, so a search finds a company by any of them. A company
`agent_id` hid is left out; `affinity` is that agent's, 0 without
one. Copies are not counted, as in the feed."""
one. Copies are not counted, as in the feed. With `fetch_gate`, only
the roles the agent's feed shows count (`_SHOWN`), and a company with
none of them is left out."""
gate, params = "", [agent_id]
if agent_id is not None and fetch_gate:
gate, params = f"AND {_SHOWN}", [agent_id, agent_id, agent_id]
rows = self._rows(
"""SELECT r.company_key AS key, r.company AS name, COUNT(*) AS n,
c.name AS own, COALESCE(ac.affinity, 0) AS affinity
FROM roles r
LEFT JOIN companies c ON c.key = r.company_key
LEFT JOIN agent_companies ac ON ac.company_key = r.company_key
AND ac.agent_id = ?
WHERE r.closed_at IS NULL AND r.dup_of IS NULL AND r.company_key != ''
AND COALESCE(ac.affinity, 0) != -1
GROUP BY r.company_key, r.company
ORDER BY r.company_key, n DESC, r.company""", (agent_id,))
f"""SELECT r.company_key AS key, r.company AS name, COUNT(*) AS n,
c.name AS own, COALESCE(ac.affinity, 0) AS affinity
FROM roles r
LEFT JOIN companies c ON c.key = r.company_key
LEFT JOIN agent_companies ac ON ac.company_key = r.company_key
AND ac.agent_id = ?
WHERE r.closed_at IS NULL AND r.dup_of IS NULL AND r.company_key != ''
AND COALESCE(ac.affinity, 0) != -1 {gate}
GROUP BY r.company_key, r.company
ORDER BY r.company_key, n DESC, r.company""", params)
found: dict[str, tuple[list[str], list[int], int]] = {}
for r in rows:
names, counts, _ = found.setdefault(
@@ -2653,24 +2672,31 @@ class Store:
return [(key, names, sum(counts), affinity)
for key, (names, counts, affinity) in found.items()]
def open_places(self) -> list[tuple[str, str, int]]:
def open_places(self, agent_id: int | None = None) -> list[tuple[str, str, int]]:
"""`(place, country, open roles)` for every place line an open role
carries, what `places.suggest` reads. Copies are not counted, as in
the feed."""
the feed. Given `agent_id`, only the roles that agent's feed shows
(`_SHOWN`)."""
gate, params = (f"AND {_SHOWN}", [agent_id, agent_id]) if agent_id is not None \
else ("", [])
return [(str(r["place"]), str(r["country"]), int(r["n"])) for r in self._rows(
"SELECT place, country, COUNT(*) AS n FROM roles "
"WHERE closed_at IS NULL AND dup_of IS NULL AND place != '' "
"GROUP BY place, country")]
"SELECT r.place, r.country, COUNT(*) AS n FROM roles r "
f"WHERE r.closed_at IS NULL AND r.dup_of IS NULL AND r.place != '' {gate} "
"GROUP BY r.place, r.country", params)]
def open_remote_areas(self) -> list[tuple[tuple[int, ...], int]]:
def open_remote_areas(self, agent_id: int | None = None
) -> list[tuple[tuple[int, ...], int]]:
"""`(area, open roles)` for every remote area an open remote role
holds, the area as place ids in order: what `places.suggest` counts
the remote tokens from. Copies are not counted, as in the feed."""
the remote tokens from. Copies are not counted, as in the feed.
Given `agent_id`, only the roles that agent's feed shows (`_SHOWN`)."""
gate, params = (f"AND {_SHOWN}", [agent_id, agent_id]) if agent_id is not None \
else ("", [])
found: dict[str, list[int]] = {}
for r in self._rows(
"SELECT rr.uid, rr.place_id FROM role_remote rr JOIN roles r ON r.uid = rr.uid "
"WHERE r.closed_at IS NULL AND r.dup_of IS NULL AND r.remote = 'remote' "
"ORDER BY rr.uid, rr.rowid"):
f"WHERE r.closed_at IS NULL AND r.dup_of IS NULL AND r.remote = 'remote' {gate} "
"ORDER BY rr.uid, rr.rowid", params):
found.setdefault(str(r[0]), []).append(int(r[1]))
return list(Counter(tuple(ids) for ids in found.values()).items())