From 9d4a1a21849cb6a3ac422ac358d0337c6903c564 Mon Sep 17 00:00:00 2001 From: yashlamba Date: Mon, 9 Dec 2024 11:33:13 +0100 Subject: [PATCH] curation: fix rules; fix curator evaluation --- site/zenodo_rdm/curation/config.py | 3 +++ site/zenodo_rdm/curation/curators.py | 2 +- site/zenodo_rdm/curation/rules.py | 12 +++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/site/zenodo_rdm/curation/config.py b/site/zenodo_rdm/curation/config.py index 1b265409..1c27d0ee 100644 --- a/site/zenodo_rdm/curation/config.py +++ b/site/zenodo_rdm/curation/config.py @@ -52,3 +52,6 @@ CURATION_HIGH_CONF_KEYWORDS_EU = [] """High confidence keywords for EU records.""" + +CURATION_TEST_PHRASES = [] +"""Test record phrases.""" diff --git a/site/zenodo_rdm/curation/curators.py b/site/zenodo_rdm/curation/curators.py index acddef99..d652b338 100644 --- a/site/zenodo_rdm/curation/curators.py +++ b/site/zenodo_rdm/curation/curators.py @@ -62,7 +62,7 @@ def _evaluator(self, results): rule_score = current_curation.scores.get(rule) if result is None: continue - elif isinstance(rule_score, int): + elif type(rule_score) is int: score += rule_score if result else 0 elif isinstance(rule_score, bool): if result: diff --git a/site/zenodo_rdm/curation/rules.py b/site/zenodo_rdm/curation/rules.py index bb7b5db1..0524154b 100644 --- a/site/zenodo_rdm/curation/rules.py +++ b/site/zenodo_rdm/curation/rules.py @@ -34,10 +34,10 @@ def award_acronym_in_title(record): """Check if EU award name in record title.""" award_service = current_service_registry.get("awards") title = record.metadata["title"] - funding = record.metadata["funding"] + funding = record.metadata.get("funding", []) for f in funding: - if f["funder"]["id"] == "00k4n6c32": + if f["funder"].get("id") == "00k4n6c32": if award_id := f.get("award", {}).get("id"): award = award_service.record_cls.pid.resolve(award_id) if award.get("acronym") and ( @@ -64,12 +64,14 @@ def published_before_award_start(record): """Check if published before award start date.""" award_service = current_service_registry.get("awards") - for f in record.metadata["funding"]: - if f["funder"]["id"] == "00k4n6c32": + funding = record.metadata.get("funding", []) + for f in funding: + if f["funder"].get("id") == "00k4n6c32": if award_id := f.get("award", {}).get("id"): award = award_service.record_cls.pid.resolve(award_id) if award.get("start_date") and ( - record.created < arrow.get(award.get("start_date")).datetime + record.created.timestamp() + < arrow.get(award.get("start_date")).datetime.timestamp() ): return True return False