Skip to content

Commit

Permalink
WIP: generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Mircea Danila Dumitrescu committed May 13, 2014
1 parent 095be58 commit f20e3fe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion bin/generator-config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 32 additions & 2 deletions bin/generator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";
var options = require("./generator-config.js"),
samples = Math.floor(options.intervalInMS / options.sampleRateInMS);
samples = Math.floor(options.intervalInMS / options.sampleRateInMS),
WebSocket = require("ws"),
ws = new WebSocket('ws://www.host.com/path');

function rnd_snd() {
return (Math.random() * 2 - 1) + (Math.random() * 2 - 1) + (Math.random() * 2 - 1);
Expand Down Expand Up @@ -31,6 +33,28 @@ function computePacketsPerSampleInInterval(packets, samples) {
return a;
}

function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

function sendPacket() {
var country = options.data.country[getRandomInt(0, options.data.country.length - 1)],
gender = options.data.gender[getRandomInt(0, options.data.gender.length - 1)],
device = options.data.device[getRandomInt(0, options.data.device.length - 1)],
type = options.data.type[getRandomInt(0, options.data.device.type - 1)],
ws = new WebSocket('ws://localhost:1080/1.0/event/put');

ws.send(
JSON.stringify({
type: type,
data: {
v1: gender,
v2: device,
v3: country
}})
);
}

function sendPackets(n) {
var i;
for (i = 0; i < n; i++) {
Expand All @@ -43,4 +67,10 @@ function sendForIntervals(a) {
for (i = 0; i < a.length; i++) {
setTimeout(sendPackets(a[i]), i * options.sampleRateInMS);
}
}
}

ws.on('open', function () {
console.log("connected!");
});

sendForIntervals(computePacketsPerSampleInInterval)
2 changes: 1 addition & 1 deletion lib/cube/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, 50);
});
}
;
Expand Down

0 comments on commit f20e3fe

Please sign in to comment.