Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit a381202

Browse files
topcoder-archive/topcoder-platform-u-bahn-app#648 - Add script to generate mock data for bulk upload
1 parent 32534a9 commit a381202

File tree

5 files changed

+226
-0
lines changed

5 files changed

+226
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,6 @@ dist
114114
.yarn/build-state.yml
115115
.yarn/install-state.gz
116116
.pnp.*
117+
118+
1-create-users.csv
119+
2-users-with-skills.csv

create-mock-users.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* ! NOTE - Requires the skills in /data/skills.json to exist
3+
* ! first in the database
4+
*
5+
* * Creates 2 files
6+
* * 1-create-users.csv => Upload this first. This will create the users
7+
* * 2-users-with-skills.csv => Upload this next. This will create 10 skills per previously created user
8+
*/
9+
10+
const fs = require('fs')
11+
const faker = require('faker')
12+
const { parseAsync } = require('json2csv')
13+
const skills = require('./data/skills.json')
14+
15+
const baseUser = {
16+
// handle
17+
// firstName
18+
// lastName
19+
// email
20+
countryName: 'India',
21+
providerType: 'Foo Digital',
22+
provider: 'Foo Technologies',
23+
// userId
24+
}
25+
26+
const skillUser = {
27+
// handle
28+
skillProviderName: 'EMSI',
29+
// skillName: ''
30+
}
31+
32+
const buFields = [
33+
'handle',
34+
'firstName',
35+
'lastName',
36+
'email',
37+
'countryName',
38+
'providerType',
39+
'provider',
40+
'userId'
41+
]
42+
43+
const suFields = [
44+
'handle',
45+
'skillProviderName',
46+
'skillName'
47+
]
48+
49+
let userCount = 100 // Number of users
50+
let BU = []
51+
let SU = []
52+
53+
while (userCount > 0) {
54+
userCount--
55+
56+
const handle = faker.internet.userName()
57+
58+
const b = {
59+
handle,
60+
firstName: faker.name.firstName(),
61+
lastName: faker.name.lastName(),
62+
email: faker.internet.exampleEmail(),
63+
userId: faker.random.alphaNumeric(8)
64+
}
65+
66+
BU.push(Object.assign(b, baseUser))
67+
68+
let skillCount = 10 // number of skills per user
69+
70+
while (skillCount > 0) {
71+
skillCount--
72+
73+
const s = {
74+
handle,
75+
skillName: faker.random.arrayElement(skills)
76+
}
77+
78+
SU.push(Object.assign(s, skillUser))
79+
}
80+
}
81+
82+
(async function start() {
83+
try {
84+
const opts1 = { fields: buFields }
85+
const csv1 = await parseAsync(BU, opts1)
86+
87+
fs.writeFileSync('1-create-users.csv', csv1)
88+
89+
const opts2 = { fields: suFields }
90+
const csv2 = await parseAsync(SU, opts2)
91+
92+
fs.writeFileSync('2-users-with-skills.csv', csv2)
93+
} catch (error) {
94+
console.log('Error generating base users')
95+
console.error(error)
96+
97+
throw error
98+
}
99+
})()

data/skills.json

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[
2+
"(American Society For Quality) ASQ Certified",
3+
".NET Assemblies",
4+
".NET Framework",
5+
".NET Framework 1",
6+
".NET Framework 3",
7+
".NET Framework 4",
8+
".NET Reflector",
9+
".NET Remoting",
10+
".nettiers",
11+
"10 Gigabit Ethernet",
12+
"1010data",
13+
"10BASE-F (Physical Layer Protocols)",
14+
"10BASE-FL",
15+
"10BASE2",
16+
"10BASE5",
17+
"10G-PON",
18+
"123RF (Image Library)",
19+
"128bit",
20+
"12factor",
21+
"2020 Design Software",
22+
"2D Animation",
23+
"2D Computer Graphics",
24+
"2D Gel Analysis Software",
25+
"2checkout",
26+
"3.5G (Telecommunication)",
27+
"35 Mm Films",
28+
"389 Directory Server (Fedora Project)",
29+
"3COM Certified IP Telephony NBX Expert",
30+
"3COM Certified IP Telephony VCX Expert",
31+
"3CX Phone Systems",
32+
"3D Art",
33+
"3D Camcorder",
34+
"3D Computer Graphics",
35+
"3D Computer Graphics Software",
36+
"3D Conformal Radiotherapy (3DCRT)",
37+
"3D Graphic Design",
38+
"3D Modeling",
39+
"3D Modeling Software",
40+
"3D Printing",
41+
"3D Projection",
42+
"3D Reconstruction",
43+
"3D Rendering",
44+
"3D Scanning",
45+
"3D Visualization",
46+
"3DML",
47+
"3DMark (Computer Benchmarking)",
48+
"3DSlicer",
49+
"3Delight (Software)",
50+
"3Dvia Composer",
51+
"3GP (Telecommunication)",
52+
"3GPP (Telecommunication)",
53+
"3GPP2 (Telecommunication)",
54+
"3d Engine",
55+
"3d Secure",
56+
"3d Solid And Surface Modeling",
57+
"4D Modeling (Construction)",
58+
"4DOS (Command Line Interpreter)",
59+
"4Sight",
60+
"4d Database",
61+
"50% Tissue Culture Infective Dose (TCID50)",
62+
"529 College Savings Planning",
63+
"56 Kbit/S Modems",
64+
"64-Bit Power PC Processors",
65+
"64bit",
66+
"6LoWPAN",
67+
"7-Zip",
68+
"8 Mm Video Format (Video Storage)",
69+
"90nm CMOS",
70+
"960.gs",
71+
"A-Files Accountability And Control Systems",
72+
"A/B Testing",
73+
"A3 Problem Solving Techniques",
74+
"A431 Cells (Cell Lines)",
75+
"AAA Protocol (Code Division Multiple Access)",
76+
"AAA Server (Authentication Authorization And Accounting)",
77+
"ABC FlowCharter",
78+
"ABI Solid Sequencing",
79+
"ABINIT",
80+
"ABL Radiometers",
81+
"ABR Routers",
82+
"AC Power Plugs And Sockets",
83+
"AC3D",
84+
"ACA Instructor Certificate",
85+
"ACCOL Workbench",
86+
"ACCP Certified",
87+
"ACDSee",
88+
"ACI Concrete Field Testing Technician",
89+
"ACI Concrete Laboratory Testing Technician",
90+
"ACI Concrete Strength Testing Technician",
91+
"ACID Pro"
92+
]

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"dependencies": {
1313
"axios": "^0.20.0",
1414
"config": "^3.3.1",
15+
"faker": "^5.1.0",
16+
"json2csv": "^5.0.1",
1517
"lodash": "^4.17.20",
1618
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6.4"
1719
}

0 commit comments

Comments
 (0)