Parse mixed education records and certificates, flag unresolved DPO

This commit is contained in:
codex committed 2026-11-20 16:02:16 +00:00
1 parent 8dfd700bd5
commit 65d851bb92
18 files changed
+335 -14

No files matched your search

+11
View File
@@ -38,6 +38,7 @@ DIRECTORY_COLUMNS = (
("last_seen_at", "Последний раз найден", "last_seen_display"),
("dismissed_at", "Дата увольнения", "dismissed_display"),
("profile", "Профиль", "canonical_url"),
("dpo_count", "Количество ДПО", "dpo_count"),
)
_TRAINING_LABEL = "повышение квалификации"
@@ -57,16 +58,20 @@ def _has_training(data: dict[str, Any], since_year: int | None) -> bool:
dedicated = title in {_TRAINING_LABEL, "курсы повышения квалификации"}
if not dedicated and _TRAINING_LABEL not in (part.strip() for part in title.split("/")):
continue
structured_texts = set()
for value in _as_list(section.get("year_entries")):
entry = _as_dict(value)
year = entry.get("year")
text = str(entry.get("text") or "").strip()
structured_texts.add(text)
if since_year is not None and (type(year) is not int or year < since_year):
continue
if text and text != str(year) and (dedicated or _TRAINING_KIND.search(_QUOTED_TEXT.sub("", text))):
return True
# Profiles may also list completed courses in manually entered paragraphs or lists.
for text in _clean_list(section.get("paragraphs")) + _clean_list(section.get("items")):
if text in structured_texts:
continue
description = _QUOTED_TEXT.sub("", text).strip()
if not dedicated and not _TRAINING_MENTION.search(description):
continue
@@ -87,6 +92,8 @@ def employee_display_payload(employee: Employee) -> dict[str, Any]:
emails = _clean_list(contacts.get("emails"))
phones = _clean_list(contacts.get("phones"))
degree_values = academic_degrees(data)
education = [s for s in sections if isinstance(s, dict) and s.get("type") == "additional_education"]
parsed_education = bool(education) or data.get("education_parsed", False)
return {
"id": employee.id,
"full_name": employee.full_name,
@@ -103,6 +110,8 @@ def employee_display_payload(employee: Employee) -> dict[str, Any]:
"address": contacts.get("address"),
"academic_degree_text": "; ".join(degree_values),
"publications_count": _count_section_items(sections, "publications"),
"dpo_count": sum(len(s.get("items", [])) for s in education) if parsed_education else None,
"dpo_uncertain": any(s.get("unresolved") or s.get("unresolved_documents") for s in education),
"courses_count": _count_section_items(sections, "courses_by_year"),
"news_count": len(stored_news_links) or _count_section_items(sections, "news"),
"first_seen_at": employee.first_seen_at.isoformat() if employee.first_seen_at else None,
@@ -456,6 +465,8 @@ def _normalize_section(section: Any) -> dict[str, Any]:
"raw_text": raw_text,
"paragraphs": paragraphs,
"list_items": items,
"unresolved": _clean_list(section.get("unresolved")),
"unresolved_documents": _normalize_links(section.get("unresolved_documents")),
"links": _normalize_links(section.get("links")),
"year_entries": _normalize_year_entries(section.get("year_entries")),
"publications": _normalize_publications(section.get("publications")),