From 588b27c9dc6911e9b8e0728f274b155cf9674c46 Mon Sep 17 00:00:00 2001 From: Julian Arni Date: Mon, 11 Mar 2013 11:17:12 -0400 Subject: [PATCH 1/5] Added Descriptor method, fixed order issue. --- common/lib/xmodule/xmodule/foldit_module.py | 14 ++++++++++---- lms/djangoapps/foldit/models.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/lib/xmodule/xmodule/foldit_module.py b/common/lib/xmodule/xmodule/foldit_module.py index 920a5aed6d..2bcdda5bc2 100644 --- a/common/lib/xmodule/xmodule/foldit_module.py +++ b/common/lib/xmodule/xmodule/foldit_module.py @@ -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): """ @@ -173,7 +176,10 @@ class FolditDescriptor(XmlDescriptor, EditingDescriptor): @classmethod def definition_from_xml(cls, xml_object, system): - """ - Get the xml_object's attributes. - """ + """ Get the xml_object's attributes. """ + return {'metadata': xml_object.attrib} + + def definition_to_xml(self): + xml_object = etree.Element('foldit') + return xml_object diff --git a/lms/djangoapps/foldit/models.py b/lms/djangoapps/foldit/models.py index 7041be1446..0dce956756 100644 --- a/lms/djangoapps/foldit/models.py +++ b/lms/djangoapps/foldit/models.py @@ -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, From 6e92666a203ed9ec149a44458c24e6d3d1a6be97 Mon Sep 17 00:00:00 2001 From: Julian Arni Date: Mon, 11 Mar 2013 14:57:19 -0400 Subject: [PATCH 2/5] Fixed score order. Less is more. --- lms/djangoapps/foldit/tests.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lms/djangoapps/foldit/tests.py b/lms/djangoapps/foldit/tests.py index 7127651601..afdd678f06 100644 --- a/lms/djangoapps/foldit/tests.py +++ b/lms/djangoapps/foldit/tests.py @@ -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) From cc2c26b9240271eb79e334b4c2768ab7684dc592 Mon Sep 17 00:00:00 2001 From: John Hess Date: Mon, 11 Mar 2013 18:04:21 -0400 Subject: [PATCH 3/5] reverted change to definition to/from xml --- common/lib/xmodule/xmodule/foldit_module.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/foldit_module.py b/common/lib/xmodule/xmodule/foldit_module.py index 2bcdda5bc2..65632fa031 100644 --- a/common/lib/xmodule/xmodule/foldit_module.py +++ b/common/lib/xmodule/xmodule/foldit_module.py @@ -176,10 +176,9 @@ class FolditDescriptor(XmlDescriptor, EditingDescriptor): @classmethod def definition_from_xml(cls, xml_object, system): - """ Get the xml_object's attributes. """ + """ + Get the xml_object's attributes. + """ return {'metadata': xml_object.attrib} - def definition_to_xml(self): - xml_object = etree.Element('foldit') - return xml_object From 00c35c95a4140741da9669c7d01965cba98a7170 Mon Sep 17 00:00:00 2001 From: John Hess Date: Mon, 11 Mar 2013 18:05:10 -0400 Subject: [PATCH 4/5] whitespace back to original --- common/lib/xmodule/xmodule/foldit_module.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/foldit_module.py b/common/lib/xmodule/xmodule/foldit_module.py index 65632fa031..152930876d 100644 --- a/common/lib/xmodule/xmodule/foldit_module.py +++ b/common/lib/xmodule/xmodule/foldit_module.py @@ -176,9 +176,7 @@ class FolditDescriptor(XmlDescriptor, EditingDescriptor): @classmethod def definition_from_xml(cls, xml_object, system): - """ + """ Get the xml_object's attributes. """ - return {'metadata': xml_object.attrib} - From ad92eb4d022da3c7aba6df37929905621b2d4610 Mon Sep 17 00:00:00 2001 From: John Hess Date: Mon, 11 Mar 2013 18:05:34 -0400 Subject: [PATCH 5/5] whitespace back to original. for real though. --- common/lib/xmodule/xmodule/foldit_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/foldit_module.py b/common/lib/xmodule/xmodule/foldit_module.py index 152930876d..37255bd5cb 100644 --- a/common/lib/xmodule/xmodule/foldit_module.py +++ b/common/lib/xmodule/xmodule/foldit_module.py @@ -177,6 +177,6 @@ class FolditDescriptor(XmlDescriptor, EditingDescriptor): @classmethod def definition_from_xml(cls, xml_object, system): """ - Get the xml_object's attributes. + Get the xml_object's attributes. """ return {'metadata': xml_object.attrib}