44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
"""Analytics responses are mostly assembled as dicts in views.
|
|
|
|
Keep helpers here only when reuse across methods would otherwise duplicate.
|
|
"""
|
|
|
|
|
|
def serialize_stage_count(stage,count) -> dict:
|
|
return {"stage": stage,"count": int(count or 0)}
|
|
|
|
|
|
def serialize_source_count(source,count,source_id=None,spend=0.0) -> dict:
|
|
count=int(count or 0)
|
|
spend=float(spend or 0.0)
|
|
return {
|
|
"id": source_id,
|
|
"source": source or "Unknown",
|
|
"count": count,
|
|
"spend": spend,
|
|
"cost_per_application": round(spend/count,2) if spend and count else None,
|
|
}
|
|
|
|
|
|
def serialize_job_application_count(job,count) -> dict:
|
|
return {
|
|
"job_post_id": str(job.id),
|
|
"title": job.title or "",
|
|
"department": job.department or "",
|
|
"requisition_status": job.requisition_status,
|
|
"vacancies": int(job.vacancies or 0),
|
|
"is_active": bool(job.is_active),
|
|
"count": int(count or 0),
|
|
}
|
|
|
|
|
|
def serialize_recruiter_row(user_id,name,hires,open_reqs,avg_time_to_hire,completed=0) -> dict:
|
|
return {
|
|
"id": str(user_id) if user_id else None,
|
|
"name": name,
|
|
"hires": int(hires or 0),
|
|
"completed": int(completed or 0),
|
|
"open_reqs": int(open_reqs or 0),
|
|
"avg_time_to_hire": float(avg_time_to_hire) if avg_time_to_hire is not None else None,
|
|
}
|