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

Commit

Permalink
CPA-261-re Average calculation on visualization api
Browse files Browse the repository at this point in the history
 - [x] Average bids average value fixed
 - [x] Round value fixed on average bids and monopolization
 - [x] Monopolization average value
 - [x] sum, count taken from table instead of goods & services table
 - [x] round off value in monopolization "value"
 - [x] Calculate average value from month wise average data in both monopolization and average bids
  • Loading branch information
sonikabaniya authored and KushalRaj committed Apr 22, 2021
1 parent b6247d7 commit 2ccdd5f
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions visualization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def get(self, request):
buyer = self.request.GET.get("buyer")

filter_args = {}
filter_args["no_of_bidders__gte"] = 1
if country:
filter_args["country__country_code_alpha_2"] = country
if buyer:
Expand All @@ -234,12 +235,10 @@ def get(self, request):

# Difference percentage calculation

# Overall average number of bids for contracts
overall_avg = Tender.objects.filter(**filter_args).aggregate(
sum=Sum("no_of_bidders"), count=Count("no_of_bidders")
)
result = {
"average": round(overall_avg["sum"] / overall_avg["count"], 1) if overall_avg["sum"] else 0,
"average": round(sum(item["value"] for item in final_line_chart_data) / len(final_line_chart_data), 1)
if len(final_line_chart_data) > 0
else 0,
"line_chart": final_line_chart_data,
}
return JsonResponse(result)
Expand Down Expand Up @@ -750,7 +749,7 @@ def get(self, request):
filter_args["country__country_code_alpha_2"] = country
if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)

filter_args["supplier_id__isnull"] = False
# Month wise average of number of bids for contracts
monthwise_data = (
Tender.objects.filter(**filter_args)
Expand All @@ -762,7 +761,7 @@ def get(self, request):
final_line_chart_data = [
{
"date": monthwise_data[i]["month"],
"value": round(monthwise_data[i]["count_contract"] / monthwise_data[i]["count_supplier"])
"value": round(monthwise_data[i]["count_contract"] / monthwise_data[i]["count_supplier"], 1)
if monthwise_data[i]["count_supplier"] and monthwise_data[i]["count_contract"]
else 0,
}
Expand All @@ -771,14 +770,9 @@ def get(self, request):

# Difference percentage calculation

# Overall average number of bids for contracts
overall = Tender.objects.filter(**filter_args).aggregate(
count_supplier=Count("supplier__supplier_id", distinct=True), count_contract=Count("id")
)

result = {
"average": round(overall["count_contract"] / overall["count_supplier"], 1)
if overall["count_contract"] and overall["count_supplier"]
"average": round(sum(item["value"] for item in final_line_chart_data) / len(final_line_chart_data), 1)
if len(final_line_chart_data) > 0
else 0,
"line_chart": final_line_chart_data,
}
Expand Down

0 comments on commit 2ccdd5f

Please sign in to comment.