diff --git a/bin/generator-config.js b/bin/generator-config.js index 4727a1e..fea022a 100644 --- a/bin/generator-config.js +++ b/bin/generator-config.js @@ -5,6 +5,7 @@ module.exports = { "data": { "country": ["US", "US", "US", "US", "US", "US", "US", "US", "US", "US", "US", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "IN", "IN", "IN", "IN", "IN", "IN", "FR", "FR", "FR", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "GA", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"], "device": ["web", "iphone", "android"], - "gender": ["male", "male", "male", "female", "female", "female", "female", "female", "female", "female"] + "gender": ["male", "male", "male", "female", "female", "female", "female", "female", "female", "female"], + "type": ["t1", "t1", "t1", "t1", "t1", "t2", "t3", "t3", "t3"] } }; \ No newline at end of file diff --git a/bin/generator.js b/bin/generator.js index 482f6a1..3a32504 100644 --- a/bin/generator.js +++ b/bin/generator.js @@ -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); @@ -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++) { @@ -43,4 +67,10 @@ function sendForIntervals(a) { for (i = 0; i < a.length; i++) { setTimeout(sendPackets(a[i]), i * options.sampleRateInMS); } -} \ No newline at end of file +} + +ws.on('open', function () { + console.log("connected!"); +}); + +sendForIntervals(computePacketsPerSampleInInterval) \ No newline at end of file diff --git a/lib/cube/aggregator.js b/lib/cube/aggregator.js index 7a8fa65..15c684e 100644 --- a/lib/cube/aggregator.js +++ b/lib/cube/aggregator.js @@ -470,7 +470,7 @@ exports.register = function (dbs, endpoints, options) { }; options.aggregations.forEach(function (aggregationObject) { - validateAndRunAggregation(aggregationObject, 1000); + validateAndRunAggregation(aggregationObject, 50); }); } ;