Merge pull request #1646 from MITx/feature/jkarni/folditx
Feature/jkarni/folditx
This commit is contained in:
@@ -86,7 +86,10 @@ class FolditModule(XModule):
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
|
||||
@@ -59,7 +59,7 @@ class Score(models.Model):
|
||||
scores = Score.objects \
|
||||
.filter(puzzle_id__in=puzzles) \
|
||||
.annotate(total_score=models.Sum('best_score')) \
|
||||
.order_by('-total_score')[:n]
|
||||
.order_by('total_score')[:n]
|
||||
num = len(puzzles)
|
||||
|
||||
return [{'username': s.user.username,
|
||||
|
||||
@@ -143,11 +143,12 @@ class FolditTestCase(TestCase):
|
||||
def test_SetPlayerPuzzleScores_manyplayers(self):
|
||||
"""
|
||||
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']
|
||||
player1_score = 0.07
|
||||
player2_score = 0.08
|
||||
player1_score = 0.08
|
||||
player2_score = 0.02
|
||||
response1 = self.make_puzzle_score_request(puzzle_id, player1_score,
|
||||
self.user)
|
||||
|
||||
@@ -164,8 +165,12 @@ class FolditTestCase(TestCase):
|
||||
self.assertEqual(len(top_10), 2)
|
||||
|
||||
# Top score should be player2_score. Second should be player1_score
|
||||
self.assertEqual(top_10[0]['score'], Score.display_score(player2_score))
|
||||
self.assertEqual(top_10[1]['score'], Score.display_score(player1_score))
|
||||
self.assertAlmostEqual(top_10[0]['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
|
||||
self.assertEqual(top_10[0]['username'], self.user2.username)
|
||||
|
||||
Reference in New Issue
Block a user