Commit 663acc01 authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

Added a widget for displaying various charts for decision support.

parent e33382fb
......@@ -851,19 +851,13 @@ class KepnerTregoe:
self.data = data
self.weights = weights
self.smaller_is_better = smaller_is_better if smaller_is_better else set()
self.name = 'Kepner-Tregoe'
def __call__(self, weights=None):
import Orange
from Orange.feature import Type
if weights == None:
weights = self.weights
# Normalize the weights.
#s = sum([weights[att] for att in weights.keys()])
# Normalize.
#norm_weights = {}
#if s > 0:
# for att in weights.keys():
# norm_weights[att] = float(weights[att])/s
# New normalized table
# New augmented table
norm_data = Orange.data.Table(self.data)
newid = min(norm_data.domain.get_metas().keys()) - 1
score_attr = Orange.feature.Continuous('score')
......@@ -905,5 +899,8 @@ def kepner_tregoe_finished(postdata, input_dict, output_dict):
def sensitivity_analysis(input_dict):
return input_dict
def ds_charts(input_dict):
return input_dict
def string_to_file(input_dict):
return {}
......@@ -62,7 +62,6 @@
"bSort" : false,
"bFilter" : false
});
// Normalization code.
$("#normalizeButton{{widget.pk}}").button().click(function() {
var weight_elements = $('[id^="weight{{widget.pk}}"]');
......@@ -78,7 +77,6 @@
});
}
});
// Reset button code.
$("#resetButton{{widget.pk}}").button().click(function() {
$('[id^="weight{{widget.pk}}"]').each(function() {
......
<div id="widgetvisualization-{{widget.pk}}" rel="{{widget.pk}}" class="widgetvisualizationdialog" title="{{widget.name}} visualization" width="700px" height="670px">
<div style="width:620px; margin: 0 auto;">
Input model: {{ model_name }}<br><br>
<form>
<div id="weight_charts_tabs" style="margin-bottom: 10px;">
<ul>
<li><a href="#weights-1">Weights pie chart</a></li>
<li><a href="#weights-2">Weights bar chart</a></li>
</ul>
<div id="weights-1"></div>
<div id="weights-2"></div>
</div>
<div id="alt_charts_tabs" style="margin-bottom: 10px;">
<ul>
<li><a href="#alts-1">Alternatives column chart</a></li>
<li><a href="#alts-2">Attribute values chart</a></li>
</ul>
<div id="alts-1"></div>
<div id="alts-2"></div>
</div>
<input type="hidden" name="widget_id" value="{{widget.pk}}"/>
</form>
<script type="text/javascript">
$(function () {
// Pretty radio buttons.
$("#weight_charts_tabs").tabs({
collapsible: true
});
$("#alt_charts_tabs").tabs({
collapsible: true,
selected: -1
});
$(document).ready(function(){
plot();
});
// Handles radio button selection events.
$("form input[class=target_att]").change(function () {
var target_att = $("form input[class=target_att]:checked").val();
plot(target_att);
});
// Plots for the selected attribute.
function plot() {
// Weights barchart
new Highcharts.Chart({
chart: {
renderTo: 'weights-1',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Weights',
x: -20 //center
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'Weights',
data: {{ weight_shares|safe }}
}],
credits: {
enabled: false
},
});
// Weights bar chart
new Highcharts.Chart({
chart: {
renderTo: 'weights-2',
type: 'bar'
},
title: {
text: 'Weights',
x: -20 //center
},
xAxis: {
categories: {{ attributes|safe }},
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Weight'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
formatter: function() {
return ''+
this.series.name +': '+ this.y + '%';
}
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
credits: {
enabled: false
},
series: {{ weights_bar|safe }},
legend: {
enabled: false
}
});
// Alternatives column chart
new Highcharts.Chart({
chart: {
renderTo: 'alts-1',
type: 'column'
},
title: {
text: 'Scores',
x: -20 //center
},
xAxis: {
categories: {{ alternatives|safe }},
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Score'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
formatter: function() {
return ''+
this.series.name +': '+ this.y;
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
credits: {
enabled: false
},
series: {{ values_column|safe }},
legend: {
enabled: false
}
});
// Attribute values chart
new Highcharts.Chart({
chart: {
renderTo: 'alts-2',
type: 'bar'
},
title: {
text: 'Values',
x: -20 //center
},
xAxis: {
categories: {{ attributes|safe }},
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Value'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
formatter: function() {
return ''+
this.series.name +': '+ this.y ;
}
},
credits: {
enabled: false
},
series: {{ alt_data|safe }},
});
}
});
</script>
</div>
</div>
\ No newline at end of file
......@@ -4,7 +4,7 @@ Select the attribute to perform sensitivity analysis on.<br><br>
<form>
<div id="radio" style="margin-bottom: 10px; text-align: center;">
{% for att in attributes %}
<input type="radio" class="target_att" name="target{{widget.pk}}" id="target{{widget.pk}}{{att}}" value="{{att}}" {% if forloop.first %}checked="checked"{% endif %}> <label for="target{{widget.pk}}{{att}}">{{att}}</label>
<input type="radio" class="target_att" name="target{{widget.pk}}" id="target{{widget.pk}}{{att}}" value="{{att}}" {% if forloop.first %}checked="checked"{% endif %}> <label for="target{{widget.pk}}{{att}}">{{att}}</label></input>
{% endfor %}
</div>
<input type="hidden" name="widget_id" value="{{widget.pk}}"/>
......@@ -75,7 +75,10 @@ $(function () {
y: 100,
borderWidth: 0
},
series: data_points[target_att]
series: data_points[target_att],
credits: {
enabled: false
},
});
}
});
......
......@@ -258,3 +258,23 @@ def sensitivity_analysis_viewer(request, input_dict, output_dict, widget):
'data_points' : json.dumps(data_points),
'output_dict': {}
})
def ds_charts_viewer(request, input_dict, output_dict, widget):
model = input_dict['model']
norm_data = model()
weight_shares = [ [att, weight] for att, weight in model.weights.items() ]
attributes = sorted(model.weights.keys())
alternatives = [ex['label'].value for ex in norm_data]
weights_bar = [{ 'data' : [model.weights[att] for att in attributes] }]
values_column = [{ 'data' : [ex['score'].value for ex in norm_data] }]
alt_data = [{ 'name' : ex['label'].value, 'data' : [ex[att].value for att in attributes] } for ex in norm_data ]
return render(request, 'visualizations/ds_charts.html',
{'widget' : widget,
'model_name' : model.name,
'attributes' : json.dumps(attributes),
'alternatives' : json.dumps(alternatives),
'weight_shares' : json.dumps(weight_shares),
'weights_bar' : json.dumps(weights_bar),
'values_column' : json.dumps(values_column),
'alt_data' : json.dumps(alt_data)
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment