Permalink
Browse files

Unified config. Tweaks. Better defaults

  • Loading branch information...
stagas committed Mar 14, 2012
1 parent 123eda4 commit dfa68b379b2dc86a07e70698394c83f796f8fef4
Showing with 44 additions and 39 deletions.
  1. +5 −5 bin/maptail
  2. +6 −2 examples/extreme-traffic.js
  3. +28 −11 lib/maptail.js
  4. +1 −1 package.json
  5. +4 −20 public/maptail.js
View
@@ -23,11 +23,11 @@ while (arg = args.shift()) {
else if (arg == '-p' || arg == '--port') config.port = parseInt(args.shift(), 10)
else if (arg == '--help') console.log(help), process.exit()
else if (arg == '--quiet') config.quiet = true
- else if (arg == '--max-dots' || arg == '--maxdots') maptail.clientConfig.maxDots = parseInt(args.shift(), 10)
- else if (arg == '--decay' || arg == '--ttl') maptail.clientConfig.ttl = parseInt(args.shift(), 10)
- else if (arg == '--max-age' || arg == '--maxage') maptail.clientConfig.visitorMaxAge = parseInt(args.shift(), 10)
- else if (arg == '--fps') maptail.clientConfig.ageInterval = 1000 / parseInt(args.shift(), 10)
- else if (arg == '--buffer') maptail.bufferTime = parseInt(args.shift(), 10)
+ else if (arg == '--max-dots' || arg == '--maxdots') maptail.config.maxDots = parseInt(args.shift(), 10)
+ else if (arg == '--decay' || arg == '--ttl') maptail.config.ttl = parseInt(args.shift(), 10)
+ else if (arg == '--max-age' || arg == '--maxage') maptail.config.maxAge = parseInt(args.shift(), 10)
+ else if (arg == '--fps') maptail.config.fps = 1000 / parseInt(args.shift(), 10)
+ else if (arg == '--buffer') maptail.config.bufferTime = parseInt(args.shift(), 10)
else spawnArgs.push(arg)
}
@@ -16,5 +16,9 @@ function rand () {
}
setInterval(function () {
- if (Math.random() * 10 < 10) maptail.emit('ip', [0,0,0,0].map(rand).join('.'))
-}, 1)
+ for (var i = 10; i--;) maptail.emit('ip', [0,0,0,0].map(rand).join('.'))
+}, 100)
+
+maptail.config.bufferMax = 200
+maptail.config.bufferTime = 500
+maptail.config.maxDots = 200
View
@@ -3,13 +3,31 @@ var geoip = require('geoip-lite-with-city-data')
var maptail = exports = module.exports = new EventEmitter
+maptail.config = {
+ // maximum history items
+ historyMax: 100
+
+ // maximum markers to buffer
+, bufferMax: 100
+
+ // buffer time in milliseconds
+, bufferTime: 1000
+
+ // markers' initial time to live in seconds
+, ttl: 100 // seconds
+
+ // maximum dots to be displayed (this adjusts ttl automatically)
+, maxDots: 100
+
+ // report visitors up to that age
+, maxAge: 240 // seconds
+
+ // aging repaint in fps
+, fps: 60
+}
+
maptail.history = []
-maptail.historyMax = 100
maptail.buffer = []
-maptail.bufferMax = 100
-maptail.bufferTime = 250
-
-maptail.clientConfig = {}
maptail.on('ip', function (ip, message) {
var geo = ip && maptail.lookup(ip) || {}
@@ -73,9 +91,8 @@ maptail.attach = function (app) {
.on('subscribe', function (what) {
if (what === 'geoip') {
users.add(socket)
- maptail.clientConfig.dateNow = Date.now()
- maptail.clientConfig.bufferTime = maptail.bufferTime
- socket.remote.emit('config', maptail.clientConfig)
+ maptail.config.dateNow = Date.now()
+ socket.remote.emit('config', maptail.config)
socket.remote.emit('geoip', maptail.history)
}
})
@@ -87,16 +104,16 @@ maptail.attach = function (app) {
maptail.on('geoip', function (geo) {
maptail.history.push(geo)
maptail.buffer.push(geo)
- if (maptail.history.length > maptail.historyMax) maptail.history.shift()
- if (Date.now() - before > maptail.bufferTime && maptail.buffer.length) {
+ if (maptail.history.length > maptail.config.historyMax) maptail.history.shift()
+ if (Date.now() - before > maptail.config.bufferTime && maptail.buffer.length) {
users.forEach(function (socket) {
socket.remote.emit('geoip', maptail.buffer)
})
maptail.buffer = []
before = Date.now()
}
else {
- if (maptail.buffer.length > maptail.bufferMax) maptail.buffer.shift()
+ if (maptail.buffer.length > maptail.config.bufferMax) maptail.buffer.shift()
}
})
}
View
@@ -2,7 +2,7 @@
"author": "George Stagas <gstagas@gmail.com> (http://stagas.com)",
"name": "maptail",
"description": "maptail is a realtime map view of GeoIP data",
- "version": "0.1.6",
+ "version": "0.1.8",
"repository": {
"url": "git://github.com/stagas/maptail.git"
},
View
@@ -1,21 +1,5 @@
// config
-var config = {}
-
-// markers' initial time to live in seconds
-config.ttl = 100 // seconds
-
-// maximum dots to be displayed (this adjusts ttl automatically)
-config.maxDots = 60
-
-// report visitors up to that age
-config.visitorMaxAge = 240 // seconds
-
-// aging repaint in milliseconds
-config.ageInterval = 1000 / 60
-
-// from the server
-config.timeDiff = 0
-config.bufferTime = 1000
+var config = { timeDiff: 0 }
// visitors
var visitors = 0
@@ -226,7 +210,7 @@ window.onload = function () {
} else {
marker = this.markers.list[geo.ip]
clearTimeout(marker.visitorTimeout)
- marker.visitorTimeout = setTimeout(visitorsDec, config.visitorMaxAge * 1000)
+ marker.visitorTimeout = setTimeout(visitorsDec, config.maxAge * 1000)
marker.date = geo.date
}
}
@@ -270,7 +254,7 @@ window.onload = function () {
this.ipList.object.className = 'ip'
this.ipList.object.innerHTML = this.ip + ' <span style="color:yellow">' + (geo.country || '??') + '</span>'
- this.visitorTimeout = setTimeout(visitorsDec, config.visitorMaxAge * 1000)
+ this.visitorTimeout = setTimeout(visitorsDec, config.maxAge * 1000)
}
Marker.prototype.paint = function () {
@@ -349,7 +333,7 @@ window.onload = function () {
setInterval(function () {
map.markers.age()
- }, config.ageInterval)
+ }, 1000 / config.fps)
connect(function (client) {
client.remote.on('config', function (cfg) {

0 comments on commit dfa68b3

Please sign in to comment.