|
a/OSSEval/analysis/models.py |
|
b/OSSEval/analysis/models.py |
|
... |
|
... |
51 |
def to_xml(self):
|
51 |
def to_xml(self):
|
52 |
str_xml = "<Description><![CDATA[" + self.description + "]]></Description>"
|
52 |
str_xml = "<Description><![CDATA[" + self.description + "]]></Description>"
|
53 |
str_xml += "<Documentation><![CDATA[" + self.documentation + "]]></Documentation>"
|
53 |
str_xml += "<Documentation><![CDATA[" + self.documentation + "]]></Documentation>"
|
54 |
str_xml += self.entity.to_xml()
|
54 |
str_xml += self.entity.to_xml()
|
55 |
return '<Methodology Id="' + str(self.id) + '" Name="' + self.name + '" Active="' + str(self.active) + '">' + str_xml + "</Methodology>"
|
55 |
return '<Methodology Id="' + str(self.id) + '" Name="' + self.name + '" Active="' + str(self.active) + '">' + str_xml + "</Methodology>"
|
|
|
56 |
|
56 |
|
57 |
|
57 |
class HasPages(models.Model):
|
58 |
class HasPages(models.Model):
|
58 |
bar_chart = models.TextField(blank=True)
|
59 |
def bar_chart(self, weight_profile_id):
|
|
|
60 |
weight_scenario = WeightScenario.objects.get(pk=weight_profile_id)
|
|
|
61 |
if self.__class__.__name__ == "Page":
|
|
|
62 |
g = Graphs.objects.get(page = self, weight_scenario=weight_scenario)
|
|
|
63 |
else:
|
|
|
64 |
g = Graphs.objects.get(methodology_version=self, weight_scenario=weight_scenario)
|
|
|
65 |
return g.bar_chart
|
|
|
66 |
|
|
|
67 |
def radar_chart(self, weight_profile_id):
|
|
|
68 |
weight_scenario = WeightScenario.objects.get(pk=weight_profile_id)
|
|
|
69 |
if self.__class__.__name__ == "Page":
|
|
|
70 |
g = Graphs.objects.get(page = self, weight_scenario=weight_scenario)
|
|
|
71 |
else:
|
|
|
72 |
g = Graphs.objects.get(methodology_version=self, weight_scenario=weight_scenario)
|
|
|
73 |
return g.radar_chart
|
|
|
74 |
|
59 |
radar_chart = models.TextField(blank=True)
|
75 |
# radar_chart = models.TextField(blank=True)
|
60 |
def create_graphs(self, instances, include_max = True):
|
76 |
def create_graphs(self, instances, weight_scenario, include_max = True):
|
61 |
# I draw the graphs for the report
|
77 |
# I draw the graphs for the report
|
62 |
#styles = [NeonStyle, DarkSolarizedStyle, LightSolarizedStyle, LightStyle, CleanStyle, RedBlueStyle, DarkColorizedStyle, LightColorizedStyle, TurquoiseStyle, LightGreenStyle, DarkGreenStyle, DarkGreenBlueStyle, BlueStyle]
|
78 |
#styles = [NeonStyle, DarkSolarizedStyle, LightSolarizedStyle, LightStyle, CleanStyle, RedBlueStyle, DarkColorizedStyle, LightColorizedStyle, TurquoiseStyle, LightGreenStyle, DarkGreenStyle, DarkGreenBlueStyle, BlueStyle]
|
63 |
#style=styles[randrange(len(styles))]
|
79 |
#style=styles[randrange(len(styles))]
|
64 |
style=LightColorizedStyle
|
80 |
style=LightColorizedStyle
|
65 |
bar_chart = Bar(width=300, height=400, explicit_size=True, rounded_bars=5, disable_xml_declaration=True, style=style)
|
81 |
bar_chart = Bar(width=300, height=400, explicit_size=True, rounded_bars=5, disable_xml_declaration=True, style=style)
|
66 |
radar_chart = Radar(width=400, height=400, explicit_size=True, legend_at_bottom=True, disable_xml_declaration=True, style=style)
|
82 |
radar_chart = Radar(width=400, height=400, explicit_size=True, legend_at_bottom=True, disable_xml_declaration=True, style=style)
|
|
|
83 |
|
67 |
if self.__class__.__name__ == "Page":
|
84 |
if self.__class__.__name__ == "Page":
|
68 |
radar_chart.title = self.name
|
85 |
radar_chart.title = self.name
|
|
|
86 |
try:
|
|
|
87 |
g = Graphs.objects.get(page = self, weight_scenario=weight_scenario)
|
|
|
88 |
g.delete()
|
|
|
89 |
except:
|
|
|
90 |
pass
|
69 |
else:
|
91 |
else:
|
70 |
radar_chart.title = 'Summary graph'
|
92 |
radar_chart.title = 'Summary graph'
|
|
|
93 |
try:
|
|
|
94 |
g = Graphs.objects.get(methodology_version=self, weight_scenario=weight_scenario)
|
|
|
95 |
g.delete()
|
|
|
96 |
except:
|
|
|
97 |
pass
|
71 |
radar_chart.x_labels = []
|
98 |
radar_chart.x_labels = []
|
72 |
instance_scores = {}
|
99 |
instance_scores = {}
|
73 |
for instance in instances:
|
100 |
for instance in instances:
|
74 |
instance_scores[instance.id] = []
|
101 |
instance_scores[instance.id] = []
|
75 |
if include_max:
|
102 |
if include_max:
|
|
... |
|
... |
90 |
radar_chart.add(instance.name, instance_scores[instance.id])
|
117 |
radar_chart.add(instance.name, instance_scores[instance.id])
|
91 |
bar_chart.add(instance.name, sum(instance_scores[instance.id]))
|
118 |
bar_chart.add(instance.name, sum(instance_scores[instance.id]))
|
92 |
if include_max:
|
119 |
if include_max:
|
93 |
radar_chart.add("MAX", instance_scores[0])
|
120 |
radar_chart.add("MAX", instance_scores[0])
|
94 |
bar_chart.add("MAX", sum(instance_scores[0]))
|
121 |
bar_chart.add("MAX", sum(instance_scores[0]))
|
|
|
122 |
g = Graphs()
|
|
|
123 |
g.radar_chart = radar_chart.render()
|
|
|
124 |
g.bar_chart = bar_chart.render()
|
|
|
125 |
if self.__class__.__name__ == 'Page':
|
|
|
126 |
g.page = self
|
|
|
127 |
else:
|
|
|
128 |
g.methodology_version = self
|
|
|
129 |
g.weight_scenario = weight_scenario
|
|
|
130 |
g.save()
|
|
|
131 |
|
95 |
self.radar_chart = radar_chart.render()
|
132 |
# self.radar_chart = radar_chart.render()
|
96 |
self.bar_chart = bar_chart.render()
|
133 |
# self.bar_chart = bar_chart.render()
|
97 |
self.save()
|
134 |
# self.save()
|
98 |
class Meta:
|
135 |
class Meta:
|
99 |
abstract = True
|
136 |
abstract = True
|
100 |
|
137 |
|
101 |
class MethodologyVersion(HasPages):
|
138 |
class MethodologyVersion(HasPages):
|
102 |
number = models.IntegerField()
|
139 |
number = models.IntegerField()
|
|
... |
|
... |
230 |
except Exception as ex:
|
267 |
except Exception as ex:
|
231 |
#I haven't found an answer, nothing to add
|
268 |
#I haven't found an answer, nothing to add
|
232 |
pass
|
269 |
pass
|
233 |
self.save()
|
270 |
self.save()
|
234 |
ps.save()
|
271 |
ps.save()
|
235 |
self.create_graphs(instances)
|
272 |
self.create_graphs(instances, weight_scenario)
|
236 |
return ps.score
|
273 |
return ps.score
|
237 |
|
274 |
|
238 |
class Meta:
|
275 |
class Meta:
|
239 |
ordering = ['order']
|
276 |
ordering = ['order']
|
240 |
|
277 |
|
|
... |
|
... |
399 |
str_xml += "</Weights>"
|
436 |
str_xml += "</Weights>"
|
400 |
return '<WeightScenario Id="' + str(self.id) + '" Name="' + self.name + '" Active="' + str(self.active) + '">' + str_xml + '</WeightScenario>'
|
437 |
return '<WeightScenario Id="' + str(self.id) + '" Name="' + self.name + '" Active="' + str(self.active) + '">' + str_xml + '</WeightScenario>'
|
401 |
|
438 |
|
402 |
def __str__(self):
|
439 |
def __str__(self):
|
403 |
return self.name
|
440 |
return self.name
|
|
|
441 |
|
|
|
442 |
|
|
|
443 |
class Graphs(models.Model):
|
|
|
444 |
bar_chart = models.TextField(blank=True)
|
|
|
445 |
radar_chart = models.TextField(blank=True)
|
|
|
446 |
page = models.ForeignKey(Page,null=True,blank=True)
|
|
|
447 |
methodology_version = models.ForeignKey(MethodologyVersion,null=True,blank=True)
|
|
|
448 |
weight_scenario = models.ForeignKey(WeightScenario)
|
404 |
|
449 |
|
405 |
class Weight(models.Model):
|
450 |
class Weight(models.Model):
|
406 |
question = models.ForeignKey(Question)
|
451 |
question = models.ForeignKey(Question)
|
407 |
weight = models.FloatField()
|
452 |
weight = models.FloatField()
|
408 |
scenario = models.ForeignKey(WeightScenario)
|
453 |
scenario = models.ForeignKey(WeightScenario)
|
|
... |
|
... |
463 |
#then I add its score to the corresponding page
|
508 |
#then I add its score to the corresponding page
|
464 |
#loop on top level pages and recursive calculation on child pages
|
509 |
#loop on top level pages and recursive calculation on child pages
|
465 |
for page in self.methodology_version.page_set.all():
|
510 |
for page in self.methodology_version.page_set.all():
|
466 |
for instance in self.instance_set.all():
|
511 |
for instance in self.instance_set.all():
|
467 |
page.calculate_scores(instance, weight_scenario, self.instance_set.all())
|
512 |
page.calculate_scores(instance, weight_scenario, self.instance_set.all())
|
468 |
self.methodology_version.create_graphs(self.instance_set.all())
|
513 |
self.methodology_version.create_graphs(self.instance_set.all(), weight_scenario)
|
469 |
return weight_scenario
|
514 |
return weight_scenario
|
470 |
|
|
|
471 |
# @staticmethod
|
|
|
472 |
# def create_graphs(object, pages, instances):
|
|
|
473 |
'''
|
|
|
474 |
a static method because I need to create the same
|
|
|
475 |
'''
|
|
|
476 |
|
515 |
|
477 |
def from_xml(self, xmldoc, insert = True):
|
516 |
def from_xml(self, xmldoc, insert = True):
|
478 |
'''
|
517 |
'''
|
479 |
All but the MethodologyVersion so that we can independently import from xml
|
518 |
All but the MethodologyVersion so that we can independently import from xml
|
480 |
MethodologyVersion and Analysis
|
519 |
MethodologyVersion and Analysis
|
|
... |
|
... |
605 |
class UploadedFile(models.Model):
|
644 |
class UploadedFile(models.Model):
|
606 |
'''
|
645 |
'''
|
607 |
Used to save uploaded xml file so that it can be later retrieved and imported
|
646 |
Used to save uploaded xml file so that it can be later retrieved and imported
|
608 |
'''
|
647 |
'''
|
609 |
docfile = models.FileField(upload_to='documents/%Y/%m/%d')
|
648 |
docfile = models.FileField(upload_to='documents/%Y/%m/%d')
|
|
|
649 |
|
|
|
650 |
|