Skip to content

Commit

Permalink
[#224] Fix non-integer indicator values
Browse files Browse the repository at this point in the history
Some indicator values from Cordaid are percentage floats, e.g. 6.4. The
Benchmark.value field is an integer field so these values have to be
rounded.

Fix by adding IATIBenchmarkResource.hydrate_value. Note that this method
sets value to 0 on all errors, if an exception occurs this should be
logged for traceability.
  • Loading branch information
zzgvh committed Aug 15, 2013
1 parent 80e43a6 commit 1982d71
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions akvo/api/resources/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def hydrate_category(self, bundle):
)
return bundle

def hydrate_value(self, bundle):
"Values have to be integers"
try:
bundle.data['value'] = int(round(float(bundle.data['value'])))
except:
# TODO: logging!
bundle.data['value'] = 0
return bundle


class BenchmarkResource(ConditionalFullResource):
project = ConditionalFullToOneField('akvo.api.resources.ProjectResource', 'project')
Expand Down

0 comments on commit 1982d71

Please sign in to comment.