replace explicite list of answer options with answer range (= number of answer options)

This commit is contained in:
Helmut Merz 2013-02-24 15:28:37 +01:00
parent 6164b311a6
commit 63163a00e7
2 changed files with 11 additions and 14 deletions

View file

@ -34,7 +34,7 @@ class IQuestionnaire(Interface):
questions = Attribute('An ordered collection of questions.')
questionGroups = Attribute('An ordered collection of question groups (optional).')
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 '
'explicitly provide the values attribute.')
@ -57,7 +57,7 @@ class IQuestion(Interface):
text = Attribute('The question asked.')
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 '
'corresponding relevance factors as values.')
revertAnswerOptions = Attribute('Revert the sequence of answer '

View file

@ -29,12 +29,13 @@ from cybertools.knowledge.survey.interfaces import IFeedbackItem, IResponse
class Questionnaire(object):
implements(IQuestionnaire)
defaultAnswerRange = 5
def __init__(self):
self.questionGroups = []
self.questions = []
self.responses = []
self.defaultAnswerOptions = range(5)
class QuestionGroup(object):
@ -51,8 +52,7 @@ class Question(object):
implements(IQuestion)
_answerOptions = None
_answerRange = None
revertAnswerOptions = False
def __init__(self, questionnaire, text=u''):
@ -60,14 +60,11 @@ class Question(object):
self.feedbackItems = {}
self.text = text
def getAnswerOptions(self):
result = self._answerOptions or self.questionnaire.defaultAnswerOptions
if self.revertAnswerOptions:
result.reverse()
return result
def setAnswerOptions(self, value):
self._answerOptions = value
answerOptions = property(getAnswerOptions, setAnswerOptions)
def getAnswerRange(self):
return self._answerRange or self.questionnaire.defaultAnswerRange
def setAnswerRange(self, value):
self._answerRange = value
answerRange = property(getAnswerRange, setAnswerRange)
class FeedbackItem(object):
@ -100,7 +97,7 @@ class Response(object):
score = scoreMax = 0.0
for qu in qugroup.questions:
score += self.values.get(qu, 0.0)
scoreMax += max(qu.answerOptions)
scoreMax += qu.answerRange - 1
relScore = score / scoreMax
wScore = relScore * (len(qugroup.feedbackItems) - 1)
result.append((qugroup.feedbackItems[int(wScore)], wScore))