From 676b8e1e5496b85798a1b58343c3e8737e7804c3 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Fri, 17 Feb 2023 08:03:10 +0100 Subject: [PATCH 1/2] Specific quality check for recorded entries * adds a new command specifically for recorded entries --- konova/management/commands/quality_check.py | 1 - .../commands/quality_check_recorded.py | 58 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 konova/management/commands/quality_check_recorded.py diff --git a/konova/management/commands/quality_check.py b/konova/management/commands/quality_check.py index a58bda11..579da4b9 100644 --- a/konova/management/commands/quality_check.py +++ b/konova/management/commands/quality_check.py @@ -52,7 +52,6 @@ class Command(BaseKonovaCommand): self.__ema = Ema.objects.filter(**_filter) def perform_quality_check(self): - # Interventions _runs = [ (self.__interventions, InterventionQualityChecker), (self.__compensations, CompensationQualityChecker), diff --git a/konova/management/commands/quality_check_recorded.py b/konova/management/commands/quality_check_recorded.py new file mode 100644 index 00000000..242ce07f --- /dev/null +++ b/konova/management/commands/quality_check_recorded.py @@ -0,0 +1,58 @@ +""" +Author: Michel Peltriaux +Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany +Contact: ksp-servicestelle@sgdnord.rlp.de +Created on: 16.02.23 + +""" +from compensation.models import Compensation, EcoAccount +from compensation.utils.quality import CompensationQualityChecker, EcoAccountQualityChecker +from ema.models import Ema +from ema.utils.quality import EmaQualityChecker +from intervention.models import Intervention +from intervention.utils.quality import InterventionQualityChecker +from konova.management.commands.setup import BaseKonovaCommand + + +class Command(BaseKonovaCommand): + help = "Runs quality check on recorded entries" + + __interventions = [] + __compensations = [] + __ecoaccount = [] + __ema = [] + + def handle(self, *args, **options): + self.__get_objects() + self.perform_quality_check() + + def __get_objects(self): + _filter = { + "recorded_id__isnull": False, + } + self.__interventions = Intervention.objects.filter(**_filter) + self.__compensations = Compensation.objects.filter( + intervention__recorded_id__isnull=False + ) + self.__ecoaccount = EcoAccount.objects.filter(**_filter) + self.__ema = Ema.objects.filter(**_filter) + + def perform_quality_check(self): + _runs = [ + (self.__interventions, InterventionQualityChecker), + (self.__compensations, CompensationQualityChecker), + (self.__ecoaccount, EcoAccountQualityChecker), + (self.__ema, EmaQualityChecker), + ] + eivs = set() + for run in _runs: + entries = run[0] + CheckerClass = run[1] + for entry in entries: + checker = CheckerClass(entry) + checker.run_check() + if not checker.valid and CheckerClass is CompensationQualityChecker: + eivs.add(entry.intervention.identifier) + #self._write_error(f"{entry.identifier};{';'.join(str(msg) for msg in checker.messages)}") + for eiv in eivs: + self._write_warning(eiv) From 1438cf4e899d58e6afc04e7889ef660b80f34ca4 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Tue, 21 Feb 2023 08:03:56 +0100 Subject: [PATCH 2/2] Deployment preparation * adds unrecording to invalid entries * reduces quality check runs on entries of interest (compensations) --- .../commands/quality_check_recorded.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/konova/management/commands/quality_check_recorded.py b/konova/management/commands/quality_check_recorded.py index 242ce07f..e141381c 100644 --- a/konova/management/commands/quality_check_recorded.py +++ b/konova/management/commands/quality_check_recorded.py @@ -12,6 +12,7 @@ from ema.utils.quality import EmaQualityChecker from intervention.models import Intervention from intervention.utils.quality import InterventionQualityChecker from konova.management.commands.setup import BaseKonovaCommand +from user.models import User class Command(BaseKonovaCommand): @@ -38,13 +39,20 @@ class Command(BaseKonovaCommand): self.__ema = Ema.objects.filter(**_filter) def perform_quality_check(self): + """ Performs quality check and unrecords failing entries + + """ + _runs = [ - (self.__interventions, InterventionQualityChecker), + #(self.__interventions, InterventionQualityChecker), (self.__compensations, CompensationQualityChecker), - (self.__ecoaccount, EcoAccountQualityChecker), - (self.__ema, EmaQualityChecker), + #(self.__ecoaccount, EcoAccountQualityChecker), + #(self.__ema, EmaQualityChecker), ] - eivs = set() + invalid_entries = set() + admin_user = User.objects.get( + username="kspRoot" + ) for run in _runs: entries = run[0] CheckerClass = run[1] @@ -52,7 +60,7 @@ class Command(BaseKonovaCommand): checker = CheckerClass(entry) checker.run_check() if not checker.valid and CheckerClass is CompensationQualityChecker: - eivs.add(entry.intervention.identifier) - #self._write_error(f"{entry.identifier};{';'.join(str(msg) for msg in checker.messages)}") - for eiv in eivs: - self._write_warning(eiv) + invalid_entries.add(entry.intervention) + for e in invalid_entries: + e.set_unrecorded(user=admin_user) + self._write_warning(e.identifier)