Commit 3c576f75 authored by Janez K's avatar Janez K

sliding window

parent 36f06827
......@@ -24,4 +24,5 @@ mothra-env/
build/
# SQLite
/mothra/mothra.db
\ No newline at end of file
/mothra/mothra.db
/mothra/mothra.db-journal
......@@ -24,7 +24,6 @@
}
</style>
<link href="{{STATIC_URL}}bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Condiment' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="{{STATIC_URL}}bootstrap/js/bootstrap.js"></script>
......@@ -56,7 +55,6 @@
<body>
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
......@@ -71,7 +69,7 @@
<ul class="nav pull-right">
<li {% block "homeactive" %}{% endblock %}><a href="{% url 'website index' %}">Home</a></li>
<li {% block "workflowactive" %}{% endblock %}><a href="{% url 'the index' %}" class="{% if not user.is_authenticated %}must_login{% endif %}">Start working</a></li>
<li {% block "workflowactive" %}{% endblock %}><a href="{% url 'the index' %}" class="{% if not user.is_authenticated %}must_login{% endif %}">Workflow editor</a></li>
<li {% block "exploreactive" %}{% endblock %}><a href="{% url 'existing workflows' %}">Explore workflows</a></li>
<li><a class="{% if not user.is_authenticated %}must_login{% endif %}" href="{% if user.is_authenticated %}{% url 'logout' %}{% endif %}{% if not user.is_authenticated %}{% url 'website index' %}{% endif %}">{% if not user.is_authenticated %}Log in{% endif %}{% if user.is_authenticated %}Log out{% endif %}</a></li>
</ul>
......@@ -81,6 +79,8 @@
</div>
{% block "website" %}
<div class="container">
{% block "streamnav" %}
......@@ -147,5 +147,8 @@
<div style="position:absolute;top:50%;left:50%;display:none;z-index:20;" class="ajax-loader">
<img src="{{STATIC_URL}}images/ajax-loader-big.gif">
</div>
{% endblock %}
</body>
</html>
......@@ -5,23 +5,33 @@ Streaming widgets librarby
@author: Janez Kranjc <janez.kranjc@ijs.si>
'''
def streaming_collect_and_display_tweets(input_dict,widget,stream=None):
def streaming_display_tweets(input_dict,widget,stream=None):
from streams.models import StreamWidgetData
if stream is None:
return {}
else:
try:
swd = StreamWidgetData.objects.get(stream=stream,widget=widget)
data = swd.value
except Exception as e:
swd.value = input_dict['ltw']
swd.save()
except:
swd = StreamWidgetData()
swd.stream = stream
swd.widget = widget
data = []
data = input_dict['ltw']
swd.value = data
swd.save()
swd.value = input_dict['ltw']+swd.value
swd.save()
return {}
def streaming_collect_and_display_tweets(input_dict,widget,stream=None):
from streams.models import StreamWidgetData
if stream is None:
return {}
else:
new_tweets = []
for tweet in input_dict['ltw']:
new_tweets.append(StreamWidgetData(stream=stream,widget=widget,value=tweet))
StreamWidgetData.objects.bulk_create(new_tweets)
return {}
def streaming_sentiment_graph(input_dict,widget,stream=None):
......@@ -29,18 +39,10 @@ def streaming_sentiment_graph(input_dict,widget,stream=None):
if stream is None:
return {}
else:
try:
swd = StreamWidgetData.objects.get(stream=stream,widget=widget)
data = swd.value
except Exception as e:
swd = StreamWidgetData()
swd.stream = stream
swd.widget = widget
data = []
swd.value = data
swd.save()
swd.value = input_dict['ltw']+swd.value
swd.save()
new_tweets = []
for tweet in input_dict['ltw']:
new_tweets.append(StreamWidgetData(stream=stream,widget=widget,value=tweet))
StreamWidgetData.objects.bulk_create(new_tweets)
return {}
def streaming_tweet_sentiment_service(input_dict,widget,stream=None):
......@@ -196,3 +198,32 @@ def streaming_rss_reader(input_dict,widget,stream=None):
from streams.models import HaltStream
raise HaltStream("Halting stream.")
return output_dict
def streaming_sliding_window(input_dict,widget,stream=None):
from streams.models import StreamWidgetData
output_dict = {}
if stream is None:
output_dict['list']=input_dict['list'][:int(input_dict['size'])]
else:
try:
swd = StreamWidgetData.objects.get(stream=stream,widget=widget)
data = swd.value
except:
swd = StreamWidgetData()
swd.stream = stream
swd.widget = widget
data = []
swd.value = data
swd.save()
size = int(input_dict['size'])
if len(input_dict['list'])>=size:
output_dict['list']=input_dict['list'][:size]
swd.value=output_dict['list']
swd.save()
else:
current_window = input_dict['list'] + swd.value
swd.value = current_window[:size]
output_dict['list']=current_window[:size]
swd.save()
return output_dict
{% extends "streams/base.html" %}
{% block 'container' %}
{% load paginator %}
<h1>Tweets</h1>
<div class="row">
<div class="span12">
{% paginator 3 %}
</div>
</div>
<table class="table table-striped table-bordered">
<thead>
<tr>
......@@ -25,4 +34,11 @@
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="span12">
{% paginator 3 %}
</div>
</div>
{% endblock %}
......@@ -28,31 +28,70 @@ import os
from streams.models import *
import operator
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
def streaming_tweet_cloud(request,widget,stream):
try:
tweet_data = StreamWidgetData.objects.get(widget=widget,stream=stream).value
except:
tweet_data = []
tweets_unsorted = tweet_data
tweets = sorted(tweets_unsorted, key=operator.itemgetter('created_at'))
tweets.reverse()
paginator = Paginator(tweets,20)
page=request.GET.get('page')
try:
tweets = paginator.page(page)
except PageNotAnInteger:
tweets = paginator.page(1)
except EmptyPage:
tweets = paginator.page(paginator.num_pages)
return render(request, 'streaming_vizualizations/streaming/display_tweets.html', {'tweets':tweets,'widget':widget,
'stream':stream,'paged':tweets})
def streaming_display_tweets_visualization(request,widget,stream):
try:
tweet_data = StreamWidgetData.objects.get(widget=widget,stream=stream).value
except:
tweet_data = []
tweets_unsorted = tweet_data
tweets = sorted(tweets_unsorted, key=operator.itemgetter('created_at'))
tweets.reverse()
paginator = Paginator(tweets,20)
page=request.GET.get('page')
try:
tweets = paginator.page(page)
except PageNotAnInteger:
tweets = paginator.page(1)
except EmptyPage:
tweets = paginator.page(paginator.num_pages)
return render(request, 'streaming_vizualizations/streaming/display_tweets.html', {'tweets':tweets,'widget':widget,
'stream':stream,'paged':tweets})
def streaming_collect_and_display_visualization(request,widget,stream):
tweet_data = StreamWidgetData.objects.filter(widget=widget,stream=stream)
tweets_unsorted = [x.value for x in tweet_data]
tweets = sorted(tweets_unsorted, key=operator.itemgetter('created_at'))
tweets.reverse()
paginator = Paginator(tweets,20)
page=request.GET.get('page')
try:
swd = StreamWidgetData.objects.get(stream=stream,widget=widget)
data = swd.value
except Exception as e:
swd = StreamWidgetData()
swd.stream = stream
swd.widget = widget
data = []
swd.value = data
swd.save()
return render(request, 'streaming_vizualizations/streaming/display_tweets.html', {'tweets':swd.value,'widget':widget,
'stream':stream})
tweets = paginator.page(page)
except PageNotAnInteger:
tweets = paginator.page(1)
except EmptyPage:
tweets = paginator.page(paginator.num_pages)
return render(request, 'streaming_vizualizations/streaming/display_tweets.html', {'tweets':tweets,'widget':widget,
'stream':stream,'paged':tweets})
def streaming_sentiment_graph(request,widget,stream):
try:
swd = StreamWidgetData.objects.get(stream=stream,widget=widget)
data = swd.value
except Exception as e:
swd = StreamWidgetData()
swd.stream = stream
swd.widget = widget
data = []
swd.value = data
swd.save()
tweet_data = StreamWidgetData.objects.filter(widget=widget,stream=stream)
data = [x.value for x in tweet_data]
aggregated_data = {}
positive = {}
negative = {}
......@@ -83,7 +122,7 @@ def streaming_sentiment_graph(request,widget,stream):
return render(request, 'streaming_vizualizations/streaming/sentiment_graph.html',
{'widget':widget,
'stream':stream,
'tweets':swd.value,
'tweets':data,
'volumes':volumes,
'positive':positive,
'negative':negative,
......
<div class="dataTables_paginate paging_bootstrap pagination">
<ul>
{% if has_previous %}
<li class="prev"><a href="?page={{previous}}"></a></li>
{% else %}
<li class="prev disabled"><a href="javascript:;"></a></li>
{% endif %}
{% if show_first %}
<li><a href="?page=1">1</a></li>
<li><a>...</a></li>
{% endif %}
{% for linkpage in page_numbers %}
{% ifequal linkpage page %}
<li class="active"><a href="?page={{linkpage}}">{{linkpage}}</a></li>
{% else %}
<li><a href="?page={{ linkpage }}">{{ linkpage }}</a></li>
{% endifequal %}
{% endfor %}
{% if show_last %}
<li><a>...</a></li>
<li><a href="?page={{last}}">{{last}}</a></li>
{% endif %}
{% if has_next %}
<li class="next"><a href="?page={{next}}"></a></li>
{% else %}
<li class="next disabled"><a href="javascript:;"></a></li>
{% endif %}
</ul>
</div>
\ No newline at end of file
......@@ -44,6 +44,7 @@
<script type="text/javascript" src="{{ STATIC_URL }}js/tipsy.js"></script>
<!-- <script src="{{STATIC_URL}}js/d3/d3.js"></script>
<script src="{{STATIC_URL}}js/d3/d3.layout.js"></script> -->
<script type="text/javascript">
{% load url from future %}
......
from django import template
register = template.Library()
def paginator(context, adjacent_pages=2):
"""
To be used in conjunction with the object_list generic view.
Adds pagination context variables for use in displaying first, adjacent and
last page links in addition to those created by the object_list generic
view.
Required context variables: paged: The Paginator.page() instance.
"""
paged = context['paged'] # the paginator.page(page) instance
paginator = paged.paginator
startPage = max(paged.number - adjacent_pages, 1)
if startPage <= 3: startPage = 1
endPage = paged.number + adjacent_pages + 1
if endPage >= paginator.num_pages - 1: endPage = paginator.num_pages + 1
page_numbers = [n for n in range(startPage, endPage) \
if n > 0 and n <= paginator.num_pages]
return {
'paged': paged,
'paginator': paginator,
'page': paged.number,
'pages': paginator.num_pages,
'page_numbers': page_numbers,
'next': paged.next_page_number(),
'previous': paged.previous_page_number(),
'has_next': paged.has_next(),
'has_previous': paged.has_previous(),
'show_first': 1 not in page_numbers,
'show_last': paginator.num_pages not in page_numbers,
'last':paginator.num_pages,
}
register.inclusion_tag('include/paginator.html', takes_context=True)(paginator)
"""
Example template:
<div class="pager">
{% if has_previous %}
<span class="page">
<a href="?page={{ previous }}">&lt; Prev</a>
</span>
{% endif %}
{% if show_first %}
<span class="page"><a href="?page=1">1</a></span>
<span class="ellipsis">...</span>
{% endif %}
{% for linkpage in page_numbers %}
{% ifequal linkpage page %}
<span class="current">{{ page }}</span>
{% else %}
<span class="page"><a href="?page={{ linkpage }}"
>{{ linkpage }}</a></span>
{% endifequal %}
{% endfor %}
{% if show_last %}
<span class="ellipsis">...</span>
<span class="page"><a href="?page=last">{{ pages }}</a></span>
{% endif %}
{% if has_next %}
<span class="page"><a href="?page={{ next }}">Next &gt;</a></span>
{% endif %}
</div>
"""
\ No newline at end of file
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