diff --git a/app/seniority.py b/app/seniority.py new file mode 100644 index 0000000..158d4ca --- /dev/null +++ b/app/seniority.py @@ -0,0 +1,236 @@ +"""`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 highest level named wins, checked from `exec` down: "Senior Director" is +a director, "Managing Director" an exec, "Lead Project Manager" a lead. 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: + +- **manager** is a level only where the word means someone who runs a team: + a bare "Manager", "Senior Manager", "Manager, Data Science" (the word + first, as a level), an "Assistant Store Manager" as a lead, and the compounds whose department or place is what is + managed (`_PEOPLE_MANAGER`: engineering, team, store, general ...). 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. +- **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). + "Associate Director" and "Executive Director" are directors. **manager** is + also the Danish, Swedish, German and Dutch head of a shop, site or office + (-chef, -leder, Filialleiter, Kontorchef), French "responsable" and "gérant", + Spanish "jefe" and "gerente". **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. + A bank's "Assistant Vice President" is a director. +- **lead** is "Lead" as a noun at either end ("Tech Lead", "Lead Engineer"; + not "Lead Generation"), "Leader", "Supervisor", and the team-sized German, + Danish, Dutch and French forms (Teamleiter, Teamleider, chef d'équipe). +- **staff** is "Staff" and "Principal". "Staff Nurse", "Staff Accountant" + and their kind are left out; "Principal Investigator" and a + "Staff Scientist" at a lab are taken as staff and are not. +- **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"; +"Staff" on a title with an unlisted staff noun; "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 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|(? str: + """The highest level `title` names, one of `SENIORITIES`, or `''` when it + names none. See the module docstring for what counts.""" + folded = " ".join(_NOISE.sub(" ", title_key(title)).split()) + if not folded: + return "" + for level, patterns in _COMPILED: + if any(pattern.search(folded) for pattern in patterns): + return level + return "" diff --git a/tests/test_seniority.py b/tests/test_seniority.py new file mode 100644 index 0000000..78db68a --- /dev/null +++ b/tests/test_seniority.py @@ -0,0 +1,250 @@ +"""`app.seniority.from_title` against real titles from the 2026-09-29 snapshot, +one table, grouped by level, language and trap. No network, no database.""" + +# The titles are posted with en dashes and typographic apostrophes; the table keeps them. +# ruff: noqa: RUF001 + +from __future__ import annotations + +import sys +from pathlib import Path + +import pytest + +ROOT = Path(__file__).resolve().parents[1] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + +from app.models import SENIORITIES # noqa: E402 +from app.seniority import from_title # noqa: E402 + +#: `(title, level)`. A title stays in the table as it was posted, gender +#: marker and all, since `from_title` folds it itself. +TITLES: list[tuple[str, str]] = [ + # ---- exec + ("Chief Financial Officer - Satispay Bank", "exec"), + ("Chief Information Security Officer - Klarna Bank USA", "exec"), + ("Chief Operating Officer (COO) - (Relocation to Luxembourg)", "exec"), + ("COO TILL NORDISK CLEAN SOLUTIONS", "exec"), + ("CFO med blik for digitale løsninger", "exec"), + ("VP of Engineering - Foundational Platform", "exec"), + ("SVP of Sales - EMEA (m/f/x)", "exec"), + ("Regional Vice President - Enterprise East", "exec"), + ("Managing Director, Canada (m/f/d)", "exec"), + ("Managing Director Damstahl AB", "exec"), + # A C-level named as the boss of the person hired is not the level. + ("Executive Assistant to the President", ""), + ("Chief of Staff to CHRO", ""), + ("Praktikant:in Business Development (m/w/d) - CEO Office", "intern"), + ("Senior Executive Business Partner, CFO", "senior"), + # ---- director + ("Senior Director, Global Partnerships", "director"), + ("Sr. Director, Enterprise Data", "director"), + ("Director of Engineering (Data Infrastructure)", "director"), + ("Director, Pricing", "director"), + ("Associate Director, AI Strategy", "director"), + ("Assoc Director, Oral Sema", "director"), + ("Associate VP, Drug Product Manufacturing US Quality", "director"), + ("Head of Data & AI Platforms", "director"), + ("Head, Logistics Performance", "director"), + ("Head ASP Management", "director"), + ("Global Head of AV Driver Training", "director"), + ("Senior Manager, Head of Transaction Monitoring", "director"), + ("Directeur Financier - Afrique de l'Ouest", "director"), + ("Directeur·trice technique associé·e", "director"), + ("Direktør til Industriens Uddannelser", "director"), + ("Director/a de Logística", "director"), + ("[DACH MAG] Abteilungsleiter Produktion (all genders)", "director"), + ("[DACH MAG] Bereichsleiter Schicht (all genders)", "director"), + ("Regionaler Vertriebsleiter im Außendienst (m/w/d) Region nördliches NRW/ Niedersachsen/ Bremen", "director"), + # "Head Chef"-like titles and a duty that is only mentioned are not heads. + ("Augenoptikermeister mit technischer Leitung (m/w/d) in Berlin WILMA", ""), + ("Sous Chef", ""), + # ---- manager + ("Engineering Manager - Security Engineering", "manager"), + ("Sr. Engineering Manager - Notebook Dataplane", "manager"), + ("Senior Manager, Strategic Planning", "manager"), + ("Sr. Manager, Technical Delivery", "manager"), + ("Business Development Sr. Manager", "manager"), + ("Data Science Manager, Finance Analytics", "manager"), + ("Manager, Bid Management", "manager"), + ("Manager Sales Enablement", "manager"), + ("Country Manager", "manager"), + ("Store Manager (pandamart)", "manager"), + ("Team Manager Technischer Kundendienst (x/f/m)", "manager"), + ("Data Science Manager, Risk", "manager"), + ("Director/Sr Manager, Business Planning & GTM", "director"), + ("Filialleiter (m/w/d), LEGO Store Hannover", "manager"), + ("Kontorchef til Styrelsen for International Rekruttering og Integration (SIRI)", "manager"), + ("Försäljningschef till Nordic Polytech Group (NPG)", "manager"), + ("Driftsleder Sjåførorganisasjon", "manager"), + ("Enhedschef til borgernær akutsygepleje og tildelingsenhed, Afdeling for Borgernær Sundhed", "manager"), + ("Chef for Kommunikation", "manager"), + ("Gérant(e) - Responsable de magasin", "manager"), + ("Responsable Partenariats Terrain B2B H/F", "manager"), + ("Gerente de tienda", "manager"), + ("Jefe de Posventa", "manager"), + # Individual-contributor managers say nothing, or the level beside them. + ("Account Manager", ""), + ("Key Account Manager Ultrasound (all genders)", ""), + ("Product Manager (Agents)", ""), + ("Senior Product Manager", "senior"), + ("Project Manager", ""), + ("Customer Success Manager (DACH)", ""), + ("Office Manager - 9 month fixed term contract", ""), + ("Sales Manager (m/w/d) – Photovoltaik, Wärmepumpe & intelligente Energiesysteme - 1KOMMA5° Kiel", ""), + ("Technical Program Manager, Data Centers", ""), + ("Lead Project Manager (German speaker)", "lead"), + ("Assistant Store Manager (efood market) - Θεσσαλονίκη", "lead"), + ("Responsable de projets - Expériences Fever Originals", ""), + ("Chef de projet SEO et Marketing Digital H/F", ""), + ("Bauleiter AC (m/w/d) für Photovoltaik - 1KOMMA5° Handwerk - Region Bayern", ""), + ("Projektleder til produktion af færdigretter", ""), + ("Prosjektleder DTO", ""), + ("Technologie-Forschungsingenieur für Leistungshalbleiter (w/m/div.)", ""), + # ---- lead + ("Tech Lead, Deployment & Operations — Custom Infrastructure", "lead"), + ("Lead Data Engineer", "lead"), + ("Lead Engineer", "lead"), + ("Technical Lead- AI Cockpit", "lead"), + ("Engineering Team Lead - GateManager Platform", "lead"), + ("Teamlead Winkel Schoten (36u)", "lead"), + ("Complaints Team Leader - Claims", "lead"), + ("Supervisor, Wind Site - Sunzia, NM", "lead"), + ("Teamleiter im Bereich HR IT Support (w/m/div.)", "lead"), + ("Schichtleiter Warehouse Operations (all genders)", "lead"), + ("Gruppenleiter Softwareentwicklung (m/w/x)", "lead"), + ("Teamleider Winkel Eindhoven (32-40 uur)", "lead"), + ("Chef d'équipe Entrepôt Magasin", "lead"), + ("Chef·fe d’équipe - Modélisation (Unreal)", "lead"), + ("Superviseur magasin", "lead"), + # "Lead" the noun is a level, "lead" the sales lead is not. + ("B2B Demand Generation Specialist", ""), + # ---- staff + ("Staff Software Engineer - Money Movement", "staff"), + ("Senior Staff Software Engineer- Search Quality", "staff"), + ("Staff+ Software Engineer, Safeguards", "staff"), + ("Principal Software Engineer - Platform Engineering", "staff"), + ("Principal/Senior Principal Investment Accounting Solution Consultant – IAS Value Team", "staff"), + ("Business Process Chief Expert CIS", "staff"), + ("Member of Technical Staff - Research Infrastructure Engineer", ""), + ("Chief of Staff (m/w/d)", ""), + ("Staff Accountant", ""), + # ---- senior + ("Senior Site Reliability Engineer", "senior"), + ("Sr.Account Development Representative", "senior"), + ("Sr Software Engineer -Public Sector", "senior"), + ("(Senior) Product Manager - Energy (m/f/d)", "senior"), + ("Senior konsult till Knowit FLX", "senior"), + ("Chef.fe technique senior du développement - Rainbow Six Siege", "senior"), + ("Backend Engineer III", "senior"), + # ---- mid + ("Backend Engineer - Mid Level - Autopilot Team", "mid"), + ("Intermediate Backend Engineer - Database Change Management", "mid"), + ("Site Reliability Engineer II, China Tech", "mid"), + ("Medior Cloud Developer (AI Integrations)", "mid"), + ("Chef de produit trachéotomie confirmé F/H", "mid"), + # The "mid" of a market is not a level. + ("Account Director, Mid-Market", "director"), + ("Account Executive - Mid-Market", ""), + # ---- junior + ("Junior Data Analyst", "junior"), + ("Jr. Metrology Engineer", "junior"), + ("(Junior) Key Account Manager (m/w/d)", "junior"), + ("Junior Sales Manager (m/w/d) für intelligente Energiesysteme - 1KOMMA5° Göttingen", "junior"), + ("Entry Level: Baseband Developer", "junior"), + ("Entry-level Sales and Marketing Representative - Tampa, FL - Diablo Tools - DAT", "junior"), + ("Graduate Software Engineer", "junior"), + ("Software Engineer, New Grad - Frontend", "junior"), + ("Sales Trainee", "junior"), + ("Junior Managers Program (Trainee) - Start your Leadership Journey in Controlling", "junior"), + ("Asistente de marketing Jr. - Sector Automotriz - Lima", "junior"), + # ---- intern + ("Internship - Business Intelligence", "intern"), + ("Financial Planning & Analysis Intern", "intern"), + ("Software Engineer, Intern (Summer or Winter)", "intern"), + ("Working Student (f/m/d) - HR Learning & Development", "intern"), + ("Werkstudent:in Data Analytics (Controlling Focus) (m/w/d)", "intern"), + ("Werkstudent*in im Innovationsmanagement (m/w/d) (w/m/div.)", "intern"), + ("Praktikum in der Technologieentwicklung", "intern"), + ("Pflichtpraktikum Simultaneous Engineering", "intern"), + ("Betriebspraktikum für Schüler:innen 2026/2027 (m/w/d) Standort Dresden (STAR)", "intern"), + ("Praktikant:in (m/w/d) Technische Planung Photovoltaik - 1KOMMA5° Handwerk - Remote", "intern"), + ("Ausbildung Mechatroniker 2027 (m/w/d) für Kassel/Lohfelden", "intern"), + ("Lehrausbildung Mechatronik (w/m/div.) ab Herbst 2027", "intern"), + ("Master Thesis: Network Digital Twin Fidelity and Synthetic Data Generation for Radio Networks", "intern"), + ("Stagiaire Développeur de Logiciels", "intern"), + ("Stage - Data Scientist", "intern"), + ("Finance Operations - Stage", "intern"), + ("Event Coordinator Assistant – Stage (6 mois) Janvier 2027 (F/H/NB)", "intern"), + ("Alternant Technicien Maintenance (F/H)", "intern"), + ("Apprenti(e) chef(fe) de projet H/F/N", "intern"), + ("Studentermedhjælper søges til grøn drift", "intern"), + ("Juridisk studentermedarbejder til investeringsafdelingen", "intern"), + ("Bliv økonomielev hos Lomax", "intern"), + ("Værktøjsmager-/Industriteknikerlærling", "intern"), + ("Stage Inkoper", "intern"), + ("Jobstudent Klantenservice Franstalig", "intern"), + ("Duaal- of deeltijdstudent – Logistiek", "intern"), + ("Prácticas Ingeniería i4.0 y BA fábrica componentes automoción", "intern"), + ("Jovem Aprendiz ( Apprentice)", "intern"), + ("Junior Supply Chain Officer (Apprenticeship)", "intern"), + # An internship stays one whoever it reports to. + ("SAP iXp Intern (f/m/d) - Office of the Head of Product & Engineering of Consumer Industries", "intern"), + ("Praktikum Assistenz im Management des Senior Vice Presidents der Business Unit Building Solutions", "intern"), + # English "stage" and machine learning are not French. + ("Développeur·euse logiciel en exploitation de modèles d’apprentissage automatique", ""), + # ---- nothing said + ("Software Engineer - Data Infrastructure", ""), + ("Account Executive, Platforms (Hunter)", ""), + ("Cloud Engineer", ""), + ("Legal Counsel", ""), + ("Data Engineer (f/m/div.)", ""), + ("Kundenservice Mitarbeiter (w/m/d) - Hybrid", ""), + ("Elektroniker in der Leiterkartenfertigung (w/m/div.)", ""), + ("", ""), +] + +#: Titles the snapshot has no example of, written for the traps they test. +SYNTHETIC: list[tuple[str, str]] = [ + ("Lead Generation Specialist", ""), + ("Stage Manager, Touring Production", ""), + ("Product Owner - Early Stage", ""), + ("Projectleider Logistiek", ""), + ("Software Engineer III, Platform", "senior"), + ("Manager, Data Science", "manager"), +] + + +@pytest.mark.parametrize(("title", "level"), TITLES + SYNTHETIC) +def test_title(title: str, level: str) -> None: + assert from_title(title) == level + + +def test_table_covers_every_level_and_at_least_eighty_titles() -> None: + assert len(TITLES) >= 80 + assert {level for _, level in TITLES} == set(SENIORITIES) + + +def test_answers_are_seniorities() -> None: + assert {from_title(title) for title, _ in TITLES} <= set(SENIORITIES) + + +def test_gender_marker_and_case_do_not_matter() -> None: + assert from_title("SENIOR SOFTWARE ENGINEER (m/w/d)") == "senior" + assert from_title("senior software engineer (all genders)") == "senior" + + +def test_highest_level_named_wins() -> None: + assert from_title("Senior Director of Engineering") == "director" + assert from_title("Senior Lead Engineer") == "lead" + assert from_title("Junior Principal Engineer") == "staff" + assert from_title("Vice President and Managing Director") == "exec" + + +def test_words_are_matched_whole() -> None: + # "lead" in "Leadership", "intern" in "International", "vp" nowhere. + assert from_title("Leadership Development Programme Coordinator") == "" + assert from_title("International Sales Coordinator") == "" + assert from_title("Internal Audit Analyst") == "" + assert from_title("Directory Services Administrator") == ""