presentation.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """Terminal presentation of already-validated matching results."""
  2. from pathlib import Path
  3. from .contracts import EvaluatedJob, EvaluationState
  4. VERDICT_LABELS = {"match": "明确匹配", "mismatch": "明确不匹配", "unknown": "信息不足"}
  5. CATEGORY_LABELS = {"mandatory": "必备条件", "general": "一般要求", "bonus": "加分项"}
  6. GROUP_TITLES: dict[EvaluationState, str] = {
  7. "ranked": "推荐排名",
  8. "unable": "无法评估(未评分;不纳入排名)",
  9. "eliminated": "学历不符淘汰(未评分;不是企业招聘决定)",
  10. }
  11. def render(cv_path: Path, jobs_path: Path, results: list[EvaluatedJob]) -> None:
  12. """Group validated results, preserving CSV order for equal model scores."""
  13. groups: dict[EvaluationState, list[EvaluatedJob]] = {
  14. state: [] for state in GROUP_TITLES
  15. }
  16. for result in results:
  17. groups[result.state].append(result)
  18. groups["ranked"].sort(key=lambda item: -(item.match.score or 0))
  19. print("\n匹配结果 — Match Score(0–100 相对指标,不代表录用概率或招聘决定)")
  20. for state, title in GROUP_TITLES.items():
  21. print(f"\n{title}\n{'=' * 72}")
  22. if not groups[state]:
  23. print("(无)")
  24. previous = None
  25. rank = 0
  26. for position, result in enumerate(groups[state], 1):
  27. row, job, match = result.source, result.parsed, result.match
  28. if match.score != previous:
  29. rank = position
  30. previous = match.score
  31. prefix = f"{rank}. " if state == "ranked" else "- "
  32. score = f" {match.score:g} / 100" if match.score is not None else ""
  33. print(
  34. f"{prefix}{row.fields['岗位名称'] or '未提供岗位名称'} — {row.fields['公司名字'] or '未提供公司名字'} [{jobs_path.name} 第 {row.row} 行]{score}"
  35. )
  36. print(f" 判断依据:{match.reason}")
  37. for req, assessment in zip(job.requirements, match.assessments):
  38. print(
  39. f" {CATEGORY_LABELS[req.category]} · {VERDICT_LABELS[assessment.verdict]}:{assessment.reason}"
  40. )
  41. print(
  42. f" 职位证据:{jobs_path.name} 第 {row.row} 行 · 任职资格:{req.quote}"
  43. )
  44. for fact in assessment.cv_evidence:
  45. print(
  46. f" 简历证据:{cv_path.name} 第 {fact.start_line}–{fact.end_line} 行 · {fact.quote}"
  47. )
  48. if assessment.verdict == "unknown":
  49. print(
  50. " 缺失信息:"
  51. + req.quote
  52. + (
  53. "(加分项:不加分、不扣分)"
  54. if req.category == "bonus"
  55. else ""
  56. )
  57. )
  58. if job.status != "ok":
  59. print(f" 缺失信息:任职资格 {job.status},无法完整解析")