|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+const fs = require('fs')
|
|
|
2
|
+const mockPath = './backend/db/_generated.js'
|
|
|
3
|
+
|
|
|
4
|
+// Insert here how many users you would like to generate:
|
|
|
5
|
+const total = 100
|
|
|
6
|
+
|
|
|
7
|
+// Amount of responses for a complete survey
|
|
|
8
|
+const questions = 13
|
|
|
9
|
+
|
|
|
10
|
+// Seekers per 100 profiles
|
|
|
11
|
+const percentageOfSeekers = 95
|
|
|
12
|
+
|
|
|
13
|
+// Values for responses
|
|
|
14
|
+const possibleResponses = {
|
|
|
15
|
+ not_important: '120',
|
|
|
16
|
+ some_what_important: '140',
|
|
|
17
|
+ important: '160',
|
|
|
18
|
+ very_important: '180',
|
|
|
19
|
+ extremely_important: '200',
|
|
|
20
|
+ mandatory: '400',
|
|
|
21
|
+}
|
|
|
22
|
+
|
|
|
23
|
+const possibleZipcodes = [
|
|
|
24
|
+ '90065', // Glassel
|
|
|
25
|
+ '90012', // Chinatown
|
|
|
26
|
+ '90240', // Downey
|
|
|
27
|
+ '91030', // South Pasadena
|
|
|
28
|
+ '91201', // Glendale
|
|
|
29
|
+ '91399', // Woodland Hills
|
|
|
30
|
+ '91401', // Van Nuys
|
|
|
31
|
+ '90840', // Long Beach
|
|
|
32
|
+ '91001', // Altadena
|
|
|
33
|
+ '91011', // La Canada Flintridge
|
|
|
34
|
+ '97075', // Beaverton
|
|
|
35
|
+]
|
|
|
36
|
+
|
|
|
37
|
+// Helper functions
|
|
|
38
|
+const randomNumber = max => {
|
|
|
39
|
+ return Math.floor(Math.random() * max) < 1
|
|
|
40
|
+ ? 1
|
|
|
41
|
+ : Math.floor(Math.random() * max)
|
|
|
42
|
+}
|
|
|
43
|
+
|
|
|
44
|
+const randomValFrom = arr => arr[randomNumber(arr.length)]
|
|
|
45
|
+
|
|
|
46
|
+const generate = (classObj, amount, meta) => {
|
|
|
47
|
+ const instances = []
|
|
|
48
|
+ for (let i = 0; i < amount; i++) {
|
|
|
49
|
+ instances.push(new classObj(i + 1, meta))
|
|
|
50
|
+ }
|
|
|
51
|
+ return instances
|
|
|
52
|
+}
|
|
|
53
|
+
|
|
|
54
|
+class User {
|
|
|
55
|
+ constructor(id) {
|
|
|
56
|
+ this.user_id = id
|
|
|
57
|
+ this.user_name = ''
|
|
|
58
|
+ this.user_email = ''
|
|
|
59
|
+ this.is_admin = false
|
|
|
60
|
+ this.is_poster = false
|
|
|
61
|
+ }
|
|
|
62
|
+}
|
|
|
63
|
+class Profile {
|
|
|
64
|
+ constructor(id) {
|
|
|
65
|
+ this.user_id = id
|
|
|
66
|
+ this.profile_id = id
|
|
|
67
|
+ }
|
|
|
68
|
+}
|
|
|
69
|
+class Response {
|
|
|
70
|
+ constructor(id) {
|
|
|
71
|
+ this.response_id = id
|
|
|
72
|
+ this.profile_id = null
|
|
|
73
|
+ this.response_key_id = null
|
|
|
74
|
+ this.val = null
|
|
|
75
|
+ }
|
|
|
76
|
+}
|
|
|
77
|
+
|
|
|
78
|
+const users = generate(User, total)
|
|
|
79
|
+users.forEach(
|
|
|
80
|
+ user => (user.is_poster = randomNumber(100) > percentageOfSeekers ? 1 : 0),
|
|
|
81
|
+)
|
|
|
82
|
+
|
|
|
83
|
+const profiles = generate(Profile, total)
|
|
|
84
|
+
|
|
|
85
|
+// Generate responses, then fill in details
|
|
|
86
|
+const responses = generate(Response, total * questions)
|
|
|
87
|
+profiles.forEach((profile, i) => {
|
|
|
88
|
+ const startingIndex = i * questions
|
|
|
89
|
+ for (let k = 0; k < questions; k++) {
|
|
|
90
|
+ const resToEdit = responses[startingIndex + k]
|
|
|
91
|
+ resToEdit.response_key_id = k + 1
|
|
|
92
|
+ resToEdit.profile_id = profile.profile_id
|
|
|
93
|
+ resToEdit.val =
|
|
|
94
|
+ k + 1 == questions
|
|
|
95
|
+ ? randomValFrom(possibleZipcodes)
|
|
|
96
|
+ : randomValFrom(Object.values(possibleResponses))
|
|
|
97
|
+ }
|
|
|
98
|
+})
|
|
|
99
|
+
|
|
|
100
|
+// console.log(responses)
|
|
|
101
|
+// console.log(users)
|
|
|
102
|
+const jobPosters = users.filter(user => user.is_poster > 0).length
|
|
|
103
|
+const write = async () => {
|
|
|
104
|
+ await fs.writeFile(mockPath, '', () => {})
|
|
|
105
|
+ fs.appendFile(
|
|
|
106
|
+ mockPath,
|
|
|
107
|
+ `/**\n * Generated ${total} profiles @${Date.now()}\n * ${jobPosters}:${
|
|
|
108
|
+ total - jobPosters
|
|
|
109
|
+ } posters|seekers\n * ---\n */\n\n` +
|
|
|
110
|
+ 'module.exports = ' +
|
|
|
111
|
+ JSON.stringify({ users, responses }),
|
|
|
112
|
+ err => {
|
|
|
113
|
+ if (err) {
|
|
|
114
|
+ console.error(err)
|
|
|
115
|
+ return
|
|
|
116
|
+ }
|
|
|
117
|
+ },
|
|
|
118
|
+ )
|
|
|
119
|
+}
|
|
|
120
|
+write()
|