| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- const fs = require('fs')
- const mockPath = './backend/db/_generated.js'
-
- // Insert here how many users you would like to generate:
- const total = 100
-
- // Amount of responses for a complete survey
- const questions = 13
-
- // Seekers per 100 profiles
- const percentageOfSeekers = 95
-
- // Values for responses
- const possibleResponses = {
- not_important: '120',
- some_what_important: '140',
- important: '160',
- very_important: '180',
- extremely_important: '200',
- mandatory: '400',
- }
-
- const possibleZipcodes = [
- '90065', // Glassel
- '90012', // Chinatown
- '90240', // Downey
- '91030', // South Pasadena
- '91201', // Glendale
- '91399', // Woodland Hills
- '91401', // Van Nuys
- '90840', // Long Beach
- '91001', // Altadena
- '91011', // La Canada Flintridge
- '97075', // Beaverton
- ]
-
- // Helper functions
- const randomNumber = max => {
- return Math.floor(Math.random() * max) < 1
- ? 1
- : Math.floor(Math.random() * max)
- }
-
- const randomValFrom = arr => arr[randomNumber(arr.length)]
-
- const generate = (classObj, amount, meta) => {
- const instances = []
- for (let i = 0; i < amount; i++) {
- instances.push(new classObj(i + 1, meta))
- }
- return instances
- }
-
- class User {
- constructor(id) {
- this.user_id = id
- this.user_name = ''
- this.user_email = ''
- this.is_admin = false
- this.is_poster = false
- }
- }
- class Profile {
- constructor(id) {
- this.user_id = id
- this.profile_id = id
- }
- }
- class Response {
- constructor(id) {
- this.response_id = id
- this.profile_id = null
- this.response_key_id = null
- this.val = null
- }
- }
-
- const users = generate(User, total)
- users.forEach(
- user => (user.is_poster = randomNumber(100) > percentageOfSeekers ? 1 : 0),
- )
-
- const profiles = generate(Profile, total)
-
- // Generate responses, then fill in details
- const responses = generate(Response, total * questions)
- profiles.forEach((profile, i) => {
- const startingIndex = i * questions
- for (let k = 0; k < questions; k++) {
- const resToEdit = responses[startingIndex + k]
- resToEdit.response_key_id = k + 1
- resToEdit.profile_id = profile.profile_id
- resToEdit.val =
- k + 1 == questions
- ? randomValFrom(possibleZipcodes)
- : randomValFrom(Object.values(possibleResponses))
- }
- })
-
- // console.log(responses)
- // console.log(users)
- const jobPosters = users.filter(user => user.is_poster > 0).length
- const write = async () => {
- await fs.writeFile(mockPath, '', () => {})
- fs.appendFile(
- mockPath,
- `/**\n * Generated ${total} profiles @${Date.now()}\n * ${jobPosters}:${
- total - jobPosters
- } posters|seekers\n * ---\n */\n\n` +
- 'module.exports = ' +
- JSON.stringify({ users, responses }),
- err => {
- if (err) {
- console.error(err)
- return
- }
- },
- )
- }
- write()
|