Skip to content
Browse files

one feed to find them

  • Loading branch information...
1 parent d5adeb7 commit 680db320fae34d26bdf088d05a2c07bfd9e76f13 @jedahan jedahan committed Sep 9, 2011
Showing with 18 additions and 20 deletions.
  1. +6 −0 config.json
  2. +4 −11 src/faker.coffee
  3. +8 −9 src/public/scripts/lepidoptera.coffee
View
6 config.json
@@ -5,4 +5,10 @@
, "consumer_key": "580a128c2014eccc9b9a69dae9a4a3bb3d487200"
, "swarms": [ "a88adedd607c166d04cab6680b18e669c080473f" ]
, "producer_name" : "faker"
+, "feeds": [
+ { "name": "mpg", "max": 70 }
+ , { "name": "rpm", "max": 10000 }
+ , { "name": "change", "max": 10 }
+ , { "name": "rank", "max": 50 }
+ ]
}
View
15 src/faker.coffee
@@ -16,7 +16,6 @@ buglabs = { latitude: 40.72498216901785, longitude: -73.99708271026611 }
max_distance = .01
center_latitude = (buglabs.latitude - max_distance / 2)
center_longitude = (buglabs.longitude - max_distance / 2)
-max = { mpg: 70, rpm: 10000, change: 10, rank: 50 }
cars = [ { name: "Fiesta", count: 0 }, { name: "Fusion", count: 0 } ]
reqs = []
@@ -40,17 +39,10 @@ app.get '/:feed/:swarm_id', (req, res) ->
#
# Currently, it looks like
#
-# `PUT /resources/:producer_name/feeds/mpg?swarm_id=:swarm_id`
+# `{ latitude: -25.1, longitude: 40.1, mpg: 42, rpm: 2600, ... }`
#
-# `{ latitude: -25.1, longitude: 40.1, mpg: 42 }`
-#
-# If you want to push other data, make sure the feed name and data field is the same, eg:
-#
-# `PUT /resources/:producer_name/feeds/RPM?swarm_id=:swarm_id`
-#
-# `{ latitude: -25.1, longitude: 40.1, RPM: 2600 }`
-fakeData = (feed_name="mpg", swarm_id=config.swarms[Math.floor(Math.random() * config.swarms.length)]) ->
+fakeData = (feed_name="ford", swarm_id=config.swarms[Math.floor(Math.random() * config.swarms.length)]) ->
if config.swarms.indexOf(swarm_id) > -1
options =
host: config.host
@@ -68,7 +60,8 @@ fakeData = (feed_name="mpg", swarm_id=config.swarms[Math.floor(Math.random() * c
car_name: car_name
latitude: center_latitude + Math.random() * max_distance
longitude: center_longitude + Math.random() * max_distance
- feed["#{feed_name}"] = Math.floor(Math.random() * max["#{feed_name}"])
+ for feeder in config.feeds
+ feed[feeder.name] = Math.floor(Math.random() * feeder.max)
req.write JSON.stringify feed
, 5000
req.write '\n'
View
17 src/public/scripts/lepidoptera.coffee
@@ -12,7 +12,6 @@ lepidoptera = ->
mapOptions = zoom: 12, center: new google.maps.LatLng(40.72498216901785, -73.99708271026611) , mapTypeId: google.maps.MapTypeId.ROADMAP
mapCanvas = document.getElementById "map_canvas"
mapGoogle = new google.maps.Map mapCanvas, mapOptions
-
markers = []
# the javascript api handles message callbacks as a consumer only
@@ -44,22 +43,22 @@ lepidoptera = ->
dom_resource.toggleClass 'alive', alive
updateFeed = (resource_id, body) ->
- feed = body.feed
data = JSON.parse body.data
- console.log "updateFeed(#{resource_id},#{feed},#{JSON.stringify data})"
+ console.log "updateFeed(#{resource_id},#{JSON.stringify data})"
dom_name = $("##{resource_id} > .car_name")
dom_name.html(data.car_name) if dom_name[0]?
- # if the feed doesn't exist, add it
- dom_feed = $("##{resource_id} > .feeds > .#{feed}")
+ for feed in config.feeds
+ # if the feed doesn't exist, add it
+ dom_feed = $("##{resource_id} > .feeds > .#{feed.name}")
- if dom_feed.length is 0 and data[feed]?
- dom_feed = $("##{resource_id} > .feeds").append("<li class='feed #{feed}'><h1 class='icon_wrapper'><span class='label'>#{feed}</span></h1>:<span class='data'></span></li>")
+ if dom_feed.length is 0 and data[feed.name]?
+ dom_feed = $("##{resource_id} > .feeds").append("<li class='feed #{feed.name}'><h1 class='icon_wrapper'><span class='label'>#{feed.name}</span></h1>:<span class='data'></span></li>")
- # replace the inner html with the new mpg data
- dom_feed.find(".data").html "#{data[feed]}"
+ # replace the inner html with the new mpg data
+ dom_feed.find(".data").html "#{data[feed.name]}"
# see if we have a marker on the map for this resource
for m in markers

0 comments on commit 680db32

Please sign in to comment.
Something went wrong with that request. Please try again.