Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
304-total-contracts-refactoring
Browse files Browse the repository at this point in the history
 - [x] loc reduced in total_contracts_view.py
 - [x] query reduced in total_contracts_view.py
  • Loading branch information
sonikabaniya committed May 7, 2021
1 parent b403263 commit e75c86e
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions visualization/views/total_contracts_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ def get(self, request):
buyer = self.request.GET.get("buyer")
supplier = self.request.GET.get("supplier")

open_count = 0
selective_count = 0
direct_count = 0
limited_count = 0
not_identified_count = 0
total_country = 0
bar_chart_list = []
filter_args = {}
if country:
filter_args["country__country_code_alpha_2"] = country
Expand All @@ -34,23 +31,14 @@ def get(self, request):
if supplier:
filter_args = add_filter_args("supplier", supplier, filter_args)

total_country_tender = Tender.objects.filter(**filter_args).count()
bar_chart = (
Tender.objects.filter(**filter_args)
.values("procurement_procedure")
.annotate(count=Count("procurement_procedure"))
.annotate(count=Count("procurement_procedure"), total_country_count=Count("id"))
)
for i in bar_chart:
if i["procurement_procedure"] == "selective":
selective_count = i["count"]
elif i["procurement_procedure"] == "limited":
limited_count = i["count"]
elif i["procurement_procedure"] == "open":
open_count = i["count"]
elif i["procurement_procedure"] == "direct":
direct_count = i["count"]
elif i["procurement_procedure"] == "not_identified":
not_identified_count = i["count"]
total_country += i["total_country_count"]
bar_chart_list.append({"method": i["procurement_procedure"], "value": i["count"]})

line_chart = (
Tender.objects.filter(**filter_args)
Expand All @@ -61,14 +49,8 @@ def get(self, request):
)
line_chart_list = [{"date": i["month"], "value": i["total"]} for i in line_chart]
result = {
"total": total_country_tender,
"total": total_country,
"line_chart": line_chart_list,
"bar_chart": [
{"method": "open", "value": open_count},
{"method": "limited", "value": limited_count},
{"method": "selective", "value": selective_count},
{"method": "direct", "value": direct_count},
{"method": "not_identified", "value": not_identified_count},
],
"bar_chart": bar_chart_list,
}
return JsonResponse(result)

0 comments on commit e75c86e

Please sign in to comment.