@@ -34,6 +34,12 @@ def calculate(self, conference_id):
3434 status_totals ,
3535 totals_per_continent ,
3636 ) = self ._aggregate_data_by_country (grants_by_country , statuses )
37+ sorted_country_stats = dict (
38+ sorted (country_stats .items (), key = lambda x : (x [0 ][0 ], x [0 ][2 ]))
39+ )
40+ country_type_summary = self ._aggregate_data_by_country_type (
41+ filtered_grants , statuses
42+ )
3743 gender_stats = self ._aggregate_data_by_gender (filtered_grants , statuses )
3844 financial_summary , total_amount = self ._aggregate_financial_data_by_status (
3945 filtered_grants , statuses
@@ -50,13 +56,13 @@ def calculate(self, conference_id):
5056 requested_needs_summary = self ._aggregate_data_by_requested_needs_summary (
5157 filtered_grants , statuses
5258 )
53- sorted_country_stats = dict (
54- sorted (country_stats .items (), key = lambda x : (x [0 ][0 ], x [0 ][2 ]))
55- )
5659 approved_types = {
5760 approved_type .value : approved_type .label
5861 for approved_type in Grant .ApprovedType
5962 }
63+ country_types = {
64+ country_type .value : country_type .label for country_type in Grant .CountryType
65+ }
6066
6167 return dict (
6268 conference_id = conference_id ,
@@ -76,6 +82,8 @@ def calculate(self, conference_id):
7682 approved_type_summary = approved_type_summary ,
7783 approved_types = approved_types ,
7884 requested_needs_summary = requested_needs_summary ,
85+ country_type_summary = country_type_summary ,
86+ country_types = country_types ,
7987 )
8088
8189 def _aggregate_data_by_country (self , grants_by_country , statuses ):
@@ -107,6 +115,26 @@ def _aggregate_data_by_country(self, grants_by_country, statuses):
107115
108116 return summary , status_totals , totals_per_continent
109117
118+ def _aggregate_data_by_country_type (self , filtered_grants , statuses ):
119+ """
120+ Aggregates grant data by country type and status.
121+ """
122+ country_type_data = filtered_grants .values ("country_type" , "status" ).annotate (
123+ total = Count ("id" )
124+ )
125+ country_type_summary = {
126+ country_type : {status [0 ]: 0 for status in statuses }
127+ for country_type in Grant .CountryType .values
128+ }
129+
130+ for data in country_type_data :
131+ country_type = data ["country_type" ]
132+ status = data ["status" ]
133+ total = data ["total" ]
134+ country_type_summary [country_type ][status ] += total
135+
136+ return country_type_summary
137+
110138 def _aggregate_data_by_gender (self , filtered_grants , statuses ):
111139 """
112140 Aggregates grant data by gender and status.
0 commit comments