Skip to content

Commit

Permalink
renamed node-recorder to node-sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilcke committed Jun 10, 2012
1 parent d850747 commit cce2f83
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 46 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# node-recorder
# node-sampler

A library which record things and play them back

Expand All @@ -15,6 +15,7 @@

### TODO / Wishlist

* real support of stream/buffer API
* insertion of event at arbitrary timesteps (eg. when working with incomplete time-series)
* reverse playback!

Expand All @@ -28,22 +29,22 @@

#### Install it as a dependency for your project

$ npm install recorder
$ npm install sampler

#### Install it globally in your system

$ npm install recorder -g
$ npm install sampler -g

#### Run the tests

$ npm run-script test

### For developers

To install node-recorder in a development setup:
To install node-sampler in a development setup:

$ git clone http://github.com/daizoru/node-recorder.git
$ cd node-recorder
$ git clone http://github.com/daizoru/node-sampler.git
$ cd node-sampler
$ npm link
$ # optional:
$ # npm run-script test
Expand All @@ -59,36 +60,36 @@

``` coffeescript
# myapp.coffee
Recorder = require 'recorder'
Sampler = require 'sampler'

record = new Recorder()
record.on 'event', (event) -> log "#{event.timestamp}: #{event.data}"
sample = new Sampler()
sample.on 'event', (event) -> log "#{event.timestamp}: #{event.data}"

# coffee-style timeouts
delay = (t,f) -> setTimeout f, t

# record some dummy events
log "recording events.."
delay 100, -> record.rec companyhelpdesk: "hi how can I help you"
delay 500, -> record.rec facebook: "wow! this was a big earthquake"
delay 1000, -> record.rec twitter: "just saw my dead neighbor walking in my street. It's weird. wait I'm gonna check it out"
delay 1500, -> record.rec twitter: "ZOMBIE APOCALYPSE!!1!!"
# sample some dummy events
log "sampling events.."
delay 100, -> sample.rec companyhelpdesk: "hi how can I help you"
delay 500, -> sample.rec facebook: "wow! this was a big earthquake"
delay 1000, -> sample.rec twitter: "just saw my dead neighbor walking in my street. It's weird. wait I'm gonna check it out"
delay 1500, -> sample.rec twitter: "ZOMBIE APOCALYPSE!!1!!"

delay 2000, ->
log "playing events back.."
record.play()
sample.play()

delay 5000, ->
log "playing events back. and faster."
record.play 5.0 # 2.0x
sample.play 5.0 # 2.0x

```

which should output something like:

```
10 Jun 14:57:49 - recording events..
10 Jun 14:57:49 - sampling events..
10 Jun 14:57:51 - playing events back..
10 Jun 14:57:51 - 1339333069383: { companyhelpdesk: 'hi how can I help you' }
10 Jun 14:57:51 - 1339333069783: { facebook: 'wow! this was a big earthquake' }
Expand Down
File renamed without changes.
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@
"email" : "[email protected]",
"url" : "http://github.com/daizoru"
},
"name": "recorder",
"name": "sampler",
"description": "Record things, play them back",
"version": "0.0.0",
"repository": {
"type": "git",
"url": "git://github.com/daizoru/node-recorder.git"
"url": "git://github.com/daizoru/node-sampler.git"
},
"directories" : {
"lib" : "./lib",
"examples" : "./examples",
"test" : "./test"
},
"main" : "./lib/recorder",
"main" : "./lib/sampler",
"scripts" : {
"build" : "coffee --compile --output lib/ src/",
"watch" : "coffee --watch --compile --output lib/ src/",
"pretest" : "coffee --compile --output lib/ src/",
"watch" : "coffee --watch --compile --output lib/ src/",
"test" : "mocha",
"html" : "mocha --reporter doc",
"prestart" : "coffee --compile --output lib/ src/",
"start" : "./bin/hydrant"
"html" : "mocha --reporter doc"
},
"engines": {
"node": "0.6.x || 0.7.x"
Expand Down
File renamed without changes.
65 changes: 45 additions & 20 deletions test/main.coffee
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
Recorder = require '../lib/recorder'
Sampler = require '../lib/sampler'
{log,error,inspect} = require 'util'
delay = (t,f) -> setTimeout f, t

# these are not real tests, it's more like a demo
# more complete tests should check for returned values!!!

# our tests
describe 'Recorder', ->
describe '#new Recorder()', ->
it 'should work', (done) ->

record = new Recorder()
record.on 'event', (event) -> log "#{event.timestamp}: #{inspect event.data}"

# record some dummy events
log "recording events.."
delay 100, -> record.rec companyhelpdesk: "hi how can I help you"
delay 500, -> record.rec facebook: "wow! this was a big earthquake"
delay 1000, -> record.rec twitter: "just saw my dead neighbor walking in my street. It's weird. wait I'm gonna check it out"
delay 1500, -> record.rec twitter: "ZOMBIE APOCALYPSE!!1!!"
describe 'Sampler', ->
describe '#Sampler()', ->
it 'should record', (done) ->
sample = new Sampler()
sample.on 'event', (event) -> log "#{event.timestamp}: #{inspect event.data}"

# sample some dummy events
log "sampling events.."
delay 100, -> sample.rec companyhelpdesk: "hi how can I help you"
delay 500, -> sample.rec facebook: "wow! this was a big earthquake"
delay 1000, -> sample.rec twitter: "just saw my dead neighbor walking in my street. It's weird. wait I'm gonna check it out"
delay 1500, -> sample.rec twitter: "ZOMBIE APOCALYPSE!!1!!"
delay 1600, -> done()

it 'should playback at normal speed', (done) ->
sample = new Sampler()
sample.on 'event', (event) -> log "#{event.timestamp}: #{inspect event.data}"

# sample some dummy events
log "sampling events.."
delay 100, -> sample.rec companyhelpdesk: "hi how can I help you"
delay 500, -> sample.rec facebook: "wow! this was a big earthquake"
delay 1000, -> sample.rec twitter: "just saw my dead neighbor walking in my street. It's weird. wait I'm gonna check it out"
delay 1500, -> sample.rec twitter: "ZOMBIE APOCALYPSE!!1!!"

delay 1600, ->
log "playing events back.."
record.play()
sample.play()
done()

#if (err) throw err

delay 100, ->
log "playing events back. and faster."
record.play 5.0 # 2.0x
done()
it 'should playback faster', (done) ->
sample = new Sampler()
sample.on 'event', (event) -> log "#{event.timestamp}: #{inspect event.data}"

# sample some dummy events
log "sampling events.."
delay 100, -> sample.rec companyhelpdesk: "hi how can I help you"
delay 500, -> sample.rec facebook: "wow! this was a big earthquake"
delay 1000, -> sample.rec twitter: "just saw my dead neighbor walking in my street. It's weird. wait I'm gonna check it out"
delay 1500, -> sample.rec twitter: "ZOMBIE APOCALYPSE!!1!!"

delay 1600, ->
log "playing events faster.."
sample.play 4.0
done()

#if (err) throw err
#if (err) throw err

0 comments on commit cce2f83

Please sign in to comment.