Skip to content

Commit

Permalink
return normalized rep values
Browse files Browse the repository at this point in the history
  • Loading branch information
jellegerbrandy committed Apr 26, 2016
1 parent cf38b67 commit 154f9b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions restapi/tests/test_contributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ def test_data(self):
data = self.app.get(self.url_resource(contribution_id)).json
self.assertEqual(type(data['stats']['evaluations']['0']['reputation']), types.FloatType)
self.assertEqual(type(data['stats']['evaluations']['1']['reputation']), types.FloatType)

# check also if we have normalized the reputation
# (i.e. it should be between 0 and 1)
self.assertLess(data['stats']['engaged_reputation'], 1.0)
self.assertLess(data['stats']['evaluations']['0']['reputation'], 1.0)
self.assertLess(data['stats']['evaluations']['1']['reputation'], 1.0)
7 changes: 7 additions & 0 deletions restapi/views/contributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def contribution_to_dict(contribution, request):
"""return a dictionary with information about this contribution"""
user = contribution.user
stats = contribution.get_statistics()
# show only normalized values for the reputation fields
stats['engaged_reputation'] = stats['engaged_reputation_normal']
del stats['engaged_reputation_normal']
for val in stats['evaluations']:
stats['evaluations'][val]['reputation'] = stats['evaluations'][val]['reputation_normal']
del stats['evaluations'][val]['reputation_normal']

return {
'id': contribution.id,
'contributor': {
Expand Down

0 comments on commit 154f9b5

Please sign in to comment.