mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-11-02 13:12:50 +00:00
fix(salary): never take a qualified salary header as the company column (#700)
* fix(salary): never take a qualified salary header as the company column The detection loop kept the LAST header matching a company pattern, so "Company Name | City | Company Count | Company Index" made the index column the company column and every converted row carried "company": "108.5"; IDA's "Firmanavn og by | Antal | Firmaets indeks" (#615) did the same. #571's exact-match preference only helped when a header was exactly "Company" or "Firma". Detection is now three tiers, each taking the first match: an exact pattern header, then a pattern header that is not a count/index column, then any pattern header; the city column can never alias the company column. Four new cases; the two qualified-header ones fail on master. * changelog: place the #700 entry under [Unreleased] Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Mads Lorentzen <madslorentzen_17@hotmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+109
-13
No files matched your search
@@ -197,20 +197,28 @@ def parse_sheet(ws, sheet_label=None):
|
||||
for cell in ws[header_row]:
|
||||
headers.append(" ".join(str(cell.value).split()) if cell.value else "")
|
||||
|
||||
# Find company and city columns
|
||||
company_col = None
|
||||
city_col = None
|
||||
for i, h in enumerate(headers):
|
||||
if header_matches(h, COMPANY_PATTERNS):
|
||||
company_col = i
|
||||
elif header_matches(h, CITY_PATTERNS):
|
||||
city_col = i
|
||||
# Find company and city columns. Three tiers, each taking the FIRST match:
|
||||
# 1. an exact pattern header ("Company", "Firma", "By");
|
||||
# 2. a header that carries the pattern but is not a count/index column
|
||||
# ("Company Name", "Firmanavn og by");
|
||||
# 3. any header carrying the pattern.
|
||||
# The old loop kept the LAST pattern match, so "Company Name | ... |
|
||||
# Company Index" made the salary index the company column: every row's
|
||||
# company read "108.5". #571 added tier 1; tiers 2-3 cover a qualified
|
||||
# name header that sits next to a qualified salary header. The city
|
||||
# lookup skips the company column: a combined "Company and city" header
|
||||
# carries both words, and must not shadow a real city column after it.
|
||||
def metadata_column(patterns, skip=None):
|
||||
usable = [(i, h) for i, h in enumerate(headers) if i != skip]
|
||||
exact = next((i for i, h in usable if h.lower().strip() in patterns), None)
|
||||
if exact is not None:
|
||||
return exact
|
||||
candidates = [i for i, h in usable if header_matches(h, patterns)]
|
||||
plain = [i for i in candidates if detect_column_type(headers[i]) is None]
|
||||
return (plain or candidates or [None])[0]
|
||||
|
||||
# A qualified salary header such as "Company Index" may also contain a
|
||||
# metadata token. Prefer an unqualified metadata column when one exists,
|
||||
# leaving the qualified column available as salary data.
|
||||
company_col = next((i for i, h in enumerate(headers) if h.lower() in COMPANY_PATTERNS), company_col)
|
||||
city_col = next((i for i, h in enumerate(headers) if h.lower() in CITY_PATTERNS), city_col)
|
||||
company_col = metadata_column(COMPANY_PATTERNS)
|
||||
city_col = metadata_column(CITY_PATTERNS, skip=company_col)
|
||||
|
||||
if company_col is None:
|
||||
print(f"Warning: Could not find company column in sheet '{ws.title}'.", file=sys.stderr)
|
||||
|
||||
Reference in new issue
Block a user