From 9ce51ec6cf78117957041a44f9569a4139f0e89d Mon Sep 17 00:00:00 2001 From: Alexander Kryklia Date: Tue, 27 Nov 2012 13:09:58 +0200 Subject: [PATCH] support for single list syntax in regions --- common/lib/capa/capa/responsetypes.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 74c801b450..000d77d655 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -1758,9 +1758,10 @@ class ImageResponse(LoncapaResponse): def get_score(self, student_answers): correct_map = CorrectMap() expectedset = self.get_answers() - + # import ipdb; ipdb.set_trace() for aid in self.answer_ids: # loop through IDs of # fields in our stanza + # import ipdb; ipdb.set_trace() given = student_answers[aid] # this should be a string of the form '[x,y]' correct_map.set(aid, 'incorrect') @@ -1795,10 +1796,16 @@ class ImageResponse(LoncapaResponse): break if regions[aid]: parsed_region = json.loads(regions[aid]) - for region in parsed_region: - if Polygon(region).contains(Point(gx, gy)): - correct_map.set(aid, 'correct') - break + if parsed_region: + if type(parsed_region[0][0]) != list: + # we have [[1,2],[3,4],[5,6] - single region + # instead of [[[1,2],[3,4],[5,6], [[1,2],[3,4],[5,6]] + # or [[[1,2],[3,4],[5,6]] - multiple regions syntax + parsed_region = [parsed_region] + for region in parsed_region: + if Polygon(region).contains(Point(gx, gy)): + correct_map.set(aid, 'correct') + break return correct_map def get_answers(self):