'Calculates partial credit on the Halves scheme.
If no errors, full credit.
If one error, half credit as long as there are 3+ choices
If two errors, 1/4 credit as long as there are 5+ choices
(If not enough choices, no credit.)
Arguments:
all_choices, the full set of checkboxes
student_answer, what the student actually chose
student_non_answers, what the student didn\'t choose
Returns a CorrectMap'

def grade_via_halves(self, **kwargs):

    all_choices = kwargs['all_choices']
    student_answer = kwargs['student_answer']
    student_non_answers = kwargs['student_non_answers']
    halves_error_count = 0
    incorrect_answers = sum([1 for answer in student_answer if (answer in self.incorrect_choices)])
    missed_answers = sum([1 for blank in student_non_answers if (blank in self.correct_choices)])
    halves_error_count = (incorrect_answers + missed_answers)
    if (halves_error_count == 0):
        return_grade = self.get_max_score()
        return CorrectMap(self.answer_id, correctness='correct', npoints=return_grade)
    elif ((halves_error_count == 1) and (len(all_choices) > 2)):
        return_grade = round((self.get_max_score() / 2.0), 2)
        return CorrectMap(self.answer_id, correctness='partially-correct', npoints=return_grade)
    elif ((halves_error_count == 2) and (len(all_choices) > 4)):
        return_grade = round((self.get_max_score() / 4.0), 2)
        return CorrectMap(self.answer_id, correctness='partially-correct', npoints=return_grade)
    else:
        return CorrectMap(self.answer_id, 'incorrect')
