Commit 331806f1 by John Hess

Merge pull request #1646 from MITx/feature/jkarni/folditx

Feature/jkarni/folditx
parents 894f9171 ad92eb4d
...@@ -86,7 +86,10 @@ class FolditModule(XModule): ...@@ -86,7 +86,10 @@ class FolditModule(XModule):
""" """
from foldit.models import Score from foldit.models import Score
return [(e['username'], e['score']) for e in Score.get_tops_n(10)] leaders = [(e['username'], e['score']) for e in Score.get_tops_n(10)]
leaders.sort(key=lambda x: x[1])
return leaders
def get_html(self): def get_html(self):
""" """
......
...@@ -59,7 +59,7 @@ class Score(models.Model): ...@@ -59,7 +59,7 @@ class Score(models.Model):
scores = Score.objects \ scores = Score.objects \
.filter(puzzle_id__in=puzzles) \ .filter(puzzle_id__in=puzzles) \
.annotate(total_score=models.Sum('best_score')) \ .annotate(total_score=models.Sum('best_score')) \
.order_by('-total_score')[:n] .order_by('total_score')[:n]
num = len(puzzles) num = len(puzzles)
return [{'username': s.user.username, return [{'username': s.user.username,
......
...@@ -143,11 +143,12 @@ class FolditTestCase(TestCase): ...@@ -143,11 +143,12 @@ class FolditTestCase(TestCase):
def test_SetPlayerPuzzleScores_manyplayers(self): def test_SetPlayerPuzzleScores_manyplayers(self):
""" """
Check that when we send scores from multiple users, the correct order Check that when we send scores from multiple users, the correct order
of scores is displayed. of scores is displayed. Note that, before being processed by
display_score, lower scores are better.
""" """
puzzle_id = ['1'] puzzle_id = ['1']
player1_score = 0.07 player1_score = 0.08
player2_score = 0.08 player2_score = 0.02
response1 = self.make_puzzle_score_request(puzzle_id, player1_score, response1 = self.make_puzzle_score_request(puzzle_id, player1_score,
self.user) self.user)
...@@ -164,8 +165,12 @@ class FolditTestCase(TestCase): ...@@ -164,8 +165,12 @@ class FolditTestCase(TestCase):
self.assertEqual(len(top_10), 2) self.assertEqual(len(top_10), 2)
# Top score should be player2_score. Second should be player1_score # Top score should be player2_score. Second should be player1_score
self.assertEqual(top_10[0]['score'], Score.display_score(player2_score)) self.assertAlmostEqual(top_10[0]['score'],
self.assertEqual(top_10[1]['score'], Score.display_score(player1_score)) Score.display_score(player2_score),
delta=0.5)
self.assertAlmostEqual(top_10[1]['score'],
Score.display_score(player1_score),
delta=0.5)
# Top score user should be self.user2.username # Top score user should be self.user2.username
self.assertEqual(top_10[0]['username'], self.user2.username) self.assertEqual(top_10[0]['username'], self.user2.username)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment