|
a/OSSEval/analysis/models.py |
|
b/OSSEval/analysis/models.py |
|
... |
|
... |
66 |
try:
|
66 |
try:
|
67 |
ps = PageScore.objects.get(page=page, instance=instance)
|
67 |
ps = PageScore.objects.get(page=page, instance=instance)
|
68 |
instance_scores[instance.id].append(ps.score)
|
68 |
instance_scores[instance.id].append(ps.score)
|
69 |
except:
|
69 |
except:
|
70 |
instance_scores[instance.id].append(0)
|
70 |
instance_scores[instance.id].append(0)
|
71 |
if include_max:
|
71 |
if include_max:
|
72 |
instance_scores[0].append(5)
|
72 |
instance_scores[0].append(page.max_score_weighted)
|
73 |
print str(page.id) + " - " + str(page.max_score)
|
73 |
print page.name + " - " + str(page.max_score_weighted)
|
74 |
for instance in instances:
|
74 |
for instance in instances:
|
75 |
radar_chart.add(instance.name, instance_scores[instance.id])
|
75 |
radar_chart.add(instance.name, instance_scores[instance.id])
|
76 |
bar_chart.add(instance.name, sum(instance_scores[instance.id]))
|
76 |
bar_chart.add(instance.name, sum(instance_scores[instance.id]))
|
77 |
if include_max:
|
77 |
if include_max:
|
78 |
radar_chart.add("MAX", instance_scores[0])
|
78 |
radar_chart.add("MAX", instance_scores[0])
|
|
... |
|
... |
136 |
class Page(HasPages):
|
136 |
class Page(HasPages):
|
137 |
name = models.CharField(max_length=200)
|
137 |
name = models.CharField(max_length=200)
|
138 |
order = models.IntegerField(null=False,blank=False)
|
138 |
order = models.IntegerField(null=False,blank=False)
|
139 |
parent = models.ForeignKey('self',null=True,blank=True)
|
139 |
parent = models.ForeignKey('self',null=True,blank=True)
|
140 |
methodology_version = models.ForeignKey(MethodologyVersion,null=True,blank=True)
|
140 |
methodology_version = models.ForeignKey(MethodologyVersion,null=True,blank=True)
|
141 |
max_score = 0
|
141 |
max_score_weighted = models.IntegerField(null=False,blank=False,default=0)
|
|
|
142 |
|
142 |
def questions(self):
|
143 |
def questions(self):
|
143 |
q = list(self.question_set.all())
|
144 |
q = list(self.question_set.all())
|
144 |
for p in self.page_set.all():
|
145 |
for p in self.page_set.all():
|
145 |
q += p.questions()
|
146 |
q += p.questions()
|
146 |
return q
|
147 |
return q
|
|
... |
|
... |
189 |
str_xml += question.to_xml()
|
190 |
str_xml += question.to_xml()
|
190 |
str_xml += "</Questions>"
|
191 |
str_xml += "</Questions>"
|
191 |
return '<Page Id="' + str(self.id) + '" Name="' + self.name + '" Order="' + str(self.order) + '">' + str_xml + "</Page>"
|
192 |
return '<Page Id="' + str(self.id) + '" Name="' + self.name + '" Order="' + str(self.order) + '">' + str_xml + "</Page>"
|
192 |
|
193 |
|
193 |
def calculate_scores(self, instance, weight_scenario, instances):
|
194 |
def calculate_scores(self, instance, weight_scenario, instances):
|
194 |
self.max_score = 5
|
195 |
self.max_score_weighted = 0
|
195 |
# Let's reset the score to 0
|
196 |
# Let's reset the score to 0
|
196 |
try:
|
197 |
try:
|
197 |
ps = PageScore.objects.get(page=self, instance=instance)
|
198 |
ps = PageScore.objects.get(page=self, instance=instance)
|
198 |
except:
|
199 |
except:
|
199 |
ps = PageScore(page=self, instance=instance, score=0)
|
200 |
ps = PageScore(page=self, instance=instance, score=0)
|
200 |
ps.score = 0
|
201 |
ps.score = 0
|
201 |
# and calculate the score for child pages and add it to current page's score
|
202 |
# and calculate the score for child pages and add it to current page's score
|
202 |
for page in self.page_set.all():
|
203 |
for page in self.page_set.all():
|
203 |
ps.score += page.calculate_scores(instance, weight_scenario, instances)
|
204 |
ps.score += page.calculate_scores(instance, weight_scenario, instances)
|
|
|
205 |
self.max_score_weighted += page.max_score_weighted
|
204 |
# Loop on questions
|
206 |
# Loop on questions
|
205 |
for question in self.questions():
|
207 |
for question in self.question_set.all():
|
206 |
weight = weight_scenario.question_weight(question.id)
|
208 |
weight = weight_scenario.question_weight(question.id)
|
|
|
209 |
self.max_score_weighted += question.max_score() * weight
|
207 |
try:
|
210 |
try:
|
208 |
answer = Answer.objects.get(question=question, instance=instance)
|
211 |
answer = Answer.objects.get(question=question, instance=instance)
|
209 |
answer.score = weight * (answer.value_integer-1)
|
212 |
answer.score = weight * (answer.value_integer-1)
|
210 |
answer.save()
|
213 |
answer.save()
|
211 |
ps.score += answer.score
|
214 |
ps.score += answer.score
|
212 |
except Exception as ex:
|
215 |
except Exception as ex:
|
213 |
#I haven't found an answer, nothing to add
|
216 |
#I haven't found an answer, nothing to add
|
214 |
print ex.message
|
|
|
215 |
pass
|
217 |
pass
|
|
|
218 |
self.save()
|
216 |
ps.save()
|
219 |
ps.save()
|
217 |
self.create_graphs(instances)
|
220 |
self.create_graphs(instances)
|
218 |
return ps.score
|
221 |
return ps.score
|
219 |
|
222 |
|
220 |
class Meta:
|
223 |
class Meta:
|
|
... |
|
... |
280 |
str_xml += "<Choices>"
|
283 |
str_xml += "<Choices>"
|
281 |
for choice in self.choice_set.all():
|
284 |
for choice in self.choice_set.all():
|
282 |
str_xml += choice.to_xml()
|
285 |
str_xml += choice.to_xml()
|
283 |
str_xml += "</Choices>"
|
286 |
str_xml += "</Choices>"
|
284 |
return '<Question Id="' + str(self.id) + '" Text="' + self.text + '" Order="' + str(self.order) + '">' + str_xml + '</Question>'
|
287 |
return '<Question Id="' + str(self.id) + '" Text="' + self.text + '" Order="' + str(self.order) + '">' + str_xml + '</Question>'
|
|
|
288 |
|
|
|
289 |
def max_score(self):
|
|
|
290 |
max_score = 0
|
|
|
291 |
for choice in self.choice_set.all():
|
|
|
292 |
if choice.order-1 > max_score:
|
|
|
293 |
max_score = choice.order-1
|
|
|
294 |
return max_score
|
285 |
|
295 |
|
286 |
class Meta:
|
296 |
class Meta:
|
287 |
ordering = ['order']
|
297 |
ordering = ['order']
|
288 |
|
298 |
|
289 |
class Query(models.Model):
|
299 |
class Query(models.Model):
|
|
... |
|
... |
576 |
return '<Answer Id="' + str(self.id) + '" ValueInteger="' + str(self.value_integer) + '">' + str_xml + "</Answer>"
|
586 |
return '<Answer Id="' + str(self.id) + '" ValueInteger="' + str(self.value_integer) + '">' + str_xml + "</Answer>"
|
577 |
|
587 |
|
578 |
class Meta:
|
588 |
class Meta:
|
579 |
unique_together = ('question', 'instance',)
|
589 |
unique_together = ('question', 'instance',)
|
580 |
|
590 |
|
581 |
class Configuration(models.Model):
|
|
|
582 |
default_methodology_version = models.ForeignKey(MethodologyVersion, blank=True, null=True)
|
|
|
583 |
|
|
|
584 |
|
591 |
|
585 |
class UploadedFile(models.Model):
|
592 |
class UploadedFile(models.Model):
|
586 |
'''
|
593 |
'''
|
587 |
Used to save uploaded xml file so that it can be later retrieved and imported
|
594 |
Used to save uploaded xml file so that it can be later retrieved and imported
|
588 |
'''
|
595 |
'''
|