Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- noflo = require 'noflo'
- exports.getComponent = ->
- c = new noflo.Component
- c.description = "base human-behavior-model component to build onto"
- c.icon = "question"
- # base in ports which all HBM components should have
- @inPorts =
- average: new noflo.Port 'number'
- variance: new noflo.Port 'number'
- max: new noflo.Port 'number'
- min: new noflo.Port 'number'
- # init values
- @average = 0
- @variance = 1
- @max = 3
- @min = -3
- # setters
- @inPorts.average.on 'data', (@average) =>
- @inPorts.variance.on 'data', (@variance) =>
- @inPorts.max.on 'data', (@max) =>
- @inPorts.min.on 'data', (@min) =>
- # init with an array of average values (to help reolve loops)
- #TODO: randomize this series instead of using avg?
- MAX_LEN = 1000 # max time steps in simulation TODO: how can I better guess this
- @values = (@average for [1..MAX_LEN])
- # function to get value @ t from dependency time-series objects
- @step = (t, dep1, dep2)=>
- return dep1[t] + dep2[t] # TODO: handle out-of-bounds t by wrapping array calls in a function?
- @compute = ()=>
- for t of values
- # compute value for given dependencies
- @values[t] = @step(t, dep1, dep2) # TODO: where to get these dep time-series from? store them on object or are they already on c?
- c.outPorts.out.send values
- # inflows (dependencies)
- c.inPorts.add 'dep1', (event, payload) =>
- if event is 'data'
- @dep1 = payload
- @compute()
- c.inPorts.add 'dep2', (event, payload) =>
- if event is 'data'
- @dep2 = payload
- @compute()
- # array of values
- c.outPorts.add 'out'
- return c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement