-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-responses.ts
163 lines (149 loc) · 3.98 KB
/
generate-responses.ts
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
import * as fs from 'fs'
import { faker } from '@faker-js/faker'
import { stringify } from 'csv-stringify/sync'
type ResponseDefinition = {
question: string
response: ResponseGenerator
}
type ResponseGenerator = () => string
const optional = (response: ResponseGenerator): ResponseGenerator => {
return () => (faker.datatype.boolean() ? response() : '')
}
const singleChoice = (choices: Array<string>): ResponseGenerator => {
return () => faker.helpers.arrayElement(choices)
}
const multipleChoices = (choices: Array<string>): ResponseGenerator => {
return () =>
faker.helpers
.arrayElements(
choices,
faker.datatype.number({ min: 1, max: choices.length })
)
.join(', ')
}
const generateFormResponses = (
definitions: Array<ResponseDefinition>,
count: number
): Array<Array<string>> => {
const result = []
// Header
result.push(['Response number'].concat(definitions.map((d) => d.question)))
// Responses
let currentResponseNumber: number = 1
while (currentResponseNumber <= count) {
result.push(
[currentResponseNumber + ''].concat(definitions.map((d) => d.response()))
)
currentResponseNumber++
}
return result
}
const customerFeedbackResponses: Array<ResponseDefinition> = [
{
question: 'Feedback type',
response: singleChoice([
'Comments',
'Questions',
'Bug Report',
'Feature Request',
]),
},
{
question: 'Feedback',
response: () =>
faker.lorem.sentences(faker.datatype.number({ min: 1, max: 8 })),
},
{
question: 'Suggestions for improvement',
response: optional(() =>
faker.lorem.sentences(faker.datatype.number({ min: 3, max: 10 }))
),
},
{
question: 'Product(s) used',
response: optional(
multipleChoices([
'Invoicing',
'Customer Management',
'Accounting',
'Inventory Management',
'Employee Management',
])
),
},
{
question: 'How likely are you to recommend us to a friend or colleague?',
response: () => faker.datatype.number({ min: 0, max: 10 }) + '',
},
{ question: 'Name', response: optional(faker.name.findName) },
{ question: 'Email', response: optional(faker.internet.email) },
]
const orderRequestResponses: Array<ResponseDefinition> = [
{
question: 'Are you a new or existing customer?',
response: optional(
singleChoice(['I am a new customer', 'I am an existing customer'])
),
},
{
question: 'What is the item you would like to order?',
response: singleChoice([
'JF72HSY0',
'AK10BBZ7',
'MB917ZH5',
'0B7ANSH6',
'01N58XNS',
'1928SJWN',
]),
},
{
question: 'What color(s) would you like to order?',
response: optional(multipleChoices(['Red', 'Blue', 'Green', 'Yellow'])),
},
{
question: 'Product options',
response: optional(
multipleChoices([
'Red: 2 SMALL',
'Red: 1 MEDIUM',
'Blue: 1 MEDIUM',
'Blue: 1 LARGE',
'Green: 3 SMALL',
'Green: 1 LARGE',
'Yellow: 3 MEDIUM',
'Yellow: 1 SMALL',
])
),
},
{ question: 'Your name', response: faker.name.findName },
{
question: 'Phone number',
response: () => faker.phone.phoneNumber('###-###-####'),
},
{ question: 'Email', response: optional(faker.internet.email) },
{
question: 'Preferred contact method',
response: multipleChoices(['Phone', 'Email']),
},
{
question: 'How satisfied are you with our service?',
response: () => faker.datatype.number({ min: 1, max: 5 }) + '',
},
{
question: 'Questions and comments',
response: optional(() =>
faker.lorem.sentences(faker.datatype.number({ min: 3, max: 10 }))
),
},
]
const run = () => {
fs.writeFileSync(
'./src/data/customer-feedback-responses.csv',
stringify(generateFormResponses(customerFeedbackResponses, 132))
)
fs.writeFileSync(
'./src/data/order-request-responses.csv',
stringify(generateFormResponses(orderRequestResponses, 154))
)
}
run()