Files
jobboard/app/seniority.py
T
WolfandClaude Opus 5.5 322db49773 Title levels on the ladder: principal, senior manager, distinguished, lead split (WP A)
from_title matches a title twice, for the highest people level and the
highest individual grade. A people level wins on its own rung; a grade
above that rung lifts it one rung (Principal Engineering Manager is a
senior manager). Senior Staff is principal, Senior Principal, Distinguished
and Technical Fellow are distinguished; Associate Director, AVP and Senior
Manager are senior managers. lead is now a team lead only (Team Lead, Shift
Lead, Supervisor, Teamleiter); Tech Lead, Lead X and X Lead(er) are staff.
A slash names two levels, so Senior/Staff is staff.

- Jobylon "lead" maps to staff; Recruitee maps student_college, manager,
  senior_manager and executive.
- extract's prompt describes the ladder and its two tracks; enum from LEVELS.
- prep VERSION 2, so the next prep maps every open role again.
- Migration 25 clears seniority_model where it is staff, lead, manager or
  director, so extract reads those roles again, and sets roles.seniority to
  the first filled of model, stated and title.
- The coverage test of tests/test_seniority.py passes; its xfail is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 13:11:26 +02:00

314 lines
17 KiB
Python

"""`from_title`: the level a job title names, as one of `SENIORITIES`, or `''`.
What fills `roles.seniority` at ingest, before `extract` has read the posting
(which overwrites it). `''` and not `"mid"` when the title does not say:
most titles name no level, and a filter that treats "does not say" as a level
loses every role it could not read. So every rule here is written for
precision, and a title that matches nothing stays unknown.
The approach is `plugins/ats.classify`'s, after its substring matches went
wrong (" it" inside "Italy"): the title is folded with `title_key` (case,
accents and the `(m/w/d)` marker gone, punctuation to spaces) and every
pattern is a word-bounded regex against that. Patterns are therefore written
folded: `direktör` is `direktor`, `chef d'équipe` is `chef d equipe`; `ø` and
`æ` stay as they are, since NFKD does not decompose them.
The levels are the ladder of `app.models.LADDER`: from `staff` up, a rung has
an individual-contributor level and a people-lead level. A title is matched
twice, for the highest people level it names (`_PEOPLE`: a head, a manager,
a team lead) and for the highest individual grade (`_GRADES`: Principal,
Staff, Senior). A people level wins over a grade on its own rung or below:
"Staff Engineering Manager" is a manager, "Senior Director" a director. A
grade above the people level's rung lifts it one rung, and one only:
"Principal Engineering Manager" is a senior manager. Without a people level
the grade decides: "Principal Product Manager" is principal, since a product
manager is an individual contributor. A slash names two levels (`_OR`):
"Senior/Staff Engineer" is staff, not a Senior Staff. The one exception is `intern`, tried
first: a title that says internship or thesis is one whatever it names after
("Praktikum ... Assistenz des Senior Vice Presidents"). A C-level or head
named as the boss of the person hired ("Executive Assistant to the CEO",
"Office of the Head of ...") is cut out before matching (`_NOISE`). Rules
that decide the doubtful cases:
- **exec** is C-level ("Chief ... Officer", CTO), "VP" and above (a bank's VP
is mid-level, but a tech company's is not, and the filter is the reader's:
exec), "Managing Director", Geschäftsführer, Vorstand and VD.
- **director** is the word in English, Danish, Swedish, German, French,
Spanish and Italian, "Head of" and a title's own first word "Head", and the
German "Leiter" alone or of a whole department (Bereichsleiter,
Abteilungsleiter). "Senior Director" and "Executive Director" are directors.
- **senior_manager** is "Senior Manager", a senior people manager ("Sr.
Engineering Manager"), "Associate Director", "Assistant Director" and a
bank's "Assistant Vice President" (AVP, Associate VP).
- **manager** is a level only where the word means someone who runs a team:
a bare "Manager", "Manager, Data Science" (the word first, as a level), and
the compounds whose department or place is what is managed
(`_PEOPLE_MANAGER`: engineering, team, store, general ...), and a "Tech
Lead Manager". Every other "X
Manager" is an individual contributor by function (Account, Product,
Project, Customer Success, Office, Marketing, Sales ...) and says nothing,
so "Senior Product Manager" is senior. An unlisted compound stays unknown,
which costs a recall the filter's "and no level" makes up. **manager** is
also the head of a shop, site or office: "Store Leader", the Danish,
Swedish, German and Dutch -chef, -leder, Filialleiter, Kontorchef, French
"responsable" and "gérant", Spanish "jefe" and "gerente".
- **lead** is a team lead: "Team Lead", "Team Leader", the floor-sized leads
(`_TEAM_SIZED_LEAD`: shift, crew, kitchen ...), a "People Leader",
"Supervisor", an "Assistant Store Manager" or "Associate Store Leader", and
the team-sized German, Danish, Dutch, Swedish and French forms (Teamleiter,
Teamleider, teamledare, chef d'équipe).
- **distinguished** is "Senior Principal", "Distinguished", "Technical
Fellow", "Engineering Fellow" and SAP's "Chief Expert". "Fellow" alone is
academic ("Research Fellow", "Postdoctoral Fellow") and says nothing.
- **principal** is "Principal" and "Senior Staff".
- **staff** is "Staff", and "Lead" or "Leader" as a noun at either end that
is not a team lead ("Tech Lead", "Lead Engineer", "Marketing Lead", "Sales
Leader"; not "Lead Generation"). "Staff Nurse", "Staff Accountant" and their
kind are left out.
- **project managers stay unknown** in every language (Projektleiter,
Bauleiter, chef de projet, projektleder, prosjektleder): they are Project
Managers. Halbleiter and the other -leiter words for things are cut out too.
- **intern** is anything that says the person is still studying or training:
intern, Werkstudent, Praktikant, stagiaire, Ausbildung, apprentice,
elev, studentermedhjælper, a thesis. **junior** is "Junior", "Graduate",
"Trainee" and "entry level". **mid** only when the title says so:
"Mid-level", "Intermediate", "II", "Medior".
Known wrong, and left so: "Senior Care Assistant" and other "senior" that
means elderly; "Level II" outside a role level; "Principal Investigator" and
a "Staff Scientist" at a lab as principal and staff; "Staff" on a title with
an unlisted staff noun; a retail "Lead Store Advisor" and a "Sales Leader"
who runs a team as staff; "Distinguished Engineer, Team Lead" as a senior
manager, one rung above the lead; "Field CTO" taken as unknown; "Chief of
Staff" as unknown; "Assistant Manager" as unknown; French "responsable" is
taken as a manager wherever it stands, and "Directeur" of a small firm as a
director; "VP" as exec at a bank.
"""
from __future__ import annotations
import re
from app.models import LADDER, title_key
#: A C-level title or abbreviation, for `_NOISE`.
_C_LEVEL = (r"(?:ceo|cto|cfo|coo|cio|ciso|cpo|cdo|chro|caio"
r"|chief(?: \w+){0,3} officer|managing director|(?<!vice )president"
r"|geschaftsfuhr\w*|geschaftsfuhrung|vorstand)")
#: A vice president, which the phrases below take as a boss only after "to the",
#: not after "assistant" ("Assistant Vice President" is a director).
_VP = r"(?:vice president|[se]?vp)"
#: Phrases that carry a level word without naming a level, cut out of the
#: folded title before anything is matched: "Chief of Staff" is not "Staff",
#: "Executive Assistant to the CEO" is not a CEO, "Lead Generation" is not a
#: Lead. What a title says after "reporting to" is about someone else.
_NOISE = re.compile(
r"\b(?:chief of staff|member of technical staff|technical staff"
r"|(?:support|kitchen|wait|nursing|field|floor|retail|store|clinical|medical"
r"|teaching|academic|administrative|hospital|bar|service|office|warehouse"
r"|hotel|catering|cabin|restaurant|casual|agency|temporary|volunteer|library"
r"|hourly|seasonal|healthcare|sales|customer) staff"
r"|staff (?:accountant|nurse|attorney|pharmacist|auditor|writer|reporter"
r"|assistant|augmentation|admin|augment|nurses)"
r"|lead (?:gen(?:eration)?|development rep\w*|qualification|nurturing"
r"|scoring|capture|to (?:cash|revenue))"
rf"|(?:to|for|of|des|der) (?:the |dem |den )?(?:{_C_LEVEL}|{_VP})"
rf"|(?:assistant|assistenz|assistent|secretary|sekretar\w*|business partner|coordinator"
rf"|office|support|referent\w*|advisor|adviser) (?:\w+ ){{0,3}}?{_C_LEVEL}"
rf"|{_C_LEVEL} (?:assistant|assistenz|office|team|support|founder associate)"
r"|field (?:cto|cio|ciso)"
r"|(?:technical|engineering|technology) fellows? office"
r"|\w*(?:halb|nicht|supra|strom|blitzab)leiter"
r"|\w*(?:projekt|prosjekt|project|bau|bygge|produkt)(?:leiter|leitung|leder|ledare|leider)(?:in)?"
r"|zugchef\w*)\b"
r"|\breport(?:s|ing)? to\b.*",
)
#: "X Manager" where the manager runs a team, a site or a shop; see the
#: docstring. Only the word directly before "manager" counts.
_PEOPLE_MANAGER = (
r"(?:engineering|software development|science|research|hardware|team|department"
r"|group|store|branch|restaurant|shift|warehouse|site|plant|area|district"
r"|regional|country|general)")
#: The stems of the -leiter/-leder words that are a team lead, not a manager.
_TEAM_SIZED = r"(?:team|gruppen?|grupp|schicht|hold|vagt)"
#: Words after a title-initial "Head" that make it a job of its own (Head
#: Chef), not the head of a function.
_HEAD_JOBS = (r"(?:chef|cook|barista|nurse|coach|waiter|bartender|mechanic|gardener"
r"|teacher|cashier|housekeeper|receptionist|technician|butcher|baker"
r"|stylist|of)")
#: Floor-sized leads, which run a shift or a crew: "Shift Lead" and "Crew
#: Leader" are team leads where "Marketing Lead" is an individual.
_TEAM_SIZED_LEAD = r"(?:team|shift|crew|group|kitchen|warehouse|floor)"
#: What says the person is still studying or training, tried before
#: anything else: a title that says internship is one whatever it names
#: after ("Internship, Office of the Head of Product").
_INTERN: tuple[str, ...] = (
r"\binterns?\b", r"\binternship\w*", r"\bwerkstudent\w*", r"\bworking students?\b",
r"\bstudent (?:assistant|worker|helper|aide|job|position|trainee|employee)s?\b",
r"\bstudentische\w*", r"\bstudent(?:er)?med(?:hj|arb)\w*",
r"\bstudent\w*job\w*", r"\bjobstudent\b",
r"\w*praktik(?:um|ant\w*|a|ophold|plads)?\b", r"\bpraxissemester\b", r"\bduales? studium\b",
r"\bstagiaires?\b", r"\bstagiair\w*", r"\bstagista\b", r"\btirocin\w*",
r"\bestagiari[oa]s?\b", r"\bbecari[oa]s?\b", r"\bpracticas\b", r"\bpracticante\b",
r"\baprendiz\b", r"\balternan\w*", r"\bapprenti(?:e|es|s)?\b", r"\bapprentice\w*",
r"\bazubi\b", r"\bauszubildende\w*", r"\bausbildung\b", r"\blehr(?:ling|ausbildung|stelle)\b",
r"\w*lærling\w*", r"\b\w*elev\b",
r"\b\w+student\b", r"(?<!phd )(?<!doctoral )(?<!graduate )(?<!masters )\bstudent$",
r"\bvolontar\w*",
r"\b(?:master|bachelor|abschluss)arbeit\b", r"\bthesis\b",
r"\bmasterproef\b", r"\beindwerk\b", r"\bafstudeer\w*",
# French and Dutch "stage": a title that starts or ends with it, or
# says how many months, and not the English stage (Stage Manager, early stage).
r"^stage\b(?! (?:manager|management|hand|crew|technician|director|lighting|door))",
r"(?<!early )(?<!late )(?<!growth )(?<!seed )(?<!mid )(?<!next )(?<!final )"
r"(?<!pre )(?<!first )(?<!phase )\bstage$",
r"\bstage (?:\d+ )?(?:mois|mesi|maanden|months)\b",
)
#: `(level, patterns)` of the people track, from `exec` down. A title takes
#: the first level with a match, so a rule need not exclude what a later rule
#: claims.
_PEOPLE: tuple[tuple[str, tuple[str, ...]], ...] = (
("exec", (
r"\b(?:ceo|cto|cfo|coo|cio|ciso|cpo|cdo|chro|caio)\b",
r"\bchief(?: \w+){0,4}? officer\b", r"\bchief executive\b",
r"(?<!assistant )(?<!associate )(?<!assoc )\b(?:vice president|[se]?vp)\b",
r"(?<!vice )\bpresident\b",
r"\bmanaging director\b", r"\b(?:administrerende|verkstallande) direktor\b",
r"\badministrerende direktør\b", r"\bvd\b", r"\bpdg\b",
r"\bdirecteur general\b", r"\bdirector general\b",
r"\bgeschaftsfuhr\w*", r"\bgeschaftsleit\w*", r"\bvorstand\b",
)),
("director", (
r"(?<!associate )(?<!assoc )(?<!assistant )(?<!asst )"
r"\b(?:director(?:a|s|es|in)?|directeur|directrice|direktor(?:in|er)?"
r"|direktør(?:er)?|direttore|direttrice)\b",
r"\bhead of\b", r"\b(?:department|division|unit|practice|group|team|country|regional) head\b",
rf"^head (?!{_HEAD_JOBS}\b)", r"\bhead$",
# Leiter(in) alone or of a whole unit (Bereichsleiter), and a title that
# starts with Leitung; "mit technischer Leitung" is a job with a duty.
r"\bleiter(?:in)?\b", r"^leitung\b",
r"\b(?:bereichs|abteilungs|hauptabteilungs|geschaftsbereichs|vertriebs"
r"|entwicklungs|werks)leit(?:er|erin|ung)\b",
r"\bhoofd\b",
)),
("senior_manager", (
r"\b(?:associate|assoc|assistant|asst) director\b",
r"\bavp\b", r"\b(?:assistant|associate|assoc) (?:vice president|vp)\b",
rf"\b(?:senior|sr|snr) (?:{_PEOPLE_MANAGER} )?manager\b",
)),
("manager", (
r"^(?:(?:global|regional|group|executive) )*manager\b",
rf"(?<!assistant )(?<!deputy )(?<!asst )\b{_PEOPLE_MANAGER} manager\b",
r"\btech lead manager\b", r"(?<!associate )\bstore lead(?:er)?\b",
# -leiter / -leder / -leider of a shop, site or department: Filialleiter,
# Afdelingsleder. The team-sized ones are lead (below), and project ones
# are cut out by _NOISE. A -leitung is only these, since "Rohrleitung"
# is a pipe.
rf"\b(?!{_TEAM_SIZED}\w*leit)\w+leit(?:er|erin)\b",
r"\b(?:filial|standort|betriebs|service|niederlassungs|markt|geschafts)leitung\b",
rf"\b(?!{_TEAM_SIZED}\w*led)\w+leder\b", r"\bleder\b",
rf"\b(?!{_TEAM_SIZED}\w*leid)\w+leider\b", r"\bleidinggevende\b",
# Danish and Swedish compounds (kontorchef, avdelningschef); a bare
# "chef" is a cook or French and says nothing.
r"\b\w{3,}chef(?:er|en)?\b",
r"\b(?:drift|avdelnings|enhets|verksamhets|butiks|lager|produktions)ledare\b",
r"\bchef (?:for|fur|i|til|inom|over|pa|av)\b",
r"\bchef d(?:e|u)? (?:service|departement|secteur|magasin|rayon|agence|site"
r"|pole|atelier|production)\b",
r"\bresponsable\b(?! adjoint| d(?:e|u|es)? projets?\b)", r"(?<!assistant )\bgerant\w*", r"\bgerente\b",
r"\bjef[ea]\b(?! d(?:e|el) (?:equipo|proyecto|obra)\b)",
r"\bresponsabile\b",
)),
("lead", (
rf"\b{_TEAM_SIZED_LEAD} ?lead(?:er)?s?\b",
r"\bsupervisor\b", r"\bsuperviseur\b",
rf"\b(?:assistant|deputy|asst) {_PEOPLE_MANAGER} manager\b",
r"\bassociate store leader\b", r"\bpeople leader\b",
r"\b(?:team|gruppen?|schicht|hold|vagt)(?:leit(?:er|erin|ung)|leder|leider)\b",
r"\b(?:team|grupp)?ledare\b", r"\bchef(?: fe)? d equipe\b",
r"\blider de equip[oe]\b", r"\bjef[ea] de equipo\b",
)),
)
#: `(level, patterns)` of the individual grades, from the highest down, as
#: `_PEOPLE`: "Senior Principal" is tried before "Principal".
_GRADES: tuple[tuple[str, tuple[str, ...]], ...] = (
("distinguished", (
r"\b(?:senior|sr|snr) principal\b", r"\bdistinguished\b",
r"\b(?:technical|engineering|technology) fellow\b",
# SAP's top individual-contributor grade.
r"\bchief expert\b",
)),
("principal", (
r"\b(?:senior|sr|snr) staff\b", r"\bprincipal\b",
)),
("staff", (
r"\bstaff\b",
# "Lead" the noun at either end; the team leads are `_PEOPLE`'s.
r"\b(?:tech)?lead\b", r"\bleader\b", r"\blider\b",
)),
("senior", (
r"\b(?:senior|sr|snr|iii)\b",
)),
("mid", (
r"\bmid ?level\b", r"\bintermediate\b", r"\bii\b", r"\bmedior\b",
r"\bconfirme\b",
)),
("junior", (
r"\b(?:junior|jr|entry level|graduates?|grad|new grad|early careers?"
r"|young professional|absolvent\w*|berufseinsteiger\w*|debutant\w*)\b",
r"\btrainee\w*",
)),
)
def _compile(rules: tuple[tuple[str, tuple[str, ...]], ...]
) -> tuple[tuple[str, re.Pattern[str]], ...]:
"""Each level's patterns as one alternation, in the same order."""
return tuple((level, re.compile("|".join(f"(?:{p})" for p in patterns)))
for level, patterns in rules)
_INTERN_RE = re.compile("|".join(f"(?:{p})" for p in _INTERN))
_PEOPLE_RE = _compile(_PEOPLE)
_GRADES_RE = _compile(_GRADES)
#: The people level one rung above each people level, for a grade that lifts it.
_LIFT: dict[str, str] = {
level: next((up for up, (r, t) in LADDER.items() if t == "people" and r == rung + 1), level)
for level, (rung, track) in LADDER.items() if track == "people"}
#: A slash between two words, which `title_key` would fold to a space:
#: "Senior/Principal" names two grades, not a Senior Principal. The gender
#: marker's single letters (m/w/d) are left to `title_key`.
_OR = re.compile(r"(?<=\w\w|\w\.)\s*/\s*(?=\w\w)")
def _first(rules: tuple[tuple[str, re.Pattern[str]], ...], folded: str) -> str:
return next((level for level, pattern in rules if pattern.search(folded)), "")
def from_title(title: str) -> str:
"""The level `title` names, one of `SENIORITIES`, or `''` when it names
none. See the module docstring for what counts."""
folded = " ".join(_NOISE.sub(" ", title_key(_OR.sub(" or ", title or ""))).split())
if not folded:
return ""
if _INTERN_RE.search(folded):
return "intern"
people, grade = _first(_PEOPLE_RE, folded), _first(_GRADES_RE, folded)
if not people:
return grade
if grade and LADDER[grade][0] > LADDER[people][0]:
return _LIFT[people]
return people