HR-ATS-Portal/backend/analytics/serializers.py

23 lines
714 B
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) -> dict:
return {"source": source or "Unknown","count": int(count or 0)}
def serialize_recruiter_row(user_id,name,hires,open_reqs,avg_time_to_hire) -> dict:
return {
"id": str(user_id) if user_id else None,
"name": name,
"hires": int(hires 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,
}