@@ -279,11 +279,11 @@ def update_aggregate(self, grant):
279279 # "maxAwardDate": yyyy-mm-dd,
280280 # "currencies": {
281281 # "recipient_org": {
282- # "GBP": { "grants": 0, "total": 0, "min": 0, "max": 0 },
282+ # "GBP": { "grants": 0, "total": 0, "min": 0, "max": 0, "avg":0 },
283283 # ...
284284 # },
285285 # "recipient_ind": {
286- # "GBP": { "grants": 0, "total": 0, "min": 0, "max": 0 },
286+ # "GBP": { "grants": 0, "total": 0, "min": 0, "max": 0, "avg":0 },
287287 # ...
288288 # }
289289 # },
@@ -335,6 +335,7 @@ def update_aggregate(self, grant):
335335 "total" : amount ,
336336 "min" : amount ,
337337 "max" : amount ,
338+ "avg" : amount ,
338339 "grants" : 1 ,
339340 }
340341 else :
@@ -343,6 +344,14 @@ def update_aggregate(self, grant):
343344 self .aggregate [C ][currency ][recipient_type ]["grants" ] += 1
344345 self .aggregate [C ][currency ][recipient_type ]["total" ] += amount
345346
347+ # Important that the avg is calculated _after_ the total number
348+ # of grants for the currency has been accumulated.
349+ # NOTE: avg currency amount to be deprecated
350+ # https://github.com/ThreeSixtyGiving/datastore/issues/292
351+ self .aggregate [C ][currency ][recipient_type ]["avg" ] = (
352+ amount / self .aggregate [C ][currency ][recipient_type ]["grants" ]
353+ )
354+
346355 if self .aggregate [C ][currency ][recipient_type ]["max" ] < amount :
347356 self .aggregate [C ][currency ][recipient_type ]["max" ] = amount
348357
0 commit comments