diff --git a/app/services/council.py b/app/services/council.py index 25f881d..c01003f 100644 --- a/app/services/council.py +++ b/app/services/council.py @@ -163,27 +163,38 @@ def _unique_articles(articles: list[dict], start: date, end: date) -> list[dict] key = identifier or fallback if key not in unique: unique[key] = {**article, "doi": identifier, - **{field: list(article[field]) for field in ("types", "quartiles", "journals", "origins", "rows")}} + **{field: list(article[field]) for field in ("types", "quartiles", "journals", "origins", "rows")}, + "evidence": []} merged = unique[key] + merged["evidence"].append(article) for field in ("types", "quartiles", "journals", "origins", "rows"): merged[field] = list(dict.fromkeys([*merged[field], *article[field]])) merged["in_csv"] |= article["in_csv"] merged["in_db"] |= article["in_db"] merged["url"] = merged["url"] or article["url"] - merged["year"] = merged["year"] or article["year"] for article in unique.values(): - year = article["year"] + evidence = article.pop("evidence") + years = sorted({item["year"] for item in evidence if item["year"] is not None}) + # Never pick a conflicting source year merely because that row came first. + year = article["year"] = years[0] if len(years) == 1 else None article["criteria"] = list(article["quartiles"]) matches = list(dict.fromkeys(k1_journals[key] for name in article["journals"] if (key := _journal_key(name)) in k1_journals)) article["criteria"].extend(f"К1 · {name} (справочник ВАК)" for name in matches) - eligible = (year is not None and start.year <= year <= end.year - and (not article["types"] or article["types"] == ["Статья"])) - article["q1"] = eligible and any(q.endswith(" Q1") for q in article["quartiles"]) - article["q2"] = eligible and any(q.endswith(" Q2") for q in article["quartiles"]) - article["k1"] = eligible and bool(matches) + eligible_type = not article["types"] or article["types"] == ["Статья"] + article["q1"] = article["q2"] = article["k1"] = False + for item in evidence: + source_year = item["year"] if item["year"] is not None else year + if not eligible_type or source_year is None or not start.year <= source_year <= end.year: + continue + article["q1"] |= any(q.endswith(" Q1") for q in item["quartiles"]) + article["q2"] |= any(q.endswith(" Q2") for q in item["quartiles"]) + article["k1"] |= any(_journal_key(name) in k1_journals for name in item["journals"]) article["qualifies"] = article["q1"] or article["q2"] or article["k1"] - if year is None: + if len(years) > 1: + article["criteria"].append("Годы источников расходятся: " + ", ".join(map(str, years)) + + "; критерии учитываются по году каждой исходной записи") + elif year is None: article["criteria"].append("Год не указан — период не подтверждён") elif start.year <= year <= end.year: article["criteria"].append("В пределах пяти лет по году; точную дату нужно проверить" if year in {start.year, end.year} diff --git a/app/version.py b/app/version.py index 0396a7f..b7d2ab0 100644 --- a/app/version.py +++ b/app/version.py @@ -1,3 +1,3 @@ -APP_VERSION = "0.14.0" -FRONTEND_VERSION = "0.14.0" -BACKEND_VERSION = "0.14.0" +APP_VERSION = "0.14.1" +FRONTEND_VERSION = "0.14.1" +BACKEND_VERSION = "0.14.1" diff --git a/pyproject.toml b/pyproject.toml index 08e7ebf..8ea2800 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "miem-workers" -version = "0.14.0" +version = "0.14.1" description = "MIEM employees parser, admin API, and web admin" requires-python = ">=3.11" dependencies = [ diff --git a/tests/test_api.py b/tests/test_api.py index cba89f9..1bba340 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -18,7 +18,7 @@ def test_health_returns_versions(): response = TestClient(app).get("/api/health") assert response.status_code == 200 - assert response.json()["backend_version"] == "0.14.0" + assert response.json()["backend_version"] == "0.14.1" def test_api_employees_and_stats_require_admin_session(): diff --git a/tests/test_council.py b/tests/test_council.py index 71756d3..db3dd99 100644 --- a/tests/test_council.py +++ b/tests/test_council.py @@ -211,7 +211,7 @@ def test_public_page_data_minimization_and_safe_links(db_session, export): assert "<script>" in response.text and "