Spaces:
Sleeping
Sleeping
| # %%writefile core/ranking.py | |
| import os | |
| import json | |
| from core.scoring import score_candidate | |
| JD_PATH = "data/jd.json" | |
| MATCH_DIR = "data/matches" | |
| OUT_PATH = "data/ranking.json" | |
| def build_ranking(top_k: int = 10): | |
| with open(JD_PATH, "r", encoding="utf-8") as f: | |
| jd_rubric = json.load(f) | |
| rows = [] | |
| for fname in os.listdir(MATCH_DIR): | |
| if not fname.endswith("_match.json"): | |
| continue | |
| fpath = os.path.join(MATCH_DIR, fname) | |
| with open(fpath, "r", encoding="utf-8") as f: | |
| match_summary = json.load(f) | |
| scored = score_candidate(jd_rubric, match_summary) | |
| scored["match_file"] = fname | |
| rows.append(scored) | |
| rows.sort(key=lambda x: x["total_score"], reverse=True) | |
| result = { | |
| "jd_role_title": jd_rubric.get("role_title", ""), | |
| "top_k": top_k, | |
| "ranking": rows[:top_k], | |
| "all_candidates": rows | |
| } | |
| with open(OUT_PATH, "w", encoding="utf-8") as f: | |
| json.dump(result, f, indent=2) | |
| return result | |