Last active
August 29, 2015 14:19
-
-
Save 7yl4r/646e9c9e45764fd6be0c to your computer and use it in GitHub Desktop.
HBM noflo component base
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment