Merge pull request '# 175 Report law calculation bugfix' (#176) from 175_Report_law_calculation_wrong into master
Reviewed-on: SGD-Nord/konova#176
This commit is contained in:
commit
6e5237ab88
@ -137,22 +137,36 @@ class TimespanReport:
|
||||
).order_by(
|
||||
"long_name"
|
||||
)
|
||||
# Fetch all law ids which are used by any .legal object of an intervention object
|
||||
intervention_laws_total = self.queryset.values_list("legal__laws__id")
|
||||
intervention_laws_checked = self.queryset.filter(checked__isnull=False).values_list("legal__laws__id")
|
||||
intervention_laws_recorded = self.queryset.filter(recorded__isnull=False).values_list(
|
||||
"legal__laws__id")
|
||||
# Count how often which law id appears in the above list, return only the long_name of the law and the resulting
|
||||
# count (here 'num'). This is for keeping the db fetch as small as possible
|
||||
# Compute the sum for total, checked and recorded
|
||||
self.evaluated_laws = laws.annotate(
|
||||
num=Count("id", filter=Q(id__in=intervention_laws_total)),
|
||||
num_checked=Count("id", filter=Q(id__in=intervention_laws_checked)),
|
||||
num_recorded=Count("id", filter=Q(id__in=intervention_laws_recorded)),
|
||||
).values_list("short_name", "long_name", "num_checked", "num_recorded", "num", named=True)
|
||||
self.law_sum = self.evaluated_laws.aggregate(sum_num=Sum("num"))["sum_num"]
|
||||
self.law_sum_checked = self.evaluated_laws.aggregate(sum_num_checked=Sum("num_checked"))["sum_num_checked"]
|
||||
self.law_sum_recorded = self.evaluated_laws.aggregate(sum_num_recorded=Sum("num_recorded"))["sum_num_recorded"]
|
||||
|
||||
evaluated_laws = []
|
||||
sum_num_checked = 0
|
||||
sum_num_recorded = 0
|
||||
sum_num = 0
|
||||
for law in laws:
|
||||
num = self.queryset.filter(
|
||||
legal__laws__atom_id=law.atom_id
|
||||
).count()
|
||||
num_checked = self.queryset_checked.filter(
|
||||
legal__laws__atom_id=law.atom_id
|
||||
).count()
|
||||
num_recorded = self.queryset_recorded.filter(
|
||||
legal__laws__atom_id=law.atom_id
|
||||
).count()
|
||||
evaluated_laws.append({
|
||||
"short_name": law.short_name,
|
||||
"long_name": law.long_name,
|
||||
"num": num,
|
||||
"num_checked": num_checked,
|
||||
"num_recorded": num_recorded,
|
||||
})
|
||||
sum_num += num
|
||||
sum_num_checked += num_checked
|
||||
sum_num_recorded += num_recorded
|
||||
|
||||
self.evaluated_laws = evaluated_laws
|
||||
self.law_sum = sum_num
|
||||
self.law_sum_checked = sum_num_checked
|
||||
self.law_sum_recorded = sum_num_recorded
|
||||
|
||||
def _evaluate_compensations(self):
|
||||
""" Analyzes the types of compensation distribution
|
||||
|
Loading…
Reference in New Issue
Block a user