-
Notifications
You must be signed in to change notification settings - Fork 4
/
dataGeneration.js
47 lines (42 loc) · 1.33 KB
/
dataGeneration.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
const faker = require('faker');
const fs = require('fs');
const coolImages = require('cool-images');
var generateData = () => {
var allArtists = [];
for (let i = 1; i < 101; i++) {
let artist = {
artistID: i,
artistName: faker.name.findName(),
albums: []
}
var albumNumber = Math.floor(Math.random() * 4) + 1;
for (let j = 1; j < albumNumber + 1; j++) {
let album = {
albumID: i * 10 + j,
albumName: faker.random.words(),
albumImage: coolImages.one(400, 400),
publishedYear: Math.floor(Math.random() * 69) + 1950,
songs: []
}
var songNumber = Math.floor(Math.random() * 10) + 12;
for (let k = 1; k < songNumber + 1; k++) {
let song = {
songID: i * 100 + j * 10 + k,
songName: faker.random.words(),
streams: Math.floor(Math.random() * 250000000),
length: Math.floor(Math.random() * 221) + 30,
popularity: Math.floor(Math.random() * 8) + 1,
addedToLibrary: faker.random.boolean()
}
album.songs.push(song);
}
artist.albums.push(album);
}
allArtists.push(artist);
}
fs.writeFile('data.json', JSON.stringify(allArtists), 'utf8', (err) => {
if (err) throw err;
console.log("File written!");
})
};
module.exports.generateData = generateData;