Commit cb543a65 authored by Janez K's avatar Janez K

streaming visualizations

parent 4cb7a43f
......@@ -18,23 +18,24 @@ urlpatterns = patterns('',
url(r'^', include('signuplogin.urls')),
url(r'^', include('website.urls')),
url(r'^workflows/', include('workflows.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^streams/', include('streams.urls')),
url(r'^admin/', include(admin.site.urls)),
url('^' + LOGIN_URL[1:] + '$', 'django.contrib.auth.views.login', name='login'),
url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout'),
url(r'^change-password/$', 'django.contrib.auth.views.password_change', name='password change'),
url(r'^password-changed/$', 'django.contrib.auth.views.password_change_done', name='password change done'),
url(r'^password_reset/$', 'django.contrib.auth.views.password_reset'),
url(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
url(r'^reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'django.contrib.auth.views.password_reset_confirm'),
url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
)
## debug stuff to serve static media
if DEBUG:
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': STATIC_DOC_ROOT}),
)
\ No newline at end of file
)
......@@ -5,15 +5,24 @@ class Command(NoArgsCommand):
help = 'check for streams that need to be executed and execute them'
option_list = NoArgsCommand.option_list
def handle_noargs(self, **options):
streams = Stream.objects.filter(active=True)
for stream in streams:
#preverimo ce je ze dost casa pretekl
import django
now = django.utils.timezone.now()
delta = now - stream.last_executed
delta_seconds = delta.seconds + delta.days * 86400
if delta_seconds > stream.period or 1==1:
stream.last_executed = now
stream.save()
print stream.execute()
import time
self.stdout.write("Working on streams...")
self.stdout.flush()
while True:
streams = Stream.objects.filter(active=True)
for stream in streams:
#preverimo ce je ze dost casa pretekl
import django
now = django.utils.timezone.now()
delta = now - stream.last_executed
delta_seconds = delta.seconds + delta.days * 86400
if delta_seconds > stream.period:
stream.last_executed = now
stream.save()
#self.stdout.write("-")
#self.stdout.flush()
#print stream.execute()
time.sleep(1)
#self.stdout.write(".")
#self.stdout.flush()
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('',
url(r'^data/(?P<stream_id>[0-9]+)/(?P<widget_id>[0-9]+)/$', 'streams.views.stream_widget_visualization', name='stream widget visualization'),
)
# Create your views here.
# helperji, context stvari
from django.shortcuts import render, get_object_or_404, redirect
from django.http import Http404, HttpResponse
from django.contrib import messages
from django.core import serializers
from django.utils import simplejson
from workflows.urls import *
from workflows.helpers import *
import workflows.interaction_views
import workflows.visualization_views
import sys
import traceback
# modeli
from workflows.models import *
from django.contrib.auth.models import User
from workflows.utils import *
# auth fore
from django.contrib.auth.decorators import login_required
#settings
from mothra.settings import DEBUG, FILES_FOLDER
from streams.models import Stream
import workflows.views
#ostalo
import os
@login_required
def stream_widget_visualization(request,stream_id,widget_id):
stream = get_object_or_404(Stream,pk=stream_id)
widget = get_object_or_404(Widget,pk=widget_id)
if widget.abstract_widget.streaming_visualization_view == '':
return Http404
else:
view_to_call = getattr(workflows.views,widget.abstract_widget.streaming_visualization_view)
return view_to_call(request,widget,stream)
......@@ -5,6 +5,25 @@ Streaming widgets librarby
@author: Janez Kranjc <janez.kranjc@ijs.si>
'''
def streaming_collect_and_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 = StreamWidgetData()
swd.stream = stream
swd.widget = widget
data = []
swd.value = data
swd.save()
swd.value = input_dict['ltw']+swd.value
swd.save()
return {}
def streaming_tweet_sentiment_service(input_dict,widget,stream=None):
import pickle
from pysimplesoap.client import SoapClient, SoapFault
......
<html>
<body>
<table>
<thead>
<td>Text</td>
<td>User</td>
<td>Id</td>
<td>Sentiment</td>
</thead>
<tbody>
{% for tweet in tweets %}
<tr>
<td>{{tweet.text}}</td>
<td>{{tweet.user.screen_name}}</td>
<td>{{tweet.id}}</td>
<td>{{tweet.sentiment}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
# helperji, context stvari
from django.shortcuts import render, get_object_or_404, redirect
from django.http import Http404, HttpResponse
from django.contrib import messages
from django.core import serializers
from django.utils import simplejson
from workflows.urls import *
from workflows.helpers import *
import workflows.interaction_views
import workflows.visualization_views
import sys
import traceback
# modeli
from workflows.models import *
from django.contrib.auth.models import User
from workflows.utils import *
# auth fore
from django.contrib.auth.decorators import login_required
#settings
from mothra.settings import DEBUG, FILES_FOLDER
#ostalo
import os
from streams.models import *
def streaming_collect_and_display_visualization(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()
return render(request, 'streaming_vizualizations/streaming/display_tweets.html', {'tweets':swd.value})
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