-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate.py
More file actions
executable file
·73 lines (60 loc) · 1.57 KB
/
template.py
File metadata and controls
executable file
·73 lines (60 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from eca import *
from eca.generators import start_offline_tweets
import random
import datetime
import textwrap
import pprint
import re
## You might have to update the root path to point to the correct path
## (by default, it points to <rules>_static)
# root_content_path = 'template_static'
# binds the 'setup' function as the action for the 'init' event
# the action will be called with the context and the event
@event('init')
def setup(ctx, e):
ctx.count = 0
start_offline_tweets('data/bata_2014.txt', time_factor=10000000)
def clip(lower, value, upper):
return max(lower, min(value, upper))
positief = []
negatief = ['slecht']
begindata = {'previous':0.0}
pattern = re.compile('\W+')
def words(message):
result = pattern.split(message)
return result
@event('tweet')
def generate_sample(ctx, e):
tweet = e.data
print (ctx.count)
sample = 0
ctx.count += 1
if ctx.count % 50 == 0:
emit('debug', {'text': 'Log message #'+str(ctx.count)+'!'})
# base sample on previous one
try:
print(tweet['text'])
if 'batavierenrace' in tweet['text']:
sample = clip(-100, begindata['previous'] + 0.1, 100)
print (sample)
#elif negatief in tweet['text']:
#sample = clip(-100, begindata['previous'] - 0.1, 100)
#else:
#sample = clip(-100, begindata['previous'], 100)
#print("Error")
except TypeError:
pass
print("Error2")
# emit to outside world
emit('sample',{
'action': 'add',
'value': sample
})
begindata = {'previous':sample}
print (begindata)
#try:
# tweet.pop(0)
#except TypeError:
# pass
# chain event
#fire('tweet', delay=0.05)