From 9c523a0a0cd2863103d9f937882b8d7af8652c7a Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 21 Oct 2021 15:37:01 +0200 Subject: [PATCH] #26 Annual conservation report * Adds download as excel sheet * adds excel_report.xlsx as template for excel sheet download * improves db access performance --- analysis/utils/excel/excel_report.xlsx | Bin 5958 -> 6433 bytes analysis/utils/report.py | 100 +++++++++++++++++-------- 2 files changed, 70 insertions(+), 30 deletions(-) diff --git a/analysis/utils/excel/excel_report.xlsx b/analysis/utils/excel/excel_report.xlsx index e69d3270e66c61256b692e217685311f9532a7bb..4383fbe8a80f4a056579b72136dc1c19759745bf 100644 GIT binary patch delta 4439 zcmZ8lcQhQ#*Ip~4v+C-WjS?-0UZX7$eRV3V6+3+ANwqIe&YPagD;g_VV#9N-lZu2;UGE{l|p$!r+@~NKVd-|D6W~!9xD7i1-OUpOh%8J*l z%Py&d@;5P|SY49j50~-FYv0>{t=Wny%QCvX&RoqUpWZYAt+LW44(wJTNXF7*VO-j< z4f9{@m#J1mZ3bUTO`f$!pno5P2T^S&^xe$#&I<4Xh8ES_Y-NeYq z5>kfMototCGuBn$`w&8#J+`gj=G4;S6rv=ZnM$@S{A&Z%+1I~@=ar#`>cSinw$cRS zI)$xd^3N2^BMQ@LwNq7`SC7MG`V+9BNn%9{%4uoxPIqYnCxd&3VsB zfC3LpJkPB3m({>;3bi<~+D@5LaGoKprAJf=!W_i(!Rs^D)(U_cklG7_or7cBWL8G2KFtW0lS4xaZStH&BknzwXu=?fG(@&_*qxC8RIAjp&ss{kVn<@n}(-Sb7xK0o9b4cf4UTNH2ib>ZdtTNa*a9{h`EcoM9VxmQrAHa{qbW@{UrLQ zm=0mV`l(TfO=g4n-JGdB5+_zwzFP0T6iBWe#*d$a=dpUd zqP_Af4Te1L@G$kr*B%>~W@|F1F)OASP6eNc5;_4lC3hmu71+UpfZ zt+3w>8AU}+hb}4{w*=rBm%B_Uw>x{nY@qxl54&ba_`o8_nvi}qt;_v4LVH&lj1n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VnIt>Hpd7}Dr2i%|CSf=iIvOfLwcy#95Ljfnb|P}_zoKP4l-DMYk-in>C~e{!om3X;)zj`i!>g_KXU)Qa{wVqR~yZ~E`8q# zkW@rmYa=H8AU`BHRD3$58URM&V=d)0`os+!XF6ma3TaMr5jufYTc%~o_kKd+Z;cEw zBzg_N*BB;Alnu2L|udqB@V$HlKx$kU z2bb+RVh;oPR9Qc0~ C0W(1W diff --git a/analysis/utils/report.py b/analysis/utils/report.py index fb5656fc..d3341a1a 100644 --- a/analysis/utils/report.py +++ b/analysis/utils/report.py @@ -57,6 +57,8 @@ class TimespanReport: deduction_sum_checked = -1 deduction_sum_recorded = -1 + excel_map = {} + def __init__(self, id: str, date_from: str, date_to: str): self.queryset = Intervention.objects.filter( responsible__conservation_office__id=id, @@ -76,6 +78,40 @@ class TimespanReport: self.queryset_recorded_count = self.queryset_recorded.count() self._create_report() + self._define_excel_map() + + def _define_excel_map(self): + """ Define the excel map, which holds values for each placeholder used in the template + + Returns: + + """ + self.excel_map = { + "i_checked": self.queryset_checked_count, + "i_recorded": self.queryset_recorded_count, + "i_total": self.queryset_count, + "i_compensations_checked": self.compensation_sum_checked, + "i_compensations_recorded": self.compensation_sum_recorded, + "i_compensations_total": self.compensation_sum, + "i_payments_recorded": self.payment_sum_recorded, + "i_payments_checked": self.payment_sum_checked, + "i_payments_total": self.payment_sum, + "i_deductions_recorded": self.deduction_sum_recorded, + "i_deductions_checked": self.deduction_sum_checked, + "i_deductions_total": self.deduction_sum, + "i_laws_iter": { + "iterable": self.evaluated_laws, + "attrs": [ + "short_name", + "num_checked", + "num_recorded", + "num", + ] + }, + "i_laws_checked": self.law_sum_checked, + "i_laws_recorded": self.law_sum_recorded, + "i_laws_total": self.law_sum, + } def _create_report(self): """ Creates all report information @@ -167,17 +203,17 @@ class TimespanReport: queryset_registration_office_tbp = Compensation.objects.none() queryset_registration_office_tbp_checked = Compensation.objects.none() queryset_registration_office_tbp_recorded = Compensation.objects.none() - queryset_registration_office_tbp = -1 - queryset_registration_office_tbp_checked = -1 - queryset_registration_office_tbp_recorded = -1 + queryset_registration_office_tbp_count = -1 + queryset_registration_office_tbp_checked_count = -1 + queryset_registration_office_tbp_recorded_count = -1 num_single_surfaces_total_tbp = -1 queryset_registration_office_other = Compensation.objects.none() queryset_registration_office_other_checked = Compensation.objects.none() queryset_registration_office_other_recorded = Compensation.objects.none() - queryset_registration_office_other = -1 - queryset_registration_office_other_checked = -1 - queryset_registration_office_other_recorded = -1 + queryset_registration_office_other_count = -1 + queryset_registration_office_other_checked_count = -1 + queryset_registration_office_other_recorded_count = -1 num_single_surfaces_total_other = -1 num_single_surfaces_total = -1 @@ -210,6 +246,32 @@ class TimespanReport: self.queryset_recorded_count = self.queryset_recorded.count() self._create_report() + self._define_excel_map() + + def _define_excel_map(self): + """ Define the excel map, which holds values for each placeholder used in the template + + Returns: + + """ + self.excel_map = { + "c_unb_checked": self.queryset_registration_office_unb_checked_count, + "c_unb_recorded": self.queryset_registration_office_unb_recorded_count, + "c_unb": self.queryset_registration_office_unb_count, + "c_surfaces_unb": self.num_single_surfaces_total_unb, + "c_tbp_checked": self.queryset_registration_office_tbp_checked_count, + "c_tbp_recorded": self.queryset_registration_office_tbp_recorded_count, + "c_tbp": self.queryset_registration_office_tbp_count, + "c_surfaces_tbp": self.num_single_surfaces_total_tbp, + "c_other_checked": self.queryset_registration_office_other_checked_count, + "c_other_recorded": self.queryset_registration_office_other_recorded_count, + "c_other": self.queryset_registration_office_other_count, + "c_surfaces_other": self.num_single_surfaces_total_other, + "c_checked": self.queryset_checked_count, + "c_recorded": self.queryset_recorded_count, + "c_total": self.queryset_count, + "c_surfaces": self.num_single_surfaces_total, + } def _create_report(self): """ Creates all report information @@ -432,28 +494,6 @@ class TimespanReport: self.excel_map = { "date_from": date_from.strftime(DEFAULT_DATE_FORMAT), "date_to": date_to.strftime(DEFAULT_DATE_FORMAT), - "i_checked": self.intervention_report.queryset_checked_count, - "i_recorded": self.intervention_report.queryset_recorded_count, - "i_total": self.intervention_report.queryset_count, - "i_compensations_checked": self.intervention_report.compensation_sum_checked, - "i_compensations_recorded": self.intervention_report.compensation_sum_recorded, - "i_compensations_total": self.intervention_report.compensation_sum, - "i_payments_recorded": self.intervention_report.payment_sum_recorded, - "i_payments_checked": self.intervention_report.payment_sum_checked, - "i_payments_total": self.intervention_report.payment_sum, - "i_deductions_recorded": self.intervention_report.deduction_sum_recorded, - "i_deductions_checked": self.intervention_report.deduction_sum_checked, - "i_deductions_total": self.intervention_report.deduction_sum, - "i_laws_iter": { - "iterable": self.intervention_report.evaluated_laws, - "attrs": [ - "short_name", - "num_checked", - "num_recorded", - "num", - ] - }, - "i_laws_checked": self.intervention_report.law_sum_checked, - "i_laws_recorded": self.intervention_report.law_sum_recorded, - "i_laws_total": self.intervention_report.law_sum, } + self.excel_map.update(self.intervention_report.excel_map) + self.excel_map.update(self.compensation_report.excel_map)