In [1]:
import os
from pyot.models.tres import *
from pyot.tres.tresApp import *
test= """
from tres_pymite import *
print 'testing state'
class state:
def __init__(self):
self.s1 = -1
self.s2 = -1
s = getState(state)
print s.s1, s.s2
print 'saving new state'
s.s1 += 1
s.s2 += 2
saveState(s)
'print testing getIntInput/pop/push'
b = pop(0)
print 'popped', b
a = getIntInput()
f = getFloatInput()
print 'int input = ', a
print 'float input = ', f
push(a+3)
setOutput(a)
print 'end'
"""
ema = """
from tres_pymite import *
class state:
def __init__(self):
self.m = 0.0
print "Exponential Moving Average:",
s = getState(state)
x = getFloatInput()
s.m = 0.1 * x + 0.9 * s.m
print s.m
setOutput(s.m)
saveState(s)
"""
halve = """
from tres_pymite import *
print "Halve:",
i = getIntInput()
print i/2.
setOutput(i/2.)
"""
t1 = TResPF.fromSource(halve, 'halve')
rin = Resource.objects.filter(uri='/test/push', host__active=True)
rout = Resource.objects.filter(uri='/actuator', host__active=True)[0]
print rin, rout
tresTask = TResTask(TresPf=t1, inputS=rin)
print tresTask
tresTask.emulate(duration=40)
In [6]:
r = tresTask.getEmuLastOutput()
print r
print tresTask.getEmuResult()
In [3]:
In [ ]: