apluslms/mooc-grader

Radio with custom integer values is not graded properly on correct answer

MikaelSiidorow opened this issue · 2 comments

If I have a submit exercise with a radio field:

# -- snip --
max_points: 1
view_type: access.types.stdsync.createForm

fieldgroups:
  - title: Radio Form
    type: radio
    required: true
    points: 1
    options:
      - label: Option 1
        value: 100
        correct: true
      - label: Option 2
        value: 200
        correct: true

All options are correct so I should receive points regardless of which one I pick, but the result is always 0 points.

I believe I've located the cause to the method grade_radio

def grade_radio(self, configuration, value, hints=None):
hints = hints or []
# There may be several correct options, but only one of them needs to
# be selected in the submission in order to gain points.
correct = False
i = 0
for opt in configuration.get("options", []):
name = self.option_name(i, opt)
if opt.get("correct", False):
if name == value:
correct = True
else:
self.append_hint(hints, opt)
elif name == value:
self.append_hint(hints, opt)
i += 1
return correct, hints, 'string'

Where on line 752 the if name == value is performing a str to int comparison, so it is always false.

Thanks for the report! If this is about comparing strings to ints, then what if you write values as strings in the assignment config.yaml file? That is, value: "100"

Thanks for the report! If this is about comparing strings to ints, then what if you write values as strings in the assignment config.yaml file? That is, value: "100"

Yeah, this works perfectly and is the workaround we ended up going with, since there was no need for our data to specifically be integers.