diff --git a/README.md b/README.md
index 369d93c..d2edee1 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ The cog opens `/settings`: a rail of pages on the left, the page beside it, stic
| | |
|---|---|
-| **Search agents** | a card per agent, newest first: name, an On/Off switch, what it looks for, and its weights. Edit turns the card into the form in place (name, intent, weights, require/prefer gates behind an Advanced disclosure); New agent puts a blank card on top. Saving or switching on rescores; deleting one takes its votes, liked companies and scores with it |
+| **Search agents** | a card per agent, newest first: name, an On/Off switch, what it looks for, and its weights. Edit turns the card into the form in place (name, intent, weights, require/any/prefer gates behind an Advanced disclosure); New agent puts a blank card on top. Saving or switching on rescores; deleting one takes its votes, liked companies and scores with it |
| **Sources** | one page showing one section at a time, picked in the rail or by the URL fragment: job boards (queries on Jobindex or Adzuna: try, save, edit, remove), company boards (every company whose board is read, its open roles and its affinity for the picked agent, following a company) and runs (Run the pull now, what is running, the schedule, and the Problems log) |
| **Account** | the password, sessions and passkeys. Open on loopback, locked on anything else |
diff --git a/app/jobs/score.py b/app/jobs/score.py
index 335bea4..cf02428 100644
--- a/app/jobs/score.py
+++ b/app/jobs/score.py
@@ -4,8 +4,16 @@ A role is scored per agent, `(uid, agent) -> score`, because a role is only
good for a given search. For each agent:
require gates a role that fails one keeps its row, with score 0 and the
- reason ("place unknown", "remote not remote")
+ reason ("remote not remote")
+ any gates one group: a role that matches none of them, and has the
+ column filled for at least one, is gated ("none of
+ country DK / remote remote")
prefer gates `weight` when the role matches, 0 when it does not
+
+A gate rejects on evidence, never on absence: a role whose column is empty
+is not gated by it. `extract` is what fills an empty column, and it reads
+only the roles that rank, so gating on an empty column would keep those
+roles out of extract's reach for good.
fit cos(role vector, intent vector), min-max scaled across
the roles this agent scores in this run: the closest is 1,
the farthest 0, a lone role 1
@@ -117,21 +125,32 @@ def scale(cosines: dict[str, float]) -> dict[str, float]:
return {uid: (value - low) / (high - low) for uid, value in cosines.items()}
-def _reason(gate: Gate, state: int) -> str:
- if state < 0:
- return f"{gate.field} unknown"
+def _wanted(gate: Gate) -> str:
+ if gate.field == "salary_min":
+ return f"salary_min {min(gate.values, key=lambda v: float(v))}"
+ return f"{gate.field} {' / '.join(str(v) for v in gate.values)}"
+
+
+def _reason(gate: Gate) -> str:
if gate.field == "salary_min":
return f"salary_min under {min(gate.values, key=lambda v: float(v))}"
return f"{gate.field} not {' / '.join(str(v) for v in gate.values)}"
def failed_gates(candidate: Candidate, gates: Sequence[Gate]) -> list[str]:
- """Every require gate this role fails, as reasons. None for a favourite,
- which skips the gates."""
+ """Why this role is gated, as reasons: every require gate it fails, and
+ the `any` group when it matches none of them. A gate with an empty column
+ (state -1) neither passes nor fails, so the group fails only when some
+ member had evidence. None for a favourite, which skips the gates."""
if candidate.affinity == 2:
return []
- return [_reason(g, state) for g, state in zip(gates, candidate.gates, strict=True)
- if g.mode == "require" and state != 1]
+ states = list(zip(gates, candidate.gates, strict=True))
+ reasons = [_reason(g) for g, state in states if g.mode == "require" and state == 0]
+ group = [(g, state) for g, state in states if g.mode == "any"]
+ if group and not any(state == 1 for _, state in group) \
+ and any(state == 0 for _, state in group):
+ reasons.append("none of " + ", ".join(_wanted(g) for g, _ in group))
+ return reasons
def score_one(candidate: Candidate, gates: Sequence[Gate], weights: Weights,
diff --git a/app/main.py b/app/main.py
index 920d894..07d367c 100644
--- a/app/main.py
+++ b/app/main.py
@@ -46,9 +46,10 @@ def create_app(config: Config | None = None) -> FastAPI:
store = Store(config.database)
jobs.seed_agents(config, store)
jobs.seed_searches(config, store)
- # Roles pulled before `country` was read from `place` have none; after the
- # first start only the places the lookup cannot place are left to read.
- store.backfill_country()
+ # Roles stored before a word reached the place lookups have no country or
+ # remote from it; after the first start only the lines the lookups cannot
+ # read are left, and those are read again each start, which is cheap.
+ store.backfill_from_place()
app = FastAPI(title="roledesk", docs_url="/api/docs",
summary="ATS boards and job searches in, roles scored per search agent, "
diff --git a/app/models.py b/app/models.py
index 5336b67..70d44e6 100644
--- a/app/models.py
+++ b/app/models.py
@@ -188,6 +188,30 @@ def country_of(place: str) -> str:
Remote = Literal["", "remote", "hybrid", "onsite"]
REMOTE: tuple[str, ...] = get_args(Remote)
+#: Words in a location line that say how the role is worked, for a board that
+#: gives no remote flag of its own: Greenhouse writes "Remote", "Hybrid" or
+#: "Distributed" as the location and nothing else.
+_REMOTE_WORDS: tuple[tuple[str, str], ...] = (
+ ("hybrid", "hybrid"),
+ ("remote", "remote"), ("distributed", "remote"), ("home based", "remote"),
+ ("home-based", "remote"), ("work from home", "remote"), ("anywhere", "remote"),
+ ("worldwide", "remote"), ("telecommute", "remote"),
+ ("on-site", "onsite"), ("onsite", "onsite"), ("on site", "onsite"),
+ ("in-office", "onsite"), ("in office", "onsite"),
+)
+
+
+def remote_of(place: str) -> str:
+ """How a board's location line says the role is worked, as one of
+ `REMOTE`, or '' when it does not say. "Hybrid" wins over "remote" in the
+ same line ("Remote or hybrid, Berlin" is hybrid: some days in an office),
+ and a line that names only a place is ''."""
+ folded = _fold(place or "")
+ for word, mode in _REMOTE_WORDS:
+ if word in folded:
+ return mode
+ return ""
+
Seniority = Literal["", "intern", "junior", "mid", "senior", "staff", "lead", "manager",
"director", "exec"]
SENIORITIES: tuple[str, ...] = get_args(Seniority)
@@ -363,13 +387,16 @@ GateField = Literal["place", "country", "remote", "seniority", "function", "sala
"currency", "permit", "languages", "company"]
GATE_FIELDS: tuple[str, ...] = get_args(GateField)
-GateMode = Literal["require", "prefer"]
+GateMode = Literal["require", "any", "prefer"]
class Gate(Model):
"""One condition of an agent. `require` gates a role that fails it (the
- row is kept with the reason); `prefer` adds `weight` to its score when it
- matches."""
+ row is kept with the reason); the `any` gates together are one group a
+ role must match at least one of ("in Denmark, or remote"); `prefer` adds
+ `weight` to its score when it matches. A gate rejects on evidence only: a
+ role whose column is empty is not rejected, since `extract` fills the
+ column later for the roles that rank, and only for those."""
field: GateField
values: list[str | int | float] = Field(min_length=1)
diff --git a/app/storage/store.py b/app/storage/store.py
index 6c36787..c463971 100644
--- a/app/storage/store.py
+++ b/app/storage/store.py
@@ -23,7 +23,7 @@ from desk.models import Item
from app.models import (
AFFINITY, REMOTE, STATUSES, Agent, Application, ApplicationEvent, Candidate,
Company, Gate, Limits, Role, ScoredRole, Subscription, Weights, company_key,
- country_of, place_key, title_key,
+ country_of, place_key, remote_of, title_key,
)
from app.storage import schema
@@ -291,6 +291,7 @@ class Store:
}
row |= {name: str(raw.get(name) or "") for name in _RAW_TEXT}
row["country"] = row["country"] or country_of(place)
+ row["remote"] = row["remote"] or remote_of(place)
row |= {name: _int_or_none(raw.get(name)) for name in _RAW_INT}
keep_filled = ("company", "company_key", "place_key", "remote", "description",
@@ -608,14 +609,21 @@ class Store:
"UPDATE roles SET closed_at = ? WHERE subscription_id = ? AND closed_at IS NULL",
(self.now(), subscription_id))
- def backfill_country(self) -> int:
- """Fill `country` from `place` on every role that has none, the way
- `upsert_role` does for a new one. Returns how many it filled."""
- rows = self._rows("SELECT uid, place FROM roles WHERE country = '' AND place != ''")
- filled = [(code, r["uid"]) for r in rows if (code := country_of(r["place"]))]
+ def backfill_from_place(self) -> int:
+ """Fill `country` and `remote` from `place` on every role that has
+ none, the way `upsert_role` does for a new one, so a word added to the
+ lookups reaches the roles already stored. Returns how many columns it
+ filled."""
+ rows = self._rows("SELECT uid, place FROM roles "
+ "WHERE place != '' AND (country = '' OR remote = '')")
+ countries = [(code, r["uid"]) for r in rows if (code := country_of(r["place"]))]
+ remotes = [(mode, r["uid"]) for r in rows if (mode := remote_of(r["place"]))]
with self.transaction() as conn:
- conn.executemany("UPDATE roles SET country = ? WHERE uid = ?", filled)
- return len(filled)
+ conn.executemany("UPDATE roles SET country = ? WHERE uid = ? AND country = ''",
+ countries)
+ conn.executemany("UPDATE roles SET remote = ? WHERE uid = ? AND remote = ''",
+ remotes)
+ return len(countries) + len(remotes)
# -------------------------------------------------------------- extract
diff --git a/app/templates/settings/agents.html b/app/templates/settings/agents.html
index 08e0dae..d95264f 100644
--- a/app/templates/settings/agents.html
+++ b/app/templates/settings/agents.html
@@ -42,7 +42,7 @@
[{"field": "country", "values": ["DK"], "mode": "any"}, {"field": "remote", "values": ["remote"], "mode": "any"}, {"field": "seniority", "values": ["senior", "staff"], "mode": "prefer", "weight": 0.05}] is "in Denmark, or remote". Fields: place, country, remote, seniority, function, salary_min, currency, permit, languages, company. EU is a role open anywhere in Europe. A rule only rejects a role whose column is filled; an empty one ranks until extract reads the posting.