T-Res API demo

Create processing function


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)


Validating /home/noes/pyot/pyotapp/media/scripts/halve.py ...
[<Resource: bbbb::200:0:0:4 - /test/push>, <Resource: bbbb::200:0:0:3 - /test/push>] bbbb::200:0:0:2 - /actuator
Pf=halve.py, inputs=[<Resource: bbbb::200:0:0:3 - /test/push>, <Resource: bbbb::200:0:0:4 - /test/push>], output=None
Starting observe on  bbbb::200:0:0:3 - /test/push
Starting observe on  bbbb::200:0:0:4 - /test/push

Get the last output


In [6]:
r = tresTask.getEmuLastOutput()
print r

print tresTask.getEmuResult()


236.5


In [3]:


In [ ]: