mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-11-11 17:37:59 +00:00
* fix(salary): split combined name-and-city workbook columns
The IDA demonstration workbook heads its company column "Firmanavn og by"
and stores "Ørsted A/S, Fredericia" in that one cell. After the header is
detected, convert_salary_excel copied the whole cell into company with
city "". salary_lookup --city only reads entry["city"], so the documented
lookup for Ørsted in Fredericia missed.
When the company header also names a city and there is no city column,
split the cell on the last ", ". A Company-only header still keeps commas
in the name.
* fix(salary): split a combined name-and-city cell on the last comma
Real IDA cells have no space after the separating comma
("Ørsted A/S,Fredericia"), and some company names contain ", "
themselves ("Rambøll Danmark A/S, Odense,Odense C"). Splitting on the
last ", " missed almost every real row, so --city still dropped out.
split_combined_company_city now splits on the last "," and strips both
parts. Test fixtures use the real unspaced cell shape, and a new unit
test covers a company name that contains a comma. The docstrings,
CHANGELOG entry, tools/README_SALARY_TOOL.md and the README salary
section describe the new split.
* docs(changelog): move the combined-city entry under Unreleased
The merge of master brought in the 1.7.3 release section, which left
this PR's Fixed entry under an already released version. Move it to
the Unreleased Fixed list.
* chore: drop the CHANGELOG hunk, the file is frozen since #800
Release notes are generated from PR titles now.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Mads Lorentzen <madslorentzen17@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
81 lines
3.3 KiB
Python
81 lines
3.3 KiB
Python
"""A combined name-and-city workbook column must feed salary_lookup --city.
|
|
|
|
The IDA demonstration workbook heads its company column "Firmanavn og by"
|
|
and stores "Ørsted A/S,Fredericia" in that one cell (no space after the
|
|
comma). convert_salary_excel used to copy the whole cell into company with
|
|
city "". The documented
|
|
lookup `python3 salary_lookup.py "Ørsted" --city "Fredericia"` then missed,
|
|
even though the city was in the converted file - just not in the field
|
|
--city reads.
|
|
"""
|
|
import json
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
|
|
try:
|
|
import openpyxl
|
|
except ImportError:
|
|
openpyxl = None
|
|
|
|
REPO = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
@unittest.skipUnless(openpyxl, "requires optional openpyxl (installed in CI)")
|
|
class CombinedCityWorkbookCLI(unittest.TestCase):
|
|
def convert_and_lookup(self, headers, row, *lookup_args):
|
|
with TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
workbook = root / "salary.xlsx"
|
|
output = root / "salary_data.json"
|
|
book = openpyxl.Workbook()
|
|
try:
|
|
book.active.append(headers)
|
|
book.active.append(row)
|
|
book.save(workbook)
|
|
finally:
|
|
book.close()
|
|
conversion = subprocess.run(
|
|
[sys.executable, str(REPO / "tools/convert_salary_excel.py"),
|
|
str(workbook), "--output", str(output)],
|
|
capture_output=True, text=True, encoding="utf-8",
|
|
)
|
|
self.assertEqual(conversion.returncode, 0, conversion.stderr)
|
|
companies = json.loads(output.read_text(encoding="utf-8"))["companies"]
|
|
shutil.copyfile(REPO / "salary_lookup.py", root / "salary_lookup.py")
|
|
lookup = subprocess.run(
|
|
[sys.executable, str(root / "salary_lookup.py"), *lookup_args],
|
|
capture_output=True, text=True, encoding="utf-8",
|
|
)
|
|
return companies, lookup
|
|
|
|
def test_ida_firmanavn_og_by_row_is_findable_with_city_filter(self):
|
|
companies, lookup = self.convert_and_lookup(
|
|
["Firmanavn og by", "Antal", "Indeks"],
|
|
["Ørsted A/S,Fredericia", 200, 105.2],
|
|
"Ørsted", "--city", "Fredericia",
|
|
)
|
|
self.assertEqual(companies, [{
|
|
"company": "Ørsted A/S",
|
|
"city": "Fredericia",
|
|
"categories": {"all_employees": {"count": 200, "index": 105.2}},
|
|
}])
|
|
self.assertEqual(lookup.returncode, 0, lookup.stdout + lookup.stderr)
|
|
self.assertIn("Ørsted A/S", lookup.stdout)
|
|
self.assertIn("Fredericia", lookup.stdout)
|
|
self.assertNotIn("No results found", lookup.stdout)
|
|
|
|
def test_separate_city_column_is_unchanged(self):
|
|
companies, lookup = self.convert_and_lookup(
|
|
["Company", "City", "Count", "Index"],
|
|
["Novo Nordisk A/S", "Bagsværd", 500, 108.5],
|
|
"Novo Nordisk", "--city", "Bagsværd",
|
|
)
|
|
self.assertEqual(companies[0]["company"], "Novo Nordisk A/S")
|
|
self.assertEqual(companies[0]["city"], "Bagsværd")
|
|
self.assertEqual(lookup.returncode, 0, lookup.stdout + lookup.stderr)
|
|
self.assertIn("Novo Nordisk A/S", lookup.stdout)
|