-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataGenerator.js
176 lines (164 loc) · 3.46 KB
/
dataGenerator.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
This generates our fake newsfeed information.
There is no need to touch the code in here until you get to basic requirement #4,
but please check it out to familiarize yourself beforehand.
*/
(() => {
window.bacefook = {};
bacefook.newsfeed = [];
bacefook.friends = {};
bacefook.friendNames = ["tamaroh", "kani", "eriko", "tsubasa", "masataka"];
bacefook.friendNames.forEach(name => {
bacefook.friends[name] = [];
});
const getRandomElement = array => {
// Given an array, returns a random element
const randomIndex = Math.floor(Math.random() * array.length);
return array[randomIndex];
};
const starters = [
"totally just",
"just",
"completely",
"waaaaah! i",
"i just",
"a salaryman",
"a salaryman",
"yesterday I",
"a ninja",
"my boss"
];
const verbs = [
"ate",
"drank",
"threw up in",
"refactored",
"iterated on",
"thought about",
"threw up on",
"saw",
"walked to",
"got lost in",
"walked into",
"googled",
"drove",
"ran to",
"worked on",
"slept on",
"slept in"
];
const fillers = [
"my",
"your",
"his",
"her",
"my favorite",
"a beautiful",
"a delicious",
"that",
"this",
"an interesting",
"",
"the best",
"the greatest",
"a delightful"
];
const nouns = [
"DIG",
"restaurant",
"omakase",
"hitomedia",
"family mart",
"private jet",
"mama",
"lawsons",
"conbini",
"whisky",
"onigiri",
"car",
"food",
"house",
"toilet",
"tokyo",
"city",
"iphone",
"google",
"unicorn",
"mess",
"pirate ship",
"ninja"
];
const hashtags = [
"#DIG",
"#techlife",
"#toyota",
"#tokyo",
"#japan",
"#interesting",
"#til",
"#lol",
"#tgifriday",
"#hashtags",
"#japanlife",
"#oops",
""
];
const feelings = [
"happy",
"smug",
"lovestruck",
"gross",
"scared",
"tired",
"angry",
"frustrated",
"excited",
""
];
const images = [
"./images/1.jpg",
"./images/2.png",
"./images/3.png",
];
const generateRandomText = () => {
return [
getRandomElement(starters),
getRandomElement(verbs),
getRandomElement(fillers),
getRandomElement(nouns),
getRandomElement(hashtags)
].join(" ");
};
const generatePostObj = timeOffset => {
// if an offset is provided, make the timestamp that much older, otherwise just use the current time
const timestamp = timeOffset
? new Date(new Date().getTime() - timeOffset)
: new Date();
return {
friend: getRandomElement(bacefook.friendNames),
text: generateRandomText(),
feeling: getRandomElement(feelings),
image: getRandomElement(images),
timestamp
};
};
const addPost = obj => {
const friend = obj.friend;
bacefook.friends[friend].push(obj);
bacefook.newsfeed.push(obj);
};
const createPost = timeOffset => {
const newPost = generatePostObj(timeOffset);
addPost(newPost);
};
for (let i = 0; i < 10; i++) {
// make the starting posts look like they were posted over the course of the past day
const timeOffset = (2 * (10 - i) + Math.random()) * 60 * 60 * 1000;
createPost(timeOffset);
}
const scheduler = () => {
createPost(null);
setTimeout(scheduler, (3 + Math.random() * 5) * 1000); // generate a new post every 3 to 8 seconds
};
scheduler();
})();