Compose remote as model, host word, place line and map a remote role's area in prep

The area is the model's names, else the parts of the place texts that say remote, else the resolved places as their countries. VERSION 3 maps every open role again. run_roles maps the roles extract answered. "Remote Sensing" in a title is no remote work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 16:00:06 +02:00
1 parent 57cac5f896
commit e4c0de4465
5 files changed
+139 -36

No files matched your search

+53 -16
View File
@@ -3,14 +3,17 @@
A pull stores the host's own words and place texts (`Store.upsert_role`)
and marks the role due. `run` maps every due role: its company through
`company_aliases`, its places against the gazetteer, its level, contract
and remote through the host's tables (`app.prep.words`), and its country
from the places (`app.prep.country`). When the tables or the gazetteer in
code (`places.seed`) changed since the last run (`fingerprint`, kept in
state as `prep:tables`), the new places and spellings are added to the
database and every open role is mapped again from its stored words, with
no new pull. Then the words no
table knows are listed in `unmapped`, and `Store.rebuild_dupes` folds the
copies across the whole database.
and remote through the host's tables (`app.prep.words`), its country from
the places (`app.prep.country`), and a remote role's area
(`app.prep.area`). `remote` is the model's (`remote_model`), else the
host's word, else what the place line or a search role's title says. When
the tables or the gazetteer in code (`places.seed`) changed since the last
run (`fingerprint`, kept in state as `prep:tables`), the new places and
spellings are added to the database and every open role is mapped again
from its stored words, with no new pull. Then the words no table knows are
listed in `unmapped`, and `Store.rebuild_dupes` folds the copies across the
whole database. `run_roles` maps a few roles outside a run, for `extract`,
whose model answer changes remote and area.
"""
from __future__ import annotations
@@ -24,14 +27,16 @@ from app import places
from app.models import company_key
from app.models import company_fold
from app.prep import words
from app.prep.area import area
from app.prep.country import country, of_host
from app.prep.hosts import TABLES
from app.prep.words import Tables
from app.storage import Store
#: Raised when the rules in this package change the way a stored word maps,
#: so every open role is mapped again as it is after a table changes.
VERSION = 2
#: so every open role is mapped again as it is after a table changes. 3: the
#: remote area, and remote as the model's before the host's word.
VERSION = 3
#: The state key the last run's `fingerprint` is kept under.
STATE = "prep:tables"
@@ -75,11 +80,30 @@ def _places(raw: Any) -> list[Any]:
return found if isinstance(found, list) else []
def _texts(row: Mapping[str, Any]) -> list[str]:
"""The role's place texts: `raw`'s places, else the line cut at `;`."""
given = _places(row["raw_places"])
return [words.place_text(p) for p in given] if given \
else str(row["place"] or "").split(";")
def _model_names(raw: Any) -> list[str] | None:
"""`remote_where_model` read: None never asked, else the names."""
if raw is None:
return None
return [str(name) for name in _places(raw)]
def map_role(row: Mapping[str, Any], gaz: places.Gazetteer, folds: Mapping[str, Sequence[str]],
place_ids: Sequence[int], tables: Tables = TABLES) -> dict[str, Any]:
"""One role as `Store.write_prep` takes it, from a `Store.prep_rows` row."""
host = str(row["host"] or "")
stated, titled = words.seniority(host, row["seniority_host"], row["title"], tables)
texts = _texts(row)
remote = row["remote_model"] \
or words.remote(host, row["remote_host"] or None, (), "", tables) \
or words.remote(host, None, _places(row["raw_places"]), row["place"], tables,
title=row["title"] if row["source"] == "search" else "")
return {
"uid": row["uid"],
"due": row["prep_due"],
@@ -87,10 +111,9 @@ def map_role(row: Mapping[str, Any], gaz: places.Gazetteer, folds: Mapping[str,
"seniority_stated": stated,
"seniority_title": titled,
"employment": words.employment(host, row["employment_host"], tables),
"remote": words.remote(host, row["remote_host"] or None, (), "", tables),
"remote_places": words.remote(
host, None, _places(row["raw_places"]), row["place"], tables,
title=row["title"] if row["source"] == "search" else ""),
"remote": remote,
"remote_area": list(area(gaz, texts, place_ids, _model_names(row["remote_where_model"]))
if remote == "remote" else ()),
"country": country(gaz, place_ids, row["country_host"]),
}
@@ -98,8 +121,8 @@ def map_role(row: Mapping[str, Any], gaz: places.Gazetteer, folds: Mapping[str,
def _changed(row: Mapping[str, Any], found: Mapping[str, Any]) -> bool:
level = row["seniority_model"] or found["seniority_stated"] or found["seniority_title"]
return bool(row["prep_due"]) or level != row["seniority"] \
or (found["remote"] and found["remote"] != row["remote"]) \
or (found["remote_places"] and not row["remote"]) \
or found["remote"] != row["remote"] \
or found["remote_area"] != json.loads(row["remote_area"] or "[]") \
or (found["country"] and found["country"] != row["country"]) \
or any(found[c] != row[c] for c in ("company_key", "seniority_stated",
"seniority_title", "employment"))
@@ -143,3 +166,17 @@ def run(store: Store, *, remap: bool = False, tables: Tables = TABLES,
copies = store.rebuild_dupes().copies if dupes else None
return Prepped(read=len(rows), written=len(written), remapped=whole, unmapped=len(left),
copies=copies)
def run_roles(store: Store, uids: Sequence[str], tables: Tables = TABLES) -> int:
"""Map these roles now, due or not, and nothing else: what `extract`
calls for the roles it answered, so the rescore that follows sees the
model's remote and area. Returns the rows written."""
if not uids:
return 0
rows = store.prep_rows("all", uids=uids)
ids = store.resolve_role_places([r["uid"] for r in rows])
gaz = store.gazetteer()
folds = store.company_folds()
return store.write_prep([map_role(r, gaz, folds, ids.get(r["uid"], ()), tables)
for r in rows])