Advertisement
Guest User

Untitled

a guest
May 24th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. noflo = require 'noflo'
  2.  
  3. exports.getComponent = ->
  4. c = new noflo.Component
  5. c.description = "base human-behavior-model component to build onto"
  6. c.icon = "question"
  7.  
  8. # base in ports which all HBM components should have
  9. @inPorts =
  10. average: new noflo.Port 'number'
  11. variance: new noflo.Port 'number'
  12. max: new noflo.Port 'number'
  13. min: new noflo.Port 'number'
  14.  
  15. # init values
  16. @average = 0
  17. @variance = 1
  18. @max = 3
  19. @min = -3
  20. # setters
  21. @inPorts.average.on 'data', (@average) =>
  22. @inPorts.variance.on 'data', (@variance) =>
  23. @inPorts.max.on 'data', (@max) =>
  24. @inPorts.min.on 'data', (@min) =>
  25.  
  26. # init with an array of average values (to help reolve loops)
  27. #TODO: randomize this series instead of using avg?
  28. MAX_LEN = 1000 # max time steps in simulation TODO: how can I better guess this
  29. @values = (@average for [1..MAX_LEN])
  30.  
  31. # function to get value @ t from dependency time-series objects
  32. @step = (t, dep1, dep2)=>
  33. return dep1[t] + dep2[t] # TODO: handle out-of-bounds t by wrapping array calls in a function?
  34.  
  35. @compute = ()=>
  36. for t of values
  37. # compute value for given dependencies
  38. @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?
  39.  
  40. c.outPorts.out.send values
  41.  
  42. # inflows (dependencies)
  43. c.inPorts.add 'dep1', (event, payload) =>
  44. if event is 'data'
  45. @dep1 = payload
  46. @compute()
  47.  
  48. c.inPorts.add 'dep2', (event, payload) =>
  49. if event is 'data'
  50. @dep2 = payload
  51. @compute()
  52.  
  53. # array of values
  54. c.outPorts.add 'out'
  55.  
  56. return c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement