--- a/OSSEval/analysis/models.py
+++ b/OSSEval/analysis/models.py
@@ -258,8 +258,9 @@
weight = weight_scenario.question_weight(question.id)
self.max_score_weighted += question.max_score() * weight
try:
- answer = Answer.objects.get(question=question, instance=instance)
- answer.score = weight * (answer.value_integer-1)
+ choices = Choice.objects.filter(question=question)
+ answer = Answer.objects.get(choice__in=choices, instance=instance)
+ answer.score = weight * (answer.choice.value)
answer.save()
ps.score += answer.score
except Exception as ex:
@@ -339,8 +340,8 @@
def max_score(self):
max_score = 0
for choice in self.choice_set.all():
- if choice.order-1 > max_score:
- max_score = choice.order-1
+ if choice.value > max_score:
+ max_score = choice.value
return max_score
class Meta:
@@ -375,6 +376,7 @@
question = models.ForeignKey(Question)
text = models.CharField(max_length=200)
order = models.IntegerField()
+ value = models.FloatField()
todo = models.CharField(max_length=2000)
def from_xml(self, xmldoc, question, insert = True):
@@ -383,12 +385,13 @@
self.question = question
self.text = xmlMinidom.getStringAttribute(xmldoc, 'Text')
self.order = xmlMinidom.getNaturalAttribute(xmldoc, 'Order')
+ self.value = xmlMinidom.getFloatAttribute(xmldoc, 'Value')
self.todo = xmlMinidom.getString(xmldoc, 'Todo')
self.save()
def to_xml(self):
str_xml = "<Todo>" + self.todo + "</Todo>"
- return '<Choice Id="' + str(self.id) + '" Text="' + self.text + '" Order="' + str(self.order) + '">' + str_xml + '</Choice>'
+ return '<Choice Id="' + str(self.id) + '" Text="' + self.text + '" Order="' + str(self.order) + '" Value="' + str(self.value) + '">' + str_xml + '</Choice>'
class Meta:
ordering = ['order']
@@ -436,7 +439,6 @@
def __str__(self):
return self.name
-
class Graphs(models.Model):
bar_chart = models.TextField(blank=True)
@@ -574,10 +576,16 @@
xml_actual_instance = xmldoc.getElementsByTagName(self.analysis.methodology_version.methodology.entity.actual_entity_class)[0]
module = importlib.import_module(self.analysis.methodology_version.methodology.entity.actual_entity_app + ".models")
actual_entity_class = getattr(module, self.analysis.methodology_version.methodology.entity.actual_entity_class)
- self.actual_instance = actual_entity_class()
+
+ # The actual_instance now has a specific name for each Entity
+ # self.actual_instance = actual_entity_class()
+ setattr(self, self.analysis.methodology_version.methodology.entity.actual_instance_accessor, actual_entity_class())
+ actual_instance = getattr(self, self.analysis.methodology_version.methodology.entity.actual_instance_accessor)
+
# I need to save this instance so that I can save the actual_instance in the following from_xml
self.save()
- self.actual_instance.from_xml(xml_actual_instance, self, insert)
+ # self.actual_instance.from_xml(xml_actual_instance, self, insert)
+ actual_instance.from_xml(xml_actual_instance, self, insert)
self.save()
#Answers
xml_answers = xmldoc.getElementsByTagName('Answer')
@@ -590,7 +598,9 @@
for answer in self.answer_set.all():
str_xml += answer.to_xml()
str_xml += "</Answers>"
- str_xml += self.actual_instance.to_xml()
+ actual_instance = getattr(self, self.analysis.methodology_version.methodology.entity.actual_instance_accessor)
+ str_xml += actual_instance.to_xml()
+# str_xml += self.actual_instance.to_xml()
return '<Instance Id="' + str(self.id) + '" Name="' + self.name + '">' + str_xml + "</Instance>"
class PageScore(models.Model):
@@ -602,13 +612,12 @@
class Answer(models.Model):
"""
- value_integer is the value of the answer
- score is value_integer * weight
- where weight is associated to the question in a WeightScenario
+ choice.value is the value of the answer
+ score is choice.value * weight
+ where weight is associated to the question in current WeightScenario
"""
instance = models.ForeignKey(Instance)
- question = models.ForeignKey(Question)
- value_integer = models.IntegerField()
+ choice = models.ForeignKey(Choice)
score = models.FloatField(default=0)
notes = models.CharField(max_length=2000)
@@ -616,21 +625,20 @@
if not insert:
self.id = xmlMinidom.getNaturalAttribute(xmldoc, 'Id')
self.instance = instance
- xml_question = xmldoc.getElementsByTagName('Question')[0]
- question = Question.objects.get(pk = xmlMinidom.getNaturalAttribute(xml_question, 'Id'))
- self.question = question
- self.value_integer = xmlMinidom.getNaturalAttribute(xmldoc, 'ValueInteger')
+ xml_choice = xmldoc.getElementsByTagName('Choice')[0]
+ choice = Choice.objects.get(pk = xmlMinidom.getNaturalAttribute(xml_choice, 'Id'))
+ self.choice = choice
xml_notes = xmldoc.getElementsByTagName('Notes')[0]
try:
self.notes = xml_notes.firstChild.data
except:
self.notes = ""
# If I am inserting I must check that there's no other answer for the same
- # couple ('question', 'instance') as I have a unique_together constraint
+ # couple ('choice.question', 'instance') as I have a unique_together constraint
if not self.id:
# I look for an answer for the same question and instance
try:
- a = Answer.objects.get(instance_id=self.instance.id, question_id=self.question.id)
+ a = Answer.objects.get(instance_id=self.instance.id, choice_question_id=self.choice.question.id)
a.delete()
except:
# I didn't find one; nothing to do
@@ -639,12 +647,9 @@
def to_xml(self):
str_xml = "<Notes>" + self.notes + "</Notes>"
- str_xml += '<Question Id="' + str(self.question.id) + '"></Question>'
+ str_xml += '<Choice Id="' + str(self.choice.id) + '"></Choice>'
- return '<Answer Id="' + str(self.id) + '" ValueInteger="' + str(self.value_integer) + '">' + str_xml + "</Answer>"
-
- class Meta:
- unique_together = ('question', 'instance',)
+ return '<Answer Id="' + str(self.id) + '">' + str_xml + "</Answer>"
class UploadedFile(models.Model):
'''