rename 'ResultElement' to 'FeedbackItem'

This commit is contained in:
Helmut Merz 2013-02-24 10:01:32 +01:00
parent 952f2a989b
commit 4d9844391e
3 changed files with 17 additions and 17 deletions

View file

@ -13,14 +13,14 @@ Let's first set up a questionaire.
We now assign result elements with the questions of this questionnaire. We now assign result elements with the questions of this questionnaire.
>>> from cybertools.knowledge.survey.questionnaire import ResultElement >>> from cybertools.knowledge.survey.questionnaire import FeedbackItem
>>> re01 = ResultElement('re01') >>> re01 = FeedbackItem('re01')
>>> re02 = ResultElement('re02') >>> re02 = FeedbackItem('re02')
>>> re03 = ResultElement('re03') >>> re03 = FeedbackItem('re03')
>>> qu01.resultElements = {re01: 0.8, re03: 0.2} >>> qu01.feedbackItems = {re01: 0.8, re03: 0.2}
>>> qu02.resultElements = {re01: 0.3, re02: 0.7, re03: 0.1} >>> qu02.feedbackItems = {re01: 0.3, re02: 0.7, re03: 0.1}
>>> qu03.resultElements = {re01: 0.2, re03: 0.9} >>> qu03.feedbackItems = {re01: 0.2, re03: 0.9}
Responses Responses

View file

@ -45,16 +45,16 @@ 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.') answerOptions = Attribute('A sequence of answer options to select from.')
resultElements = Attribute('A mapping with result elements as keys and ' feedbackItems = Attribute('A mapping with feedback items as keys and '
'corresponding relevance factors as values.') 'corresponding relevance factors as values.')
class IResultElement(Interface): class IFeedbackItem(Interface):
""" Some text (e.g. a recommendation) or some other kind of information """ Some text (e.g. a recommendation) or some other kind of information
that may be deduced from the res)ponses to a questionnaire. that may be deduced from the responses to a questionnaire.
""" """
text = Attribute('A text representing this result element.') text = Attribute('A text representing this feedback item.')
class IResponse(Interface): class IResponse(Interface):

View file

@ -22,7 +22,7 @@ Questionnaires, questions and other stuff needed for surveys.
from zope.interface import implements from zope.interface import implements
from cybertools.knowledge.survey.interfaces import IQuestionnaire, IQuestion from cybertools.knowledge.survey.interfaces import IQuestionnaire, IQuestion
from cybertools.knowledge.survey.interfaces import IResultElement, IResponse from cybertools.knowledge.survey.interfaces import IFeedbackItem, IResponse
class Questionnaire(object): class Questionnaire(object):
@ -43,7 +43,7 @@ class Question(object):
def __init__(self, questionnaire, text=u''): def __init__(self, questionnaire, text=u''):
self.questionnaire = questionnaire self.questionnaire = questionnaire
self.resultElements = {} self.feedbackItems = {}
self.text = text self.text = text
def getAnswerOptions(self): def getAnswerOptions(self):
@ -53,9 +53,9 @@ class Question(object):
answerOptions = property(getAnswerOptions, setAnswerOptions) answerOptions = property(getAnswerOptions, setAnswerOptions)
class ResultElement(object): class FeedbackItem(object):
implements(IResultElement) implements(IFeedbackItem)
def __init__(self, text=u''): def __init__(self, text=u''):
self.text = text self.text = text
@ -73,7 +73,7 @@ class Response(object):
def getResult(self): def getResult(self):
result = {} result = {}
for question, value in self.values.items(): for question, value in self.values.items():
for re, rf in question.resultElements.items(): for fi, rf in question.feedbackItems.items():
result[re] = result.get(re, 0.0) + rf * value result[fi] = result.get(fi, 0.0) + rf * value
#print re.text, rf, value #print re.text, rf, value
return sorted(result.items(), key=lambda x: -x[1]) return sorted(result.items(), key=lambda x: -x[1])