forked from webmaxru/mobileera-badge-print-2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticipants.js
460 lines (382 loc) · 11.7 KB
/
participants.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
var XLSX = require('xlsx')
var _ = require('lodash')
var moment = require('moment')
var IMAGES = {
'Attendee': 'images/badge-print.png',
'Trainee': 'images/badge-print4.png',
'Speaker': 'images/badge-print3.png',
'Crew': 'images/badge-print2.png'
}
var TRACKS = [
'Bifrost', 'Valhalla', 'Vikings Cafe'
]
var DIET_STOP_LIST = [
'meat, shrimps',
'Food',
'Steak, burgers or pizzas',
'None, I'm happy with anyting',
'Nope',
'nope',
'sushi',
'No preferences',
'No.',
'cheeseburger :)',
'Meat! :o)',
'Nope',
'I love meat.',
'I like food',
'no, thanks',
'No',
'no',
'Beef',
'Steak, Burgers or pizzas.',
'Chicken',
'Roast beef',
'None, I'm happy with anyting',
'Steak & Salad',
'sushi',
'No preferences',
'NA',
'Meet',
'Meat',
'Nope.',
'I love meat.',
'Sushi!',
'banana',
'Burger',
'all its fine',
'None',
'none',
'T',
'no :)',
'No restrictions',
'Thanks for the effort, see you in the conference!',
'you cool',
'🍗🍖🥓'
]
var TSHIRTS = {
'Female XS': 0,
'Female S': 0,
'Female M': 0,
'Female L': 0,
'Female XL': 0,
'Female XXL': 0,
'Male XS': 0,
'Male S': 0,
'Male M': 0,
'Male L': 0,
'Male XL': 0,
'Male XXL': 0,
'Male XXXL': 0,
'Male XXXXL': 0,
'-': 0,
'number': 0
}
var TICKET_TYPES = {
'numberRegular': 0,
'numberDiscounted': 0,
'numberFree': 0,
'total': 0,
'number': 0
}
var STATS = {
'conf': {
'tickets': {
'regularBird': Object.assign({}, TICKET_TYPES),
'earlyBird': Object.assign({}, TICKET_TYPES),
'lateBird': Object.assign({}, TICKET_TYPES),
'student': Object.assign({}, TICKET_TYPES),
'sponsorTicket': Object.assign({}, TICKET_TYPES),
'speakerTicket': Object.assign({}, TICKET_TYPES),
'total': 0,
'number': 0
},
'people': {
'attendees': 0,
'crew': 0,
'speakers': 0,
'trainees': 0,
'number': 0
},
'diet': {
'list': [],
'number': 0
},
'referrer': {
"I'm ngVikings 2017 participant": 0,
'Twitter': 0,
'Facebook': 0,
'Meetup': 0,
'Search engine': 0,
'Printed ad': 0,
'Article or blog post': 0,
'Friend': 0
}
},
'workshops': {
'tickets': {
'Workshop: Advanced Angular for Enterprise Applications by Manfred Steyer': {
'total': 0,
'number': 0
},
'Workshop: Angular Workshop: From Zero To Viking in 1 day! by Laurent Duveau': {
'total': 0,
'number': 0
},
'Workshop: Advanced RxJS in Angular by Kwinten Pisman & Brecht Billiet': {
'total': 0,
'number': 0
},
'Workshop: NGRX Beginner to Master by Dominic Elm': {
'total': 0,
'number': 0
},
'Workshop: Pimp your app for PWA by Lauri Svan': {
'total': 0,
'number': 0
},
'Workshop: Angular - The Awesome Parts by John Papa & Ward Bell': {
'total': 0,
'number': 0
},
'Workshop: ngGirls': {
'total': 0,
'number': 0
},
'total': 0,
'number': 0
},
'diet': {
'list': [],
'number': 0
}
},
'tshirts': {
'attendees': Object.assign({}, TSHIRTS),
'crew': Object.assign({}, TSHIRTS),
'speakers': Object.assign({}, TSHIRTS),
'black': Object.assign({}, TSHIRTS),
'white': Object.assign({}, TSHIRTS),
'number': 0
},
'total': 0,
'filteredByDate': 0
}
let workshopTicketOwners = []
let conferenceTicketOwners = []
function createParticipant (participant, programData) {
// console.log(participant)
var firstName = participant['Ticket First Name'] || ''
var lastName = participant['Ticket Last Name'] || ''
var crewType = participant['Crew type'] || ''
if (firstName.trim() && lastName.trim()) {
var fullName = [firstName.trim(), lastName.trim()].join(' ')
}else {
console.log('Unassigned ticket for ticket ' + participant['Ticket Reference'] + ' . Using order name')
var fullName = participant['Order Name']
}
var company = participant['Ticket Company Name']
var sessionInfo = null
var ticketName = participant['Ticket']
var ticketPrice = parseInt(participant['Price'])
var categoryName = null
var tShirt = participant['T-shirt type & size']
var dietAnswer = participant['Do you have any special dietary requirements?'] ? participant['Do you have any special dietary requirements?'].trim() : null
var diet = (dietAnswer === '-' || _.includes(DIET_STOP_LIST, dietAnswer)) ? null : dietAnswer
var discount = participant['Order Discount Code'] !== '-' ? participant['Order Discount Code'] : null
var referrer = participant['How did you hear about us?'] !== '-' ? participant['How did you hear about us?'] : null
var email = participant['Ticket Email']
var contactCard = fullName + ' <' + email + '>'
var modifiedDate = moment(participant['Ticket Last Updated Date'], 'MM/DD/YY'); // Last Updated | Created
console.log(participant['Twitter handle to print on your badge'])
var twitter = ( participant['Twitter handle to print on your badge'] && participant['Twitter handle to print on your badge'] !== '-' ) ? '@' + _.trimStart(participant['Twitter handle to print on your badge'].replace('https://twitter.com/', '').replace('https://github.com/', ''), '@') : null
console.log(twitter)
if (company) {
contactCard += ' of ' + company
}
if (ticketName.includes('Bird') || ticketName.includes('Student') || ticketName.includes('Conference')) {
categoryName = 'Attendee'
var confType = _.camelCase(ticketName)
if (ticketName.includes('Early')) {
confType = 'earlyBird'
}
if (ticketName.includes('Late')) {
confType = 'lateBird'
}
if (ticketName.includes('Conference')) {
confType = 'regularBird'
}
if (ticketName.includes('Student') || ticketName.includes('student')) {
confType = 'student'
}
STATS.conf.tickets.number++
STATS.conf.tickets.total += ticketPrice
STATS.conf.people.attendees++
STATS.conf.people.number++
STATS.total += ticketPrice
if (ticketPrice === 0) {
STATS.conf.tickets[confType].numberFree++
STATS.conf.tickets[confType].number++
console.log('Free ticket with code/tag: ' + (discount ? discount : '') + (participant['Tags'] ? participant['Tags'] : '') + ' ref: ' + participant['Ticket Reference'] + ' company: ' + participant['Ticket Company Name'])
} else if (!discount) {
STATS.conf.tickets[confType].numberRegular++
STATS.conf.tickets[confType].number++
STATS.conf.tickets[confType].total += ticketPrice
} else {
STATS.conf.tickets[confType].numberDiscounted++
STATS.conf.tickets[confType].number++
STATS.conf.tickets[confType].total += ticketPrice
}
STATS.tshirts.attendees[tShirt]++
STATS.tshirts.attendees.number++
STATS.tshirts.number++
STATS.tshirts.black[tShirt]++
STATS.tshirts.black.number++
if (diet) {
STATS.conf.diet.list.push(diet)
STATS.conf.diet.number++
}
if (referrer && (STATS.conf.referrer[referrer] === 0 || STATS.conf.referrer[referrer] > 0)) {
STATS.conf.referrer[referrer]++
}
conferenceTicketOwners.push(email)
} else if (ticketName.includes('Workshop')) {
categoryName = 'Trainee'
STATS.workshops.tickets.number++
STATS.workshops.tickets.total += ticketPrice
STATS.conf.people.trainees++
STATS.conf.people.number++
STATS.total += ticketPrice
if (ticketName.includes('Liisa')) {
ticketName = 'Workshop: Angular - The Awesome Parts by John Papa & Ward Bell'
}
STATS.workshops.tickets[ticketName].number++
STATS.workshops.tickets[ticketName].total += ticketPrice
workshopTicketOwners.push(email)
if (diet) {
STATS.workshops.diet.list.push(diet)
STATS.workshops.diet.number++
}
} else if (ticketName === 'Crew Ticket') {
categoryName = 'Crew'
STATS.conf.people.crew++
STATS.conf.people.number++
STATS.tshirts.crew[tShirt]++
STATS.tshirts.crew.number++
STATS.tshirts.number++
STATS.tshirts.white[tShirt]++
STATS.tshirts.white.number++
if (diet) {
STATS.conf.diet.list.push(diet)
STATS.conf.diet.number++
}
} else if (ticketName === 'Speaker Ticket') {
categoryName = 'Speaker'
sessionInfo = {}
STATS.conf.tickets['speakerTicket'].numberFree++
var speaker = programData.speakers.find(speaker => {
return speaker ? speaker['name'] == fullName : false
}
)
if (!speaker) {
console.log("Can't find session for ", fullName)
} else {
sessionInfo.social = speaker.socials
var session = Object.values(programData.sessions).find(session => {
return (session && session.speakers) ? session.speakers.includes(speaker.id) : false
}
)
if (!session) {
console.log("Can't find session for ", fullName)
//sessionInfo.title = "Workshop: ngGirls"
} else {
sessionInfo.title = session.title
var timeslot = null
for (const day of programData.schedule) {
let isFound = false
timeslot = day.timeslots.find(timeslot => {
let items = _.chain(timeslot.sessions)
.map('items')
.flatten()
.value()
return items.includes(parseInt(session.id))
})
if (timeslot) {
sessionInfo.date = moment(day.dateFormat, 'YYYY-MM-DD').format('dddd') // MMMM Do
sessionInfo.startTime = timeslot.startTime
let flatSlots = _.chain(timeslot.sessions)
.map('items')
.flatten()
.value()
sessionInfo.track = TRACKS[flatSlots.indexOf(parseInt(session.id))]
break
}
}
if (!timeslot) {
console.log("Can't find timeslot for ", session.id, fullName, sessionInfo.title)
}
}
}
STATS.conf.people.speakers++
STATS.conf.people.number++
STATS.tshirts.speakers[tShirt]++
STATS.tshirts.speakers.number++
STATS.tshirts.number++
STATS.tshirts.black[tShirt]++
STATS.tshirts.black.number++
if (diet) {
STATS.conf.diet.list.push(diet)
STATS.conf.diet.number++
}
} else {
console.log('===== Unknown category for ticket ' + participant['Ticket'])
}
var image = IMAGES[categoryName]
return {
fullName,
company,
contactCard,
sessionInfo,
image,
categoryName,
ticketName,
modifiedDate,
twitter,
crewType,
firstName,
lastName}
}
function participants (filename, filterOnType, startingDate, programData) {
var workbook = XLSX.readFile(filename)
var worksheet = workbook.Sheets[workbook.SheetNames[0]]
var participantsRaw = XLSX.utils.sheet_to_json(worksheet)
var participantsProcessed = participantsRaw.map(function (participant) {
return createParticipant(participant, programData)
}).filter(function (p) {
return p.categoryName
}).filter(function (p) {
return !filterOnType || filterOnType === p.categoryName
}).filter(function (p) {
if (startingDate) {
if (p.modifiedDate.isSameOrAfter(startingDate)) {
console.log('Modified date: ' + p.modifiedDate.format())
STATS.filteredByDate++
return true
} else {
return false // Set to false when filtering by date
}
} else {
return true
}
}).sort(function (a, b) {
if (a.categoryName.localeCompare(b.categoryName) != 0) {
return a.categoryName.localeCompare(b.categoryName)
}
return a.fullName.localeCompare(b.fullName)
})
console.log(JSON.stringify(STATS, undefined, 2))
console.log('ONLY workshop attendees:');
console.log(JSON.stringify(_.difference(workshopTicketOwners, conferenceTicketOwners), undefined, 2));
return participantsProcessed
}
module.exports = participants