Commit 9ce51ec6 by Alexander Kryklia

support for single list syntax in regions

parent 647d1514
...@@ -1758,9 +1758,10 @@ class ImageResponse(LoncapaResponse): ...@@ -1758,9 +1758,10 @@ class ImageResponse(LoncapaResponse):
def get_score(self, student_answers): def get_score(self, student_answers):
correct_map = CorrectMap() correct_map = CorrectMap()
expectedset = self.get_answers() expectedset = self.get_answers()
# import ipdb; ipdb.set_trace()
for aid in self.answer_ids: # loop through IDs of <imageinput> for aid in self.answer_ids: # loop through IDs of <imageinput>
# fields in our stanza # fields in our stanza
# import ipdb; ipdb.set_trace()
given = student_answers[aid] # this should be a string of the form '[x,y]' given = student_answers[aid] # this should be a string of the form '[x,y]'
correct_map.set(aid, 'incorrect') correct_map.set(aid, 'incorrect')
...@@ -1795,10 +1796,16 @@ class ImageResponse(LoncapaResponse): ...@@ -1795,10 +1796,16 @@ class ImageResponse(LoncapaResponse):
break break
if regions[aid]: if regions[aid]:
parsed_region = json.loads(regions[aid]) parsed_region = json.loads(regions[aid])
for region in parsed_region: if parsed_region:
if Polygon(region).contains(Point(gx, gy)): if type(parsed_region[0][0]) != list:
correct_map.set(aid, 'correct') # we have [[1,2],[3,4],[5,6] - single region
break # 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 return correct_map
def get_answers(self): def get_answers(self):
......
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