Commit 707d31a1 authored by Janez K's avatar Janez K

dodal zoomlevel na sentiment graph

parent 2b9919a3
......@@ -4,13 +4,27 @@
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div class="nav">
</div>
<div id="sentiment-graph" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
<li {% if zoomlevel == "day" %}class="active"{% endif %}><a href="?zoomlevel=day">aggregate by day</a></li>
<li {% if zoomlevel == "hour" %}class="active"{% endif %}><a href="?zoomlevel=hour">aggregate by hour</a></li>
<li {% if zoomlevel == "minute" %}class="active"{% endif %}><a class="active" href="?zoomlevel=minute">aggregate by minute</a></li>
</ul>
</div>
</div>
<script>
$(function () {
$('#sentiment-graph').highcharts({
chart: {
type: 'areaspline'
type: 'areaspline',
zoomType: 'x',
},
title: {
text: '{{stream.workflow}}'
......@@ -34,7 +48,7 @@ $(function () {
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%e. %b', this.x) +': '+ this.y +' tweets';
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +': '+ this.y +' tweets';
}
},
......@@ -43,7 +57,7 @@ $(function () {
type: 'spline',
data: [
{% for tweet in volumes %}
[Date.UTC({{tweet.0|date:"Y"}}, {{tweet.0|date:"n"|add:"-1"}}, {{tweet.0|date:"j"}}), {{tweet.1}} ],
[Date.UTC({{tweet.0|date:"Y"}}, {{tweet.0|date:"n"|add:"-1"}}, {{tweet.0|date:"j"}}{% if zoomlevel == "hour" %}, {{tweet.0|date:"H"}},0{% endif %}{% if zoomlevel == "minute" %}, {{tweet.0|date:"H"}}, {{tweet.0|date:"i"}}{% endif %}), {{tweet.1}} ],
{% endfor %}
]
},{
......@@ -51,7 +65,7 @@ $(function () {
color: '#12aa12',
data: [
{% for tweet in positive %}
[Date.UTC({{tweet.0|date:"Y"}}, {{tweet.0|date:"n"|add:"-1"}}, {{tweet.0|date:"j"}}), {{tweet.1}} ],
[Date.UTC({{tweet.0|date:"Y"}}, {{tweet.0|date:"n"|add:"-1"}}, {{tweet.0|date:"j"}}{% if zoomlevel == "hour" %}, {{tweet.0|date:"H"}},0{% endif %}{% if zoomlevel == "minute" %}, {{tweet.0|date:"H"}}, {{tweet.0|date:"i"}}{% endif %}), {{tweet.1}} ],
{% endfor %}
]
},{
......@@ -59,7 +73,7 @@ $(function () {
color: '#aa1212',
data: [
{% for tweet in negative %}
[Date.UTC({{tweet.0|date:"Y"}}, {{tweet.0|date:"n"|add:"-1"}}, {{tweet.0|date:"j"}}), -{{tweet.1}} ],
[Date.UTC({{tweet.0|date:"Y"}}, {{tweet.0|date:"n"|add:"-1"}}, {{tweet.0|date:"j"}}{% if zoomlevel == "hour" %}, {{tweet.0|date:"H"}},0{% endif %}{% if zoomlevel == "minute" %}, {{tweet.0|date:"H"}}, {{tweet.0|date:"i"}}{% endif %}), -{{tweet.1}} ],
{% endfor %}
]
},{
......@@ -67,7 +81,7 @@ $(function () {
type: 'spline',
data: [
{% for tweet in difference %}
[Date.UTC({{tweet.0|date:"Y"}}, {{tweet.0|date:"n"|add:"-1"}}, {{tweet.0|date:"j"}}), {{tweet.1}} ],
[Date.UTC({{tweet.0|date:"Y"}}, {{tweet.0|date:"n"|add:"-1"}}, {{tweet.0|date:"j"}}{% if zoomlevel == "hour" %}, {{tweet.0|date:"H"}},0{% endif %}{% if zoomlevel == "minute" %}, {{tweet.0|date:"H"}}, {{tweet.0|date:"i"}}{% endif %}), {{tweet.1}} ],
{% endfor %}
]
}]
......
......@@ -84,35 +84,105 @@ def streaming_collect_and_display_visualization(request,widget,stream):
'stream':stream,'paged':tweets})
def streaming_sentiment_graph(request,widget,stream):
tweet_data = StreamWidgetData.objects.filter(widget=widget,stream=stream)
data = [x.value for x in tweet_data]
aggregated_data = {}
positive = {}
negative = {}
difference = {}
for tweet in data:
if aggregated_data.has_key(tweet['created_at'].date()):
aggregated_data[tweet['created_at'].date()] = (tweet['created_at'].date(),aggregated_data[tweet['created_at'].date()][1]+1)
else:
positive[tweet['created_at'].date()] = (tweet['created_at'].date(),0)
negative[tweet['created_at'].date()] = (tweet['created_at'].date(),0)
difference[tweet['created_at'].date()] = (tweet['created_at'].date(),0)
aggregated_data[tweet['created_at'].date()] = (tweet['created_at'].date(),1)
if tweet['reliability'] != -1.0:
if tweet['sentiment'] == "Positive":
positive[tweet['created_at'].date()] = (tweet['created_at'].date(),positive[tweet['created_at'].date()][1]+1)
difference[tweet['created_at'].date()] = (tweet['created_at'].date(),difference[tweet['created_at'].date()][1]+1)
if tweet['sentiment'] == "Negative":
negative[tweet['created_at'].date()] = (tweet['created_at'].date(),negative[tweet['created_at'].date()][1]+1)
difference[tweet['created_at'].date()] = (tweet['created_at'].date(),difference[tweet['created_at'].date()][1]-1)
volumes = aggregated_data.values()
volumes.sort()
positive = positive.values()
positive.sort()
negative = negative.values()
negative.sort()
difference = difference.values()
difference.sort()
zoomlevel = "day"
if request.GET.has_key('zoomlevel'):
zoomlevel = request.GET.get('zoomlevel')
if zoomlevel == "day":
tweet_data = StreamWidgetData.objects.filter(widget=widget,stream=stream)
data = [x.value for x in tweet_data]
aggregated_data = {}
positive = {}
negative = {}
difference = {}
for tweet in data:
if aggregated_data.has_key(tweet['created_at'].date()):
aggregated_data[tweet['created_at'].date()] = (tweet['created_at'].date(),aggregated_data[tweet['created_at'].date()][1]+1)
else:
positive[tweet['created_at'].date()] = (tweet['created_at'].date(),0)
negative[tweet['created_at'].date()] = (tweet['created_at'].date(),0)
difference[tweet['created_at'].date()] = (tweet['created_at'].date(),0)
aggregated_data[tweet['created_at'].date()] = (tweet['created_at'].date(),1)
if tweet['reliability'] != -1.0:
if tweet['sentiment'] == "Positive":
positive[tweet['created_at'].date()] = (tweet['created_at'].date(),positive[tweet['created_at'].date()][1]+1)
difference[tweet['created_at'].date()] = (tweet['created_at'].date(),difference[tweet['created_at'].date()][1]+1)
if tweet['sentiment'] == "Negative":
negative[tweet['created_at'].date()] = (tweet['created_at'].date(),negative[tweet['created_at'].date()][1]+1)
difference[tweet['created_at'].date()] = (tweet['created_at'].date(),difference[tweet['created_at'].date()][1]-1)
volumes = aggregated_data.values()
volumes.sort()
positive = positive.values()
positive.sort()
negative = negative.values()
negative.sort()
difference = difference.values()
difference.sort()
if zoomlevel == "hour":
import datetime
tweet_data = StreamWidgetData.objects.filter(widget=widget,stream=stream)
data = [x.value for x in tweet_data]
aggregated_data = {}
positive = {}
negative = {}
difference = {}
for tweet in data:
d = tweet['created_at']
if aggregated_data.has_key(datetime.datetime(d.year,d.month,d.day,d.hour)):
aggregated_data[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),aggregated_data[datetime.datetime(d.year,d.month,d.day,d.hour)][1]+1)
else:
positive[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),0)
negative[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),0)
difference[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),0)
aggregated_data[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),1)
if tweet['reliability'] != -1.0:
if tweet['sentiment'] == "Positive":
positive[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),positive[datetime.datetime(d.year,d.month,d.day,d.hour)][1]+1)
difference[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),difference[datetime.datetime(d.year,d.month,d.day,d.hour)][1]+1)
if tweet['sentiment'] == "Negative":
negative[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),negative[datetime.datetime(d.year,d.month,d.day,d.hour)][1]+1)
difference[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),difference[datetime.datetime(d.year,d.month,d.day,d.hour)][1]-1)
volumes = aggregated_data.values()
volumes.sort()
positive = positive.values()
positive.sort()
negative = negative.values()
negative.sort()
difference = difference.values()
difference.sort()
if zoomlevel == "minute":
import datetime
tweet_data = StreamWidgetData.objects.filter(widget=widget,stream=stream)
data = [x.value for x in tweet_data]
aggregated_data = {}
positive = {}
negative = {}
difference = {}
for tweet in data:
d = tweet['created_at']
if aggregated_data.has_key(datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)):
aggregated_data[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),aggregated_data[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)][1]+1)
else:
positive[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),0)
negative[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),0)
difference[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),0)
aggregated_data[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),1)
if tweet['reliability'] != -1.0:
if tweet['sentiment'] == "Positive":
positive[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),positive[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)][1]+1)
difference[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),difference[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)][1]+1)
if tweet['sentiment'] == "Negative":
negative[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),negative[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)][1]+1)
difference[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),difference[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)][1]-1)
volumes = aggregated_data.values()
volumes.sort()
positive = positive.values()
positive.sort()
negative = negative.values()
negative.sort()
difference = difference.values()
difference.sort()
return render(request, 'streaming_vizualizations/streaming/sentiment_graph.html',
{'widget':widget,
'stream':stream,
......@@ -121,4 +191,5 @@ def streaming_sentiment_graph(request,widget,stream):
'positive':positive,
'negative':negative,
'difference':difference,
'zoomlevel':zoomlevel,
})
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