From 5c26539f074b31c019179860a5ad6df81107b11f Mon Sep 17 00:00:00 2001 From: tikazyq Date: Fri, 16 May 2014 17:23:20 +0100 Subject: [PATCH] fixed JSON.flatten --- bin/databases-config.js | 4 ++-- lib/analytics/aggregator.js | 2 +- lib/analytics/event.js | 5 +++-- public/js/analytics.js | 12 +++--------- public/js/util.js | 17 ++++++++--------- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/bin/databases-config.js b/bin/databases-config.js index c4684b9..b031dad 100644 --- a/bin/databases-config.js +++ b/bin/databases-config.js @@ -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, diff --git a/lib/analytics/aggregator.js b/lib/analytics/aggregator.js index ecf01a7..45bb603 100644 --- a/lib/analytics/aggregator.js +++ b/lib/analytics/aggregator.js @@ -470,7 +470,7 @@ exports.register = function (dbs, endpoints, options) { }; options.aggregations.forEach(function (aggregationObject) { - validateAndRunAggregation(aggregationObject, 1000); + validateAndRunAggregation(aggregationObject, 20); }); }; diff --git a/lib/analytics/event.js b/lib/analytics/event.js index d84a86f..798fbf1 100644 --- a/lib/analytics/event.js +++ b/lib/analytics/event.js @@ -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, @@ -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) { diff --git a/public/js/analytics.js b/public/js/analytics.js index d77fee7..b1af0ad 100644 --- a/public/js/analytics.js +++ b/public/js/analytics.js @@ -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); @@ -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 () { @@ -415,7 +411,6 @@ function RealTimeAggregations() { .datum(chartData) .transition().duration(1) .call(chart); - chart.update(); }); //Figure out a good way to do this automatically @@ -484,6 +479,7 @@ function RealTimeAggregations() { * @param aggregationData */ this.dataHandler = function (aggregationData) { +// console.log(JSON.flatten(aggregationData));//debug _this._data.push(JSON.flatten(aggregationData)); }; @@ -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 () { @@ -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(); } \ No newline at end of file diff --git a/public/js/util.js b/public/js/util.js index 3732563..def8ae1 100644 --- a/public/js/util.js +++ b/public/js/util.js @@ -256,13 +256,11 @@ 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 + "]"); } @@ -270,11 +268,12 @@ JSON.flatten = function (data) { 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) {