-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_generator.js
More file actions
96 lines (86 loc) · 3.18 KB
/
data_generator.js
File metadata and controls
96 lines (86 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* FAKE TWEET GENERATOR
*/
// set up data structures
window.streams = {};
streams.home = [];
streams.users = {};
streams.users.blastooo = [];
streams.users.googlegorilla = [];
streams.users.leo_tsang = [];
streams.users.annabanana = [];
streams.users.liniumz = [];
streams.users.boluchan = [];
streams.users.tallchinese = [];
streams.users.kellybelly = [];
streams.users.stiemrolla = [];
streams.users.jguamie = [];
window.users = Object.keys(streams.users);
users.shift(); // remove blastooo from random tweets
// library of real names
var fullNames = {
blastooo: 'James Lee',
leo_tsang: 'Leo Tsang',
googlegorilla: 'David Shen',
annabanana: 'Anna Kim',
liniumz: 'Jay Lin',
boluchan: 'Tina Yeh',
tallchinese: 'Mike Chan',
kellybelly: 'Kelli Hsu',
stiemrolla: 'Ben Stiemsma',
jguamie: 'John Lee'
};
// utility function for adding tweets to our data structures
var addTweet = function(newTweet){
var username = newTweet.user;
streams.users[username].push(newTweet);
streams.home.push(newTweet);
};
// utility function
var randomElement = function(array){
var randomIndex = Math.floor(Math.random() * array.length - 1) + 1;
return array[randomIndex];
};
// random tweet generator
var opening = ['just', '', '', '', '', 'ask me how i', 'completely', 'nearly', 'productively', 'efficiently', 'last night i', 'the president', 'that wizard', 'a ninja', 'a seedy old man'];
var verbs = ['downloaded', 'interfaced', 'deployed', 'developed', 'built', 'invented', 'experienced', 'navigated', 'aided', 'enjoyed', 'engineered', 'installed', 'debugged', 'delegated', 'automated', 'formulated', 'systematized', 'overhauled', 'computed'];
var objects = ['my', 'your', 'the', 'a', 'my', 'an entire', 'this', 'that', 'the', 'the big', 'a new form of'];
var nouns = ['cat', 'koolaid', 'system', 'city', 'worm', 'cloud', 'potato', 'money', 'way of life', 'belief system', 'security system', 'bad decision', 'future', 'life', 'pony', 'mind'];
var tags = ['#techlife', '#burningman', '#sf', 'but only i know how', 'for real', '#sxsw', '#ballin', '#omg', '#yolo', '#magic', '', '', '', ''];
var randomMessage = function(){
return [randomElement(opening), randomElement(verbs), randomElement(objects), randomElement(nouns), randomElement(tags)].join(' ');
};
// generate random tweets on a random schedule
var generateRandomTweet = function(){
var tweet = {};
tweet.user = randomElement(users);
tweet.fullName = fullNames[tweet.user];
tweet.message = randomMessage();
tweet.created_at = new Date();
addTweet(tweet);
};
var scheduleNextTweet = function(){
generateRandomTweet();
setTimeout(scheduleNextTweet, Math.random() * 3000);
};
scheduleNextTweet();
// utility function for letting students add "write a tweet" functionality
// (note: not used by the rest of this file.)
var writeTweet = function(message){
if(!visitor){
throw new Error('set the global visitor property!');
}
var tweet = {};
tweet.user = visitor;
tweet.message = message;
addTweet(tweet);
};
// utility function to post new tweet
var postTweet = function(message){
var tweet = {};
tweet.user = 'blastooo';
tweet.fullName = fullNames[tweet.user];
tweet.message = message;
tweet.created_at = new Date();
addTweet(tweet);
}