#36 Quality checks
* adds AbstractQualityChecker as base for all quality checker instances * adds InterventionQualityChecker, inheriting from AbstractQualityChecker * adds functionality to InterventionQualityChecker * adds/updates translations
This commit is contained in:
112
intervention/utils/quality.py
Normal file
112
intervention/utils/quality.py
Normal file
@@ -0,0 +1,112 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 25.10.21
|
||||
|
||||
"""
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from konova.utils.quality import AbstractQualityChecker
|
||||
|
||||
|
||||
class InterventionQualityChecker(AbstractQualityChecker):
|
||||
def run_check(self):
|
||||
""" Perform all defined data checks
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
|
||||
self._check_responsible_data()
|
||||
self._check_legal_data()
|
||||
self._check_compensations()
|
||||
self._check_geometry()
|
||||
self.valid = len(self.messages) == 0
|
||||
|
||||
def _check_responsible_data(self):
|
||||
""" Checks data quality of related ResponsibilityData
|
||||
|
||||
Args:
|
||||
self.messages (dict): Holds error messages
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
try:
|
||||
resp = self.obj.responsible
|
||||
# Check for file numbers
|
||||
if not resp.registration_file_number or len(resp.registration_file_number) == 0:
|
||||
self._add_missing_attr_name(_("Registration office file number"))
|
||||
|
||||
if not resp.conservation_file_number or len(resp.conservation_file_number) == 0:
|
||||
self._add_missing_attr_name(_("Conservation office file number"))
|
||||
|
||||
# Check for selected offices
|
||||
if resp.registration_office is None:
|
||||
self._add_missing_attr_name(_("Registration office"))
|
||||
|
||||
if resp.conservation_office is None:
|
||||
self._add_missing_attr_name(_("Conservation office"))
|
||||
|
||||
if resp.handler is None:
|
||||
self._add_missing_attr_name(_("Intervention handler"))
|
||||
except AttributeError:
|
||||
# responsible data not found
|
||||
self._add_missing_attr_name(_("Responsible data"))
|
||||
|
||||
def _check_legal_data(self):
|
||||
""" Checks data quality of related LegalData
|
||||
|
||||
Args:
|
||||
self.messages (dict): Holds error messages
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
try:
|
||||
legal = self.obj.legal
|
||||
# Check for a revocation
|
||||
if legal.revocation:
|
||||
self.messages.append(_("Revocation exists"))
|
||||
|
||||
if legal.registration_date is None:
|
||||
self._add_missing_attr_name(_("Registration date"))
|
||||
|
||||
if legal.binding_date is None:
|
||||
self._add_missing_attr_name(_("Binding date"))
|
||||
|
||||
if legal.laws.count() == 0:
|
||||
self._add_missing_attr_name(_("Laws"))
|
||||
|
||||
if legal.process_type is None:
|
||||
self._add_missing_attr_name(_("Process type"))
|
||||
except AttributeError:
|
||||
self._add_missing_attr_name(_("Legal data"))
|
||||
|
||||
def _check_compensations(self):
|
||||
""" Checks for compensation, deduction or payment
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
c_comps = self.obj.compensations.count()
|
||||
c_pays = self.obj.payments.count()
|
||||
c_deducs = self.obj.deductions.count()
|
||||
c_all = c_comps + c_pays + c_deducs
|
||||
if c_all == 0:
|
||||
self.messages.append(
|
||||
_("No compensation of any type found (Compensation, Payment, Deduction)")
|
||||
)
|
||||
|
||||
def _check_geometry(self):
|
||||
""" Checks on the geometry
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
try:
|
||||
geometry_obj = self.obj.geometry
|
||||
if geometry_obj.geom.empty:
|
||||
self._add_missing_attr_name(_("Geometry"))
|
||||
except AttributeError:
|
||||
self._add_missing_attr_name(_("Geometry"))
|
||||
Reference in New Issue
Block a user