Comparing version 0.0.4 to 0.0.6
@@ -1,2 +0,2 @@ | ||
exports.version = "0.0.4"; | ||
exports.version = "0.0.6"; | ||
exports.emitter = require("./server/emitter"); | ||
@@ -7,1 +7,2 @@ exports.server = require("./server/server"); | ||
exports.visualizer = require("./server/visualizer"); | ||
exports.endpoint = require("./server/endpoint"); |
@@ -33,3 +33,3 @@ var fs = require("fs"), | ||
function file() { | ||
var files = Array.prototype.map.call(arguments, resolve), | ||
var files = Array.prototype.slice.call(arguments), | ||
type = types[files[0].substring(files[0].lastIndexOf(".") + 1)]; | ||
@@ -43,3 +43,3 @@ return function(request, response) { | ||
fs.stat(file, function(error, stats) { | ||
if (error) return fiveohoh(request, response); | ||
if (error) throw fiveohoh(request, response), error; | ||
size += stats.size; | ||
@@ -74,3 +74,3 @@ var time = new Date(stats.mtime); | ||
fs.readFile(files[i], "UTF-8", function(error, data) { | ||
if (error) return fiveohoh(request, response); | ||
if (error) throw fiveohoh(request, response), error; | ||
response.write(data); | ||
@@ -84,6 +84,2 @@ if (i < files.length - 1) read(i + 1); | ||
function resolve(name) { | ||
return path.join(__dirname, name); | ||
} | ||
function fiveohoh(request, response) { | ||
@@ -90,0 +86,0 @@ response.writeHead(500, {"Content-Type": "text/plain"}); |
@@ -7,2 +7,3 @@ // TODO report failures? | ||
var util = require("util"), | ||
mongodb = require("mongodb"), | ||
parser = require("./event-expression"), | ||
@@ -75,7 +76,9 @@ tiers = require("./tiers"), | ||
exports.getter = function(db) { | ||
var collection = types(db); | ||
var collection = types(db), | ||
streamDelay = 5000; | ||
return function(request, callback) { | ||
var start = new Date(request.start), | ||
stop = new Date(request.stop); | ||
function getter(request, callback) { | ||
var stream = !("stop" in request), | ||
start = new Date(request.start), | ||
stop = stream ? new Date(Date.now() - streamDelay) : new Date(request.stop); | ||
@@ -103,13 +106,34 @@ // Validate the dates. | ||
// Query for the desired events. | ||
collection(expression.type).events.find(filter, fields, event_options, function(error, cursor) { | ||
if (error) return util.log(error); | ||
cursor.each(function(error, event) { | ||
if (error) return util.log(error); | ||
if (event) callback({ | ||
time: event.t, | ||
data: event.d | ||
function query() { | ||
collection(expression.type).events.find(filter, fields, event_options, function(error, cursor) { | ||
if (error) throw error; | ||
cursor.each(function(error, event) { | ||
if (callback.closed) return cursor.close(); | ||
if (error) throw error; | ||
if (event) callback({ | ||
time: event.t, | ||
data: event.d | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
query(); | ||
// While streaming, periodically poll for new results. | ||
if (stream) { | ||
stream = setInterval(function() { | ||
if (callback.closed) return clearInterval(stream); | ||
filter.t.$gte = stop; | ||
filter.t.$lt = stop = new Date(Date.now() - streamDelay); | ||
query(); | ||
}, streamDelay); | ||
} | ||
} | ||
getter.close = function(callback) { | ||
callback.closed = true; | ||
}; | ||
return getter; | ||
}; |
@@ -83,6 +83,6 @@ var util = require("util"), | ||
function foundMetrics(error, cursor) { | ||
if (error) return util.log(error); | ||
if (error) throw error; | ||
var time = start; | ||
cursor.each(function(error, row) { | ||
if (error) return util.log(error); | ||
if (error) throw error; | ||
if (row) { | ||
@@ -104,6 +104,6 @@ callback(row.t, row.v, row.g); | ||
type.events.find(filter, fields, group_options, function(error, cursor) { | ||
if (error) return util.log(error); | ||
if (error) throw error; | ||
var k0, values; | ||
cursor.nextObject(function(error, row) { | ||
if (error) return util.log(error); | ||
if (error) throw error; | ||
if (!row) return; | ||
@@ -113,3 +113,3 @@ k0 = group.value(row); | ||
cursor.each(function(error, row) { | ||
if (error) return util.log(error); | ||
if (error) throw error; | ||
if (row) { | ||
@@ -139,6 +139,6 @@ var k1 = group.value(row); | ||
type.events.find(filter, fields, event_options, function(error, cursor) { | ||
if (error) return util.log(error); | ||
if (error) throw error; | ||
var groups = {}; | ||
cursor.each(function(error, row) { | ||
if (error) return util.log(error); | ||
if (error) throw error; | ||
@@ -188,6 +188,6 @@ if (!row) { | ||
type.events.find(filter, fields, event_options, function(error, cursor) { | ||
if (error) return util.log(error); | ||
if (error) throw error; | ||
var time = start, values = []; | ||
cursor.each(function(error, row) { | ||
if (error) return util.log(error); | ||
if (error) throw error; | ||
if (row) { | ||
@@ -194,0 +194,0 @@ var then = tier.floor(row.t); |
@@ -10,3 +10,3 @@ var util = require("util"), | ||
process.on("uncaughtException", function(error) { | ||
if (error.code !== "EPIPE") util.log(error.stack); | ||
util.log(error.stack); | ||
}); | ||
@@ -56,3 +56,4 @@ | ||
secondary.on("connection", function(connection) { | ||
connection.remoteAddress = connection._socket.remoteAddress; | ||
connection.socket = connection._socket; | ||
connection.remoteAddress = connection.socket.remoteAddress; | ||
connection.sendUTF = connection.send; | ||
@@ -70,3 +71,5 @@ connect(connection, connection._req); | ||
function callback(response) { | ||
connection.sendUTF(JSON.stringify(response)); | ||
if (connection.socket.writable) { | ||
connection.sendUTF(JSON.stringify(response)); | ||
} | ||
} | ||
@@ -88,3 +91,3 @@ | ||
var interval = setInterval(function() { | ||
if (!connection._socket.writable) { | ||
if (!connection.socket.writable) { | ||
interval = clearInterval(interval); | ||
@@ -91,0 +94,0 @@ connection.close(); |
var url = require("url"), | ||
path = require("path"), | ||
endpoint = require("./endpoint"); | ||
@@ -12,24 +13,30 @@ | ||
endpoint.exact("/cube.js", endpoint.file( | ||
"../client/start.js", | ||
"../client/cube.js", | ||
"../client/piece.js", | ||
"../client/piece-area.js", | ||
"../client/piece-sum.js", | ||
"../client/piece-text.js", | ||
"../client/palette.js", | ||
"../client/squares.js", | ||
"../client/board.js", | ||
"../client/header.js", | ||
"../client/end.js" | ||
resolve("start.js"), | ||
resolve("cube.js"), | ||
resolve("piece.js"), | ||
resolve("piece-area.js"), | ||
resolve("piece-sum.js"), | ||
resolve("piece-text.js"), | ||
resolve("palette.js"), | ||
resolve("squares.js"), | ||
resolve("board.js"), | ||
resolve("header.js"), | ||
resolve("end.js") | ||
)), | ||
endpoint.exact("/cube.css", endpoint.file( | ||
"../client/body.css", | ||
"../client/palette.css", | ||
"../client/board.css", | ||
"../client/piece.css" | ||
resolve("body.css"), | ||
resolve("palette.css"), | ||
resolve("board.css"), | ||
resolve("piece.css") | ||
)), | ||
endpoint.exact("/d3/d3.js", endpoint.file( | ||
"../../../node_modules/d3/d3.min.js", | ||
"../client/semicolon.js", | ||
"../../../node_modules/d3/d3.time.min.js" | ||
resolve("../../../node_modules/d3/d3.min.js"), | ||
resolve("semicolon.js"), | ||
resolve("../../../node_modules/d3/d3.geo.min.js"), | ||
resolve("semicolon.js"), | ||
resolve("../../../node_modules/d3/d3.geom.min.js"), | ||
resolve("semicolon.js"), | ||
resolve("../../../node_modules/d3/d3.layout.min.js"), | ||
resolve("semicolon.js"), | ||
resolve("../../../node_modules/d3/d3.time.min.js") | ||
)) | ||
@@ -65,3 +72,3 @@ ); | ||
var boards, | ||
file = endpoint.file("../client/visualizer.html"); | ||
file = endpoint.file(resolve("visualizer.html")); | ||
@@ -178,2 +185,6 @@ db.collection("boards", function(error, collection) { | ||
function resolve(file) { | ||
return path.join(__dirname, "../client", file); | ||
} | ||
function emit(callbacks, event) { | ||
@@ -180,0 +191,0 @@ callbacks.forEach(function(callback) { |
{ | ||
"name": "cube", | ||
"version": "0.0.4", | ||
"version": "0.0.6", | ||
"description": "A system for time series visualization using MongoDB, Node and D3.", | ||
@@ -11,3 +11,3 @@ "keywords": ["time series", "visualization"], | ||
"dependencies": { | ||
"d3": "2.1.3", | ||
"d3": "2.3.2", | ||
"mongodb": "0.9.6-15", | ||
@@ -14,0 +14,0 @@ "pegjs": "0.6.2", |
@@ -9,4 +9,5 @@ var vows = require("vows"), | ||
var port = ++test.port, | ||
server = http.createServer(endpoint.file("../client/semicolon.js", "../client/semicolon.js")); | ||
var file = "lib/cube/client/semicolon.js", | ||
port = ++test.port, | ||
server = http.createServer(endpoint.file(file, file)); | ||
@@ -13,0 +14,0 @@ server.listen(port, "127.0.0.1"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
670545
9680