replace explicite list of answer options with answer range (= number of answer options)
This commit is contained in:
parent
6164b311a6
commit
63163a00e7
2 changed files with 11 additions and 14 deletions
|
@ -34,7 +34,7 @@ class IQuestionnaire(Interface):
|
||||||
questions = Attribute('An ordered collection of questions.')
|
questions = Attribute('An ordered collection of questions.')
|
||||||
questionGroups = Attribute('An ordered collection of question groups (optional).')
|
questionGroups = Attribute('An ordered collection of question groups (optional).')
|
||||||
responses = Attribute('A set of responses.')
|
responses = Attribute('A set of responses.')
|
||||||
defaultAnswerOptions = Attribute('A sequence of answer options to select from. '
|
defaultAnswerRange = Attribute('The number of answer options to select from. '
|
||||||
'Default value used for questions that do not '
|
'Default value used for questions that do not '
|
||||||
'explicitly provide the values attribute.')
|
'explicitly provide the values attribute.')
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class IQuestion(Interface):
|
||||||
|
|
||||||
text = Attribute('The question asked.')
|
text = Attribute('The question asked.')
|
||||||
questionnaire = Attribute('The questionnaire this question belongs to.')
|
questionnaire = Attribute('The questionnaire this question belongs to.')
|
||||||
answerOptions = Attribute('A sequence of answer options to select from.')
|
answerRange = Attribute('The number of answer options to select from.')
|
||||||
feedbackItems = Attribute('A mapping with feedback items as keys and '
|
feedbackItems = Attribute('A mapping with feedback items as keys and '
|
||||||
'corresponding relevance factors as values.')
|
'corresponding relevance factors as values.')
|
||||||
revertAnswerOptions = Attribute('Revert the sequence of answer '
|
revertAnswerOptions = Attribute('Revert the sequence of answer '
|
||||||
|
|
|
@ -30,11 +30,12 @@ class Questionnaire(object):
|
||||||
|
|
||||||
implements(IQuestionnaire)
|
implements(IQuestionnaire)
|
||||||
|
|
||||||
|
defaultAnswerRange = 5
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.questionGroups = []
|
self.questionGroups = []
|
||||||
self.questions = []
|
self.questions = []
|
||||||
self.responses = []
|
self.responses = []
|
||||||
self.defaultAnswerOptions = range(5)
|
|
||||||
|
|
||||||
|
|
||||||
class QuestionGroup(object):
|
class QuestionGroup(object):
|
||||||
|
@ -51,8 +52,7 @@ class Question(object):
|
||||||
|
|
||||||
implements(IQuestion)
|
implements(IQuestion)
|
||||||
|
|
||||||
_answerOptions = None
|
_answerRange = None
|
||||||
|
|
||||||
revertAnswerOptions = False
|
revertAnswerOptions = False
|
||||||
|
|
||||||
def __init__(self, questionnaire, text=u''):
|
def __init__(self, questionnaire, text=u''):
|
||||||
|
@ -60,14 +60,11 @@ class Question(object):
|
||||||
self.feedbackItems = {}
|
self.feedbackItems = {}
|
||||||
self.text = text
|
self.text = text
|
||||||
|
|
||||||
def getAnswerOptions(self):
|
def getAnswerRange(self):
|
||||||
result = self._answerOptions or self.questionnaire.defaultAnswerOptions
|
return self._answerRange or self.questionnaire.defaultAnswerRange
|
||||||
if self.revertAnswerOptions:
|
def setAnswerRange(self, value):
|
||||||
result.reverse()
|
self._answerRange = value
|
||||||
return result
|
answerRange = property(getAnswerRange, setAnswerRange)
|
||||||
def setAnswerOptions(self, value):
|
|
||||||
self._answerOptions = value
|
|
||||||
answerOptions = property(getAnswerOptions, setAnswerOptions)
|
|
||||||
|
|
||||||
|
|
||||||
class FeedbackItem(object):
|
class FeedbackItem(object):
|
||||||
|
@ -100,7 +97,7 @@ class Response(object):
|
||||||
score = scoreMax = 0.0
|
score = scoreMax = 0.0
|
||||||
for qu in qugroup.questions:
|
for qu in qugroup.questions:
|
||||||
score += self.values.get(qu, 0.0)
|
score += self.values.get(qu, 0.0)
|
||||||
scoreMax += max(qu.answerOptions)
|
scoreMax += qu.answerRange - 1
|
||||||
relScore = score / scoreMax
|
relScore = score / scoreMax
|
||||||
wScore = relScore * (len(qugroup.feedbackItems) - 1)
|
wScore = relScore * (len(qugroup.feedbackItems) - 1)
|
||||||
result.append((qugroup.feedbackItems[int(wScore)], wScore))
|
result.append((qugroup.feedbackItems[int(wScore)], wScore))
|
||||||
|
|
Loading…
Add table
Reference in a new issue