mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 08:36:25 +00:00
fix(salary): handle missing/null city & resolve custom baseline percentage bug (#98)
* fix: handle None value for city key in salary lookup * fix: calculate correct percentage difference for non-100 baselines in salary lookup
This commit is contained in:
+7
-4
@@ -160,7 +160,7 @@ def search_company(data, query, city=None):
|
|||||||
for entry in companies:
|
for entry in companies:
|
||||||
if city:
|
if city:
|
||||||
city_lower = city.lower()
|
city_lower = city.lower()
|
||||||
entry_city = entry.get("city", "").lower()
|
entry_city = (entry.get("city") or "").lower()
|
||||||
if city_lower not in entry_city and anglicize(city_lower) not in anglicize(entry_city):
|
if city_lower not in entry_city and anglicize(city_lower) not in anglicize(entry_city):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -206,10 +206,13 @@ def format_entry(entry, metadata):
|
|||||||
if count is not None or index is not None:
|
if count is not None or index is not None:
|
||||||
count_str = str(count) if count is not None else "-"
|
count_str = str(count) if count is not None else "-"
|
||||||
if isinstance(index, (int, float)):
|
if isinstance(index, (int, float)):
|
||||||
diff = index - baseline
|
|
||||||
sign = "+" if diff >= 0 else ""
|
|
||||||
index_str = f"{index:.1f}"
|
index_str = f"{index:.1f}"
|
||||||
diff_str = f"{sign}{diff:.1f}%"
|
if baseline == 0:
|
||||||
|
diff_str = ""
|
||||||
|
else:
|
||||||
|
diff_pct = ((index - baseline) / baseline) * 100
|
||||||
|
sign = "+" if diff_pct >= 0 else ""
|
||||||
|
diff_str = f"{sign}{diff_pct:.1f}%"
|
||||||
elif index is not None:
|
elif index is not None:
|
||||||
index_str = str(index)
|
index_str = str(index)
|
||||||
diff_str = ""
|
diff_str = ""
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from salary_lookup import format_entry
|
from salary_lookup import format_entry, search_company
|
||||||
|
|
||||||
|
|
||||||
class FormatEntryTests(unittest.TestCase):
|
class FormatEntryTests(unittest.TestCase):
|
||||||
@@ -36,6 +36,50 @@ class FormatEntryTests(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertIn("private", rendered)
|
self.assertIn("private", rendered)
|
||||||
|
|
||||||
|
def test_format_entry_with_zero_baseline(self):
|
||||||
|
entry = {
|
||||||
|
"company": "Example Corp",
|
||||||
|
"city": "",
|
||||||
|
"categories": {
|
||||||
|
"it": {
|
||||||
|
"count": None,
|
||||||
|
"index": 45000.0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
rendered = format_entry(entry, {"index_baseline": 0, "index_label": "Salary"})
|
||||||
|
self.assertIn("45000.0", rendered)
|
||||||
|
self.assertNotIn("%", rendered)
|
||||||
|
|
||||||
|
def test_format_entry_with_custom_baseline(self):
|
||||||
|
entry = {
|
||||||
|
"company": "Example Corp",
|
||||||
|
"city": "",
|
||||||
|
"categories": {
|
||||||
|
"it": {
|
||||||
|
"count": None,
|
||||||
|
"index": 45000.0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
rendered = format_entry(entry, {"index_baseline": 40000, "index_label": "Salary"})
|
||||||
|
self.assertIn("45000.0", rendered)
|
||||||
|
self.assertIn("+12.5%", rendered)
|
||||||
|
|
||||||
|
|
||||||
|
class SearchCompanyTests(unittest.TestCase):
|
||||||
|
def test_search_company_with_none_city(self):
|
||||||
|
data = {
|
||||||
|
"companies": [
|
||||||
|
{
|
||||||
|
"company": "Acme",
|
||||||
|
"city": None,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
results = search_company(data, "Acme", city="Aarhus")
|
||||||
|
self.assertEqual(results, [])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user