Skip to content

Instantly share code, notes, and snippets.

@knyga
Last active December 29, 2015 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knyga/7699420 to your computer and use it in GitHub Desktop.
Save knyga/7699420 to your computer and use it in GitHub Desktop.
Generates random data for invideo
var choise = {
random: function(min, max) {
return Math.floor(min + Math.random() * (max - min));
},
getName: function() {
var data = [
"Hammond",
"Holland",
"Sandoval",
"Rodgers",
"Clark",
"Banks",
"Grant",
"Ruiz",
"Johnson",
"Ortiz",
"Meyer",
"George",
"Simpson",
"Harmon",
"Zimmerman",
"Robinson",
"Pittman",
"Young",
"Baker",
"Carson",
"Farmer",
"Brock",
"Houston",
"Fernandez",
"White",
"Franklin",
"Nelson",
"Wolfe",
"Hogan",
"Bennett",
"Greer",
"Webb",
"Blake",
"Parsons",
"Ortiz",
"Blair",
"Gonzalez",
"Brewer",
"Swanson",
"Herrera",
"Day",
"Goodman",
"Morris",
"Hammond",
"Graves",
"Matthews",
"Curtis",
"Hall",
"Ramirez",
"Boone",
"Franklin",
"Park",
"Sutton",
"McLaughlin",
"Aguilar",
"Knight",
"Powell",
"Taylor",
"Wolfe",
"Gomez",
"Vargas",
"Schwartz",
"Roberson",
"Haynes",
"Larson",
"Maldonado",
"Stanley",
"Francis",
"Gibson",
"Huff",
"Carroll",
"Warren",
"Padilla",
"Cook",
"Watson",
"Santiago",
"Rodriguez",
"Evans",
"Sullivan",
"Stone",
"Bridges",
"Oliver",
"Anderson",
"Mendez",
"Watts",
"Blake",
"Palmer",
"Herrera",
"Allison",
"Norris",
"Wise",
"Cain",
"Moreno",
"Hawkins",
"Keller",
"Sparks",
"Wade",
"Campbell",
"Stephens",
"Rice",
"Chavez",
"Wilson",
"Gibbs",
"Coleman",
"McDaniel",
"McCormick",
];
return data[this.random(0, data.length-1)];
},
getURL: function(host) {
return host + "/" + this.getName();
},
getVideo: function() {
var data = [
{id: 161, value: 'xat1GVnl8-k'},
{id: 171, value: 'OeP4FFr88SQ'},
{id: 181, value: 'ZKynVP6htPE'}
];
return data[this.random(0, data.length-1)].id;
},
getIP: function() {
return this.random(0, 254) + "." +
this.random(0, 254) + "." +
this.random(0, 254) + "." +
this.random(0, 254);
},
getOS: function() {
var data = [
{id: 1, value: 'windows'},
{id: 11, value: 'mac'},
{id: 21, value: 'iphone'},
{id: 31, value: 'ipod'},
{id: 41, value: 'linux'},
{id: 51, value: 'other'},
];
return data[this.random(0, data.length-1)].id;
},
getBrowser: function() {
var data = [
{id: 1, value: 'chrome'},
{id: 11, value: 'firefox'},
{id: 21, value: 'opera'},
{id: 31, value: 'safari'},
{id: 41, value: 'omniweb'},
{id: 51, value: 'icab'},
{id: 61, value: 'camino'},
{id: 71, value: 'netscape'},
{id: 81, value: 'explorer'},
{id: 91, value: 'konqueror'},
{id: 101, value: 'other'}
];
return data[this.random(0, data.length-1)].id;
},
getVideoSizes: function() {
var data = [
{width: 420, height: 300},
{width: 320, height: 180},
{width: 150, height: 100},
{width: 560, height: 420},
{width: 640, height: 500},
{width: 729, height: 560},
];
return data[this.random(0, data.length)];
},
getWindowSizes: function() {
var data = [
{width: 1024, height: 800},
{width: 1280, height: 1024},
{width: 1360, height: 1024},
{width: 1640, height: 1280},
{width: 1920, height: 1420},
];
return data[this.random(0, data.length-1)];
},
getStates: function(year, month, maxDay, maxHour, maxMinute) {
if("undefined" === typeof year) {
year = 2013;
}
if("undefined" === typeof month) {
month = 10;
}
if("undefined" === typeof maxDay) {
maxDay = 28;
}
if("undefined" === typeof maxHour) {
maxHour = 20;
}
if("undefined" === typeof maxMinute) {
maxMinute = 59;
}
var day = this.random(1, maxDay),
hour = this.random(8, maxHour),
minute = this.random(1, maxMinute);
var time = new Date(year,
month,
day,
hour,
minute
).getTime();
var obj = {};
obj.oncreated = time
obj.onadsshow = time + this.random(100, 4000);
if(this.random(0,100) > 70) {
obj.onadsforceend = obj.onadsshow + this.random(100, 4000);
}
if(this.random(0,100) > 95) {
if(obj.hasOwnProperty('onadsforceend')) {
obj.onadsclosewindow = obj.onadsforceend + this.random(100, 500);
} else {
obj.onadsclosewindow = obj.onadsshow + this.random(100, 4000);
}
}
if(this.random(0,100) > 20) {
obj.onadshover = obj.onadsshow + this.random(100, 4000);
if(this.random(0,100) > 70) {
obj.onadsclick = obj.onadshover + this.random(100, 4000);
}
}
if( !obj.hasOwnProperty('onadsforceend') &&
!obj.hasOwnProperty('onadsclosewindow')
) {
obj.onvideoshow = obj.onadsshow + this.random(5000,10000);
}
return obj;
},
getID: function() {
return this.random(0, Math.pow(10,15)-1);
},
getSiteAds: function() {
var values = [1, 11, 31, 41, 51, 61, 71, 81];
return values[this.random(0, values.length)];
},
generate: function() {
var videoSize = this.getVideoSizes(),
windowSize = this.getWindowSizes(),
state = this.getStates();
var obj = {
id: this.getID(),
video_id: this.getVideo(),
siteAds_id: this.getSiteAds(),
url: this.getURL("http://kdummy.eu01.aws.af.cm"),
ip: this.getIP(),
videoWidth: videoSize.width,
videoHeight: videoSize.height,
windowWidth: windowSize.width,
windowHeight: windowSize.height,
browser_id: this.getBrowser(),
os_id: this.getOS(),
version: 0
};
for(var name in state) {
if(state.hasOwnProperty(name)) {
obj[name] = state[name];
}
}
var objectToQuery = function(conv) {
var query = "INSERT INTO `action` (";
for(var name in conv) {
var value = conv[name];
if(conv.hasOwnProperty(name) && "function" !== typeof value) {
query += "`"+name+"`, ";
}
}
query = query.substr(0, query.length-2);
query += ") VALUES(";
for(var name in conv) {
var value = conv[name];
if(conv.hasOwnProperty(name) && "function" !== typeof value) {
if("undefined" === typeof value) {
query += "NULL, ";
} else {
query += "'"+conv[name]+"', ";
}
}
}
query = query.substr(0, query.length-2);
query += ");";
return query;
}
obj.toString = function() {
return objectToQuery(obj);
}
return obj;
}
};
var str = "";
for(var i=0;i<1;i++) {
str += choise.generate() + "\n";
}
str;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment