From 0da70cc241f87ca8d8b6bd8d90dcce376ec8fc81 Mon Sep 17 00:00:00 2001 From: ntrncic Date: Sun, 5 Mar 2017 19:00:13 -0500 Subject: [PATCH 1/2] partner dash counts fix --- EquiTrack/partners/views/v2.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/EquiTrack/partners/views/v2.py b/EquiTrack/partners/views/v2.py index 9e1fb74f2f..a916b1653f 100644 --- a/EquiTrack/partners/views/v2.py +++ b/EquiTrack/partners/views/v2.py @@ -295,7 +295,7 @@ def total_value_for_parternships(partnerships): result['active_value'] = total_value_for_parternships(active_partnerships) result['active_percentage'] = "{0:.0f}%".format( operator.truediv(result['active_count'], result['total_count']) * 100) \ - if result['active_count'] else "0%" + if result['total_count'] else "0%" # (2a) Number and value of Approved Interventions this year result['total_this_year_count'] = len(total_this_year) @@ -303,15 +303,15 @@ def total_value_for_parternships(partnerships): result['active_this_year_value'] = total_value_for_parternships(active_this_year) result['active_this_year_percentage'] = "{0:.0f}%".format( operator.truediv(result['active_this_year_count'], result['total_this_year_count']) * 100) \ - if result['active_count'] else "0%" + if result['total_this_year_count'] else "0%" # (2b) Number and value of Approved Interventions last year result['total_last_year_count'] = len(total_last_year) result['active_last_year_count'] = len(active_last_year) result['active_last_year_value'] = total_value_for_parternships(active_last_year) result['active_last_year_percentage'] = "{0:.0f}%".format( - operator.truediv(result['active_last_year_count'], result['active_last_year_count']) * 100) \ - if result['active_last_year_count'] else "0%" + operator.truediv(result['active_last_year_count'], result['total_last_year_count']) * 100) \ + if result['total_last_year_count'] else "0%" # (3) Number and Value of Expiring Interventions in next two months result['total_expire_in_two_months_count'] = len(total_expire_in_two_months) @@ -319,6 +319,6 @@ def total_value_for_parternships(partnerships): result['expire_in_two_months_value'] = total_value_for_parternships(expire_in_two_months) result['expire_in_two_months_percentage'] = "{0:.0f}%".format( operator.truediv(result['expire_in_two_months_count'], result['active_count']) * 100) \ - if result['expire_in_two_months_count'] else "0%" + if result['active_count'] else "0%" return Response(result, status=status.HTTP_200_OK) From c1ad0ffc31a3f8418f22a9bc958fb2b23ed7149c Mon Sep 17 00:00:00 2001 From: ntrncic Date: Sun, 5 Mar 2017 19:02:34 -0500 Subject: [PATCH 2/2] div by zero fix --- EquiTrack/partners/views/v2.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/EquiTrack/partners/views/v2.py b/EquiTrack/partners/views/v2.py index a916b1653f..573361ec42 100644 --- a/EquiTrack/partners/views/v2.py +++ b/EquiTrack/partners/views/v2.py @@ -295,7 +295,7 @@ def total_value_for_parternships(partnerships): result['active_value'] = total_value_for_parternships(active_partnerships) result['active_percentage'] = "{0:.0f}%".format( operator.truediv(result['active_count'], result['total_count']) * 100) \ - if result['total_count'] else "0%" + if result['total_count'] and result['active_count'] else "0%" # (2a) Number and value of Approved Interventions this year result['total_this_year_count'] = len(total_this_year) @@ -303,7 +303,7 @@ def total_value_for_parternships(partnerships): result['active_this_year_value'] = total_value_for_parternships(active_this_year) result['active_this_year_percentage'] = "{0:.0f}%".format( operator.truediv(result['active_this_year_count'], result['total_this_year_count']) * 100) \ - if result['total_this_year_count'] else "0%" + if result['total_this_year_count'] and result['active_this_year_count'] else "0%" # (2b) Number and value of Approved Interventions last year result['total_last_year_count'] = len(total_last_year) @@ -311,7 +311,7 @@ def total_value_for_parternships(partnerships): result['active_last_year_value'] = total_value_for_parternships(active_last_year) result['active_last_year_percentage'] = "{0:.0f}%".format( operator.truediv(result['active_last_year_count'], result['total_last_year_count']) * 100) \ - if result['total_last_year_count'] else "0%" + if result['total_last_year_count'] and result['active_last_year_count'] else "0%" # (3) Number and Value of Expiring Interventions in next two months result['total_expire_in_two_months_count'] = len(total_expire_in_two_months) @@ -319,6 +319,6 @@ def total_value_for_parternships(partnerships): result['expire_in_two_months_value'] = total_value_for_parternships(expire_in_two_months) result['expire_in_two_months_percentage'] = "{0:.0f}%".format( operator.truediv(result['expire_in_two_months_count'], result['active_count']) * 100) \ - if result['active_count'] else "0%" + if result['active_count'] and result['expire_in_two_months_count'] else "0%" return Response(result, status=status.HTTP_200_OK)