forked from admin/miem_workers
fix: validate publication evidence identity and original journal ISSNs
This commit is contained in:
1 parent
7a51521abf
commit
194ed30dd4
13 files changed
+224
-39
No files matched your search
@@ -20,7 +20,7 @@ from openpyxl import load_workbook
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
from app.services.council_source import _doi, _name, _journal_names, _description_journals
|
||||
from app.services.council_catalog import issn
|
||||
from app.services.publication_quartiles import catalog_entries, entries, hse_entries, merge, sjr_entries, index_sjr, with_title_history
|
||||
from app.services.publication_quartiles import catalog_entries, entries, hse_entries, merge, sjr_entries, index_sjr, with_title_history, identity_issues
|
||||
from app.services.publication_vak import assess_vak
|
||||
|
||||
SOURCE_TITLES_URL = "https://downloads.ctfassets.net/o78em1y1w4i4/7xtaTxNiNcWRTeZkV86eNy/69cf2d506c905dc299531fdc93049dbb/ext_list_Aug_2026.xlsx"
|
||||
@@ -221,18 +221,26 @@ def main():
|
||||
table = Table("employee_publications", MetaData(), autoload_with=engine)
|
||||
if "quartiles" not in table.c:
|
||||
raise ValueError("Apply migration 010 before enrichment")
|
||||
fields = ["id", "year", "doi_url", "raw_data", "quartiles"]
|
||||
fields = ["id", "year", "doi_url", "raw_data", "quartiles", "description"]
|
||||
if args.check_vak:
|
||||
if "vak_categories" not in table.c:
|
||||
raise ValueError("Apply migration 011 before VAK enrichment")
|
||||
fields.extend(["description", "publication_type", "vak_categories"])
|
||||
fields.extend(["publication_type", "vak_categories"])
|
||||
columns = [table.c[field] for field in fields]
|
||||
with engine.connect() as connection:
|
||||
rows = [dict(row) for row in connection.execute(select(*columns)).mappings()]
|
||||
def needs_lookup(row):
|
||||
return args.all_systems or not entries(row["quartiles"]) or row["quartiles"].get("lookup", {}).get("status") == "found_latest"
|
||||
raw = row["raw_data"] if isinstance(row["raw_data"], dict) else {}
|
||||
names = _journal_names(raw)
|
||||
description = row["description"] if isinstance(row["description"], dict) else raw.get("description", {})
|
||||
if isinstance(description, dict):
|
||||
names.extend(_description_journals(description))
|
||||
ids = [raw[key] for key in ("issn", "eissn", "ISSN", "EISSN") if isinstance(raw.get(key), str)]
|
||||
payload = merge(row["quartiles"], hse_entries(row["raw_data"], row["year"]))
|
||||
return (args.all_systems or not entries(payload) or (payload.get("lookup") or {}).get("status") == "found_latest"
|
||||
or bool(identity_issues(payload, row["doi_url"], names, ids)))
|
||||
identifiers = sorted({_doi(row["doi_url"] or "") for row in rows
|
||||
if needs_lookup(row) and (args.all_systems or not hse_entries(row["raw_data"], row["year"]))} - {""})
|
||||
if needs_lookup(row)} - {""})
|
||||
resolved = {}
|
||||
if args.lookup_doi:
|
||||
with ThreadPoolExecutor(max_workers=args.workers) as pool:
|
||||
@@ -257,12 +265,13 @@ def main():
|
||||
report = []
|
||||
for row in rows:
|
||||
doi = _doi(row["doi_url"] or "")
|
||||
metadata = resolved.get(doi, row["quartiles"].get("lookup", {}) if row["quartiles"] else {})
|
||||
previous_lookup = (row["quartiles"].get("lookup") or {}) if row["quartiles"] else {}
|
||||
metadata = resolved.get(doi, previous_lookup if doi and _doi(previous_lookup.get("doi") or "") == doi else {})
|
||||
additions = hse_entries(row["raw_data"], row["year"])
|
||||
payload = merge(row["quartiles"], additions)
|
||||
if additions:
|
||||
counts["hse_quartiles"] += 1
|
||||
if args.lookup_doi and (args.all_systems or not entries(payload) or payload.get("lookup", {}).get("status") == "found_latest"):
|
||||
if args.lookup_doi and needs_lookup(row):
|
||||
doi = _doi(row["doi_url"] or "")
|
||||
metadata = resolved.get(doi, {"status": "invalid_doi" if row["doi_url"] else "missing_doi"})
|
||||
status = metadata["status"]
|
||||
@@ -290,7 +299,11 @@ def main():
|
||||
description = row["description"] if isinstance(row["description"], dict) else raw.get("description", {})
|
||||
if isinstance(description, dict):
|
||||
names.extend(_description_journals(description))
|
||||
vak_payload = assess_vak(list(dict.fromkeys(names)), metadata.get("issns", []))
|
||||
identifiers = list(metadata.get("issns", []))
|
||||
for source in (raw, imported):
|
||||
if isinstance(source, dict):
|
||||
identifiers.extend(source[key] for key in ("issn", "eissn", "ISSN", "EISSN") if isinstance(source.get(key), str))
|
||||
vak_payload = assess_vak(list(dict.fromkeys(names)), list(dict.fromkeys(identifiers)))
|
||||
if row.get("vak_categories") is not None and row["vak_categories"] != vak_payload:
|
||||
counts["vak_existing_value_kept"] += 1
|
||||
vak_payload = row["vak_categories"]
|
||||
|
||||
Reference in new issue
Block a user