51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
import uuid
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
def now_utc() -> datetime:
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
def as_uuid(record_id) -> uuid.UUID | None:
|
|
"""Parse a UUID from any id-ish value; None when blank or malformed."""
|
|
if record_id in (None, ""):
|
|
return None
|
|
try:
|
|
return uuid.UUID(str(record_id))
|
|
except ValueError:
|
|
return None
|
|
|
|
|
|
def location_options(search=None) -> list[str]:
|
|
"""`{City} - {Country}` for every city in global_cities.Countries, optionally filtered."""
|
|
from global_cities import Countries
|
|
|
|
term = (search or "").strip().lower()
|
|
seen = set()
|
|
options = []
|
|
for country, cities in Countries.items():
|
|
for city in cities:
|
|
label = f"{city} - {country}"
|
|
if label in seen or (term and term not in label.lower()):
|
|
continue
|
|
seen.add(label)
|
|
options.append(label)
|
|
return options
|
|
|
|
|
|
def department_job_metrics(job_rows, applicants_by_job) -> dict:
|
|
"""Roll job-level rows up to {department_id: {job_posts, open_roles, candidates}}.
|
|
|
|
`job_rows` are (department_id, job_post_id, requisition_status); `applicants_by_job`
|
|
maps str(job_post_id) -> unique applicants on that job. Open roles are job posts
|
|
whose requisition_status is "open", the same meaning analytics uses.
|
|
"""
|
|
metrics = {}
|
|
for department_id, job_post_id, requisition_status in job_rows or []:
|
|
m = metrics.setdefault(department_id, {"job_posts": 0, "open_roles": 0, "candidates": 0})
|
|
m["job_posts"] += 1
|
|
if requisition_status == "open":
|
|
m["open_roles"] += 1
|
|
m["candidates"] += int(applicants_by_job.get(str(job_post_id), 0))
|
|
return metrics
|