Skip to content

Commit

Permalink
fixed JSON.flatten
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed May 16, 2014
1 parent 4618af6 commit 5c26539
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
4 changes: 2 additions & 2 deletions bin/databases-config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
events: {
"mongo-host": "192.168.56.101",
"mongo-host": "localhost",
"mongo-port": 27017,
"mongo-database": "events",
"mongo-username": null,
"mongo-password": null
},
aggregations: {
"mongo-host": "192.168.56.101",
"mongo-host": "localhost",
"mongo-port": 27017,
"mongo-database": "aggregations",
"mongo-username": null,
Expand Down
2 changes: 1 addition & 1 deletion lib/analytics/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ exports.register = function (dbs, endpoints, options) {
};

options.aggregations.forEach(function (aggregationObject) {
validateAndRunAggregation(aggregationObject, 1000);
validateAndRunAggregation(aggregationObject, 20);
});
};

5 changes: 3 additions & 2 deletions lib/analytics/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
var mongodb = require("mongodb"),
type_re = /^[a-z][a-zA-Z0-9_]+$/,
genericGetter = require("./genericGetter.js"),
myutils = require("./myutils.js");
myutils = require("./myutils.js"),
util = require("util");

exports.putterInit = function (db, options) {
var eventsCollectionCreated = 0,
Expand All @@ -21,7 +22,7 @@ exports.putterInit = function (db, options) {

function save(event) {
db.collection("events").insert(event, {w: 0});
console.log("Got event: " + event);
console.log("Got event: " + util.inspect(event, {colors: true, depth: null}));
}

function putter(request, messageSenderCallback) {
Expand Down
12 changes: 3 additions & 9 deletions public/js/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ function RealTimeEvents() {
.transition().duration(1)
.call(_this.chart);

_this.chart.update();

//Figure out a good way to do this automatically
nv.utils.windowResize(_this.chart.update);

Expand Down Expand Up @@ -213,9 +211,7 @@ function RealTimeEvents() {
_this.resetData(function () {
_this._data = {};
_this.chartData = [];
// _this.refreshAll();
});
_this.socket.close();
}
_this.socket = new WebSocket(_this.socketConnection);
_this.socket.onopen = function () {
Expand Down Expand Up @@ -415,7 +411,6 @@ function RealTimeAggregations() {
.datum(chartData)
.transition().duration(1)
.call(chart);
chart.update();
});

//Figure out a good way to do this automatically
Expand Down Expand Up @@ -484,6 +479,7 @@ function RealTimeAggregations() {
* @param aggregationData
*/
this.dataHandler = function (aggregationData) {
// console.log(JSON.flatten(aggregationData));//debug
_this._data.push(JSON.flatten(aggregationData));
};

Expand Down Expand Up @@ -598,9 +594,7 @@ function RealTimeAggregations() {
_this.resetData(function () {
_this._data = [];
_this.chartData = [];
// _this.refreshAll();
});
_this.socket.close();
}
_this.socket = new WebSocket(_this.socketConnection);
_this.socket.onopen = function () {
Expand Down Expand Up @@ -770,7 +764,7 @@ function RealTimeAggregations() {
function testRealTime() {
var rte = new RealTimeEvents();
//,
// rta = new RealTimeAggregations();
window.rta = new RealTimeAggregations();
rte.test();
// rta.test();
rta.test();
}
17 changes: 8 additions & 9 deletions public/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,24 @@ JSON.flatten = function (data) {
var result = {};

function recurse(cur, prop) {
var property,
i,
l,
isEmpty;
if (Object.create(cur) !== cur) {
if (Object(cur) !== cur) {
result[prop] = cur;
} else if (Array.isArray(cur)) {
var i,
l;
for (i = 0, l = cur.length; i < l; i++) {
recurse(cur[i], prop + "[" + i + "]");
}
if (l === 0) {
result[prop] = [];
}
} else {
isEmpty = true;
for (property in cur) {
if (cur.hasOwnProperty(property)) {
var isEmpty = true,
p;
for (p in cur) {
if (cur.hasOwnProperty(p)) {
isEmpty = false;
recurse(cur[property], prop ? prop + "." + property : property);
recurse(cur[p], prop ? prop + "." + p : p);
}
}
if (isEmpty && prop) {
Expand Down

0 comments on commit 5c26539

Please sign in to comment.