"""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_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, }