Changed tweets, added eca

This commit is contained in:
2022-10-25 12:15:41 +02:00
parent 7597d7648a
commit 9860bee497
71 changed files with 7476 additions and 2036 deletions

39
template.py Normal file
View File

@@ -0,0 +1,39 @@
from eca import *
import random
## 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
fire('sample', {'previous': 0.0})
# define a normal Python function
def clip(lower, value, upper):
return max(lower, min(value, upper))
@event('sample')
def generate_sample(ctx, e):
ctx.count += 1
if ctx.count % 50 == 0:
emit('debug', {'text': 'Log message #'+str(ctx.count)+'!'})
# base sample on previous one
sample = clip(-100, e.data['previous'] + random.uniform(+5.0, -5.0), 100)
# emit to outside world
emit('sample',{
'action': 'add',
'value': sample
})
# chain event
fire('sample', {'previous': sample}, delay=0.05)