Comparing version 0.1.3 to 0.1.4
@@ -60,8 +60,9 @@ var util = require("util"), | ||
find(start, stop, tier, reduce.pyramidal && tier.next, callback); | ||
find(start, stop, tier, callback); | ||
// The metric is computed recursively, reusing the above variables. | ||
function find(start, stop, tier, pyramidal, callback) { | ||
function find(start, stop, tier, callback) { | ||
var compute = group ? (group.multi ? computeGroups : computeGroup) | ||
: pyramidal ? computePyramidal : computeFlat; | ||
: tier.next && reduce.pyramidal ? computePyramidal | ||
: computeFlat; | ||
@@ -167,3 +168,3 @@ // Query for the desired metric in the cache. | ||
var bins = {}; | ||
find(start, stop, tier.next, false, function(time, value) { | ||
find(start, stop, tier.next, function(time, value) { | ||
var bin = bins[time = tier.floor(time)] || (bins[time] = {size: tier.size(time), values: []}); | ||
@@ -170,0 +171,0 @@ if (bin.values.push(value) === bin.size) { |
var tiers = module.exports = {}; | ||
var second = 1000, | ||
second20 = 20 * second, | ||
second10 = 10 * second, | ||
minute = 60 * second, | ||
@@ -13,7 +13,7 @@ minute5 = 5 * minute, | ||
tiers[second20] = { | ||
key: second20, | ||
floor: function(d) { return new Date(Math.floor(d / second20) * second20); }, | ||
tiers[second10] = { | ||
key: second10, | ||
floor: function(d) { return new Date(Math.floor(d / second10) * second10); }, | ||
ceil: tier_ceil, | ||
step: function(d) { return new Date(+d + second20); } | ||
step: function(d) { return new Date(+d + second10); } | ||
}; | ||
@@ -25,5 +25,3 @@ | ||
ceil: tier_ceil, | ||
step: function(d) { return new Date(+d + minute5); }, | ||
next: tiers[second20], | ||
size: function() { return 15; } | ||
step: function(d) { return new Date(+d + minute5); } | ||
}; | ||
@@ -30,0 +28,0 @@ |
{ | ||
"name": "cube", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "A system for time series visualization using MongoDB, Node and D3.", | ||
@@ -5,0 +5,0 @@ "keywords": ["time series", "visualization"], |
@@ -16,10 +16,10 @@ var vows = require("vows"), | ||
keys.sort(function(a, b) { return a - b; }); | ||
assert.deepEqual(keys, [2e4, 3e5, 36e5, 864e5, 6048e5, 2592e6]); | ||
assert.deepEqual(keys, [1e4, 3e5, 36e5, 864e5, 6048e5, 2592e6]); | ||
} | ||
}, | ||
"second20": { | ||
topic: tiers[2e4], | ||
"has the key 2e4": function(tier) { | ||
assert.strictEqual(tier.key, 2e4); | ||
"second10": { | ||
topic: tiers[1e4], | ||
"has the key 1e4": function(tier) { | ||
assert.strictEqual(tier.key, 1e4); | ||
}, | ||
@@ -34,7 +34,7 @@ "next is undefined": function(tier) { | ||
"floor": { | ||
"rounds down to 20-seconds": function(tier) { | ||
"rounds down to 10-seconds": function(tier) { | ||
assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 20)), utc(2011, 08, 02, 12, 00, 20)); | ||
assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 21)), utc(2011, 08, 02, 12, 00, 20)); | ||
assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 23)), utc(2011, 08, 02, 12, 00, 20)); | ||
assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 39)), utc(2011, 08, 02, 12, 00, 20)); | ||
assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 39)), utc(2011, 08, 02, 12, 00, 30)); | ||
assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 40)), utc(2011, 08, 02, 12, 00, 40)); | ||
@@ -50,6 +50,6 @@ }, | ||
"ceil": { | ||
"rounds up to 5-minutes": function(tier) { | ||
"rounds up to 10-seconds": function(tier) { | ||
assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 20)), utc(2011, 08, 02, 12, 00, 20)); | ||
assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 21)), utc(2011, 08, 02, 12, 00, 40)); | ||
assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 23)), utc(2011, 08, 02, 12, 00, 40)); | ||
assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 21)), utc(2011, 08, 02, 12, 00, 30)); | ||
assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 23)), utc(2011, 08, 02, 12, 00, 30)); | ||
assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 39)), utc(2011, 08, 02, 12, 00, 40)); | ||
@@ -60,3 +60,3 @@ assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 40)), utc(2011, 08, 02, 12, 00, 40)); | ||
var date = utc(2011, 08, 02, 12, 00, 21); | ||
assert.deepEqual(tier.ceil(date), utc(2011, 08, 02, 12, 00, 40)); | ||
assert.deepEqual(tier.ceil(date), utc(2011, 08, 02, 12, 00, 30)); | ||
assert.deepEqual(date, utc(2011, 08, 02, 12, 00, 21)); | ||
@@ -67,16 +67,17 @@ } | ||
"step": { | ||
"increments time by twenty minutes": function(tier) { | ||
"increments time by ten seconds": function(tier) { | ||
var date = utc(2011, 08, 02, 23, 59, 20); | ||
assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 59, 30)); | ||
assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 59, 40)); | ||
assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 59, 50)); | ||
assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00, 00)); | ||
assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00, 10)); | ||
assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00, 20)); | ||
assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00, 40)); | ||
assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 01, 00)); | ||
}, | ||
"does not round the specified date": function(tier) { | ||
assert.deepEqual(tier.step(utc(2011, 08, 02, 12, 21, 23)), utc(2011, 08, 02, 12, 21, 43)); | ||
assert.deepEqual(tier.step(utc(2011, 08, 02, 12, 21, 23)), utc(2011, 08, 02, 12, 21, 33)); | ||
}, | ||
"does not modify the specified date": function(tier) { | ||
var date = utc(2011, 08, 02, 12, 20, 00); | ||
assert.deepEqual(tier.step(date), utc(2011, 08, 02, 12, 20, 20)); | ||
assert.deepEqual(tier.step(date), utc(2011, 08, 02, 12, 20, 10)); | ||
assert.deepEqual(date, utc(2011, 08, 02, 12, 20, 00)); | ||
@@ -91,7 +92,7 @@ } | ||
}, | ||
"next is the 20-second tier": function(tier) { | ||
assert.equal(tier.next, tiers[2e4]); | ||
"next is undefined": function(tier) { | ||
assert.isUndefined(tier.next); | ||
}, | ||
"size is 15": function(tier) { | ||
assert.strictEqual(tier.size(), 15); | ||
"size is undefined": function(tier) { | ||
assert.isUndefined(tier.size); | ||
}, | ||
@@ -98,0 +99,0 @@ |
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
693793