Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled check that sum of relative grades is 100 #3

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions moodlexport/python_to_moodle.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,17 @@ def _set(self, field, value=None):
self.dict[field] = {**field_structure['attribute'], **{"text": value}} # concatenation needs Python >= 3.5

def multi_answer(self): # unlocks the multiple answer mode
self.dict["single"] = "false" #TBA : check sum fractions is 100 or all 0 etc
self.dict["single"] = "false"

def has_answer(self):
return (self.get_type() == "multichoice") and self.structure['answer']['isset']

def cumulated_grade(self): # sums the fractions of grade in the answers
def cumulated_grade_correct(self): # sums the fractions of grade of correct answers
if self.structure['answer']['isset']:
s = 0
for answer in self.structure['answer']['list']:
s += answer.structure['relativegrade']
if answer.structure['relativegrade'] > 0:
s += answer.structure['relativegrade']
return s
else:
return 100
Expand All @@ -271,8 +272,8 @@ def compilation(self):
self._set('single', 'false')
elif answer.structure['relativegrade'] == 100: # we have a unique solution
self._set('single', 'true')
if self.cumulated_grade() != 100:
raise ValueError('In a multichoice Question, the sum of the relative grades/percentages of the Answers must be exactly 100, but here is '+str(self.cumulated_grade()))
if self.cumulated_grade_correct() != 100:
raise ValueError('In a multichoice Question, the sum of the relative grades/percentages of the correct answers must be exactly 100, but here is '+str(self.cumulated_grade_correct()))


def save(self, optional_name="Default-category-name"):
Expand Down Expand Up @@ -329,7 +330,7 @@ def __init__(self, answer_text="This is a default answer", grade=0):
def text(self, text):
self.structure['text'] = text

def relativegrade(self, grade):# must be a number (int?) between 0 and 100, decribing how much it is worth. Or a bool.
def relativegrade(self, grade):# must be a number (int?) between -100 and 100, decribing how much it is worth. Or a bool.
grade = bool_to_grade(grade)
self.structure['relativegrade'] = bool_to_grade(grade)

Expand All @@ -340,7 +341,7 @@ def istrue(self): # Says that this answer is THE good one
self.relativegrade(100)

def isfalse(self): # Says that this answer is not good
self.relativegrade(0)
self.relativegrade(0)

# GET FIELDS
def get_text(self):
Expand Down Expand Up @@ -371,8 +372,8 @@ def addto(self, question): # includes the answer into a question, do some checks
else:
question.structure["answer"]["isset"] = True
question.structure["answer"]["list"].append(self)
if question.cumulated_grade() > 100:
raise ValueError("In this Question the sum of relative grades/percentages of the Answers appears to be >100.")
if question.cumulated_grade_correct() > 100:
raise ValueError("In this Question the sum of relative grades/percentages of the correct answers appears to be >100.")

# NEEDED FUNCTIONS
def bool_to_grade(grade):
Expand All @@ -385,8 +386,8 @@ def bool_to_grade(grade):
return 0
else: # it is already an integer (we hope so)
grade = int(grade)
if grade > 100 or grade < 0:
raise ValueError('For an Answer, the (relative) grade must be a number between 0 and 100, representing its precentage of "truthness".')
if grade > 100 or grade < -100:
raise ValueError('For an answer, the (relative) grade must be a number between -100 and 100, representing the percentage of points gained/lost by marking it as correct.')
else:
return grade

Expand Down