-
Notifications
You must be signed in to change notification settings - Fork 14
/
report.js
207 lines (196 loc) · 6.99 KB
/
report.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
function checkSingular (num, unit) {
var singular = {
years: 'year',
minutes: 'minute',
hours: 'hour',
days: 'day',
months: 'month',
weeks: 'week'
}
if (num === '1') {
return singular[unit]
}
return unit
}
function location (loc) {
if (loc) {
return ' in ' + loc
}
return ''
}
function eventDetail (inviteType, talkType, eventName, eventLocation, travelType) {
var invite = {
invited: 'was invited',
cfp: 'proposed an idea',
sponsored: 'was sponsored'
}
var type = {
talk: 'to speak',
panel: 'to be on a panel',
workshop: 'to give a workshop'
}
var type2 = {
talk: 'I gave a talk',
panel: 'I was on a panel',
workshop: 'I run a workshop'
}
var type3 = {
talk: ' to give a talk',
panel: ' to be on a panel',
workshop: ' to run a workshop'
}
if (inviteType && talkType && eventName) {
return 'I ' + invite[inviteType] + ' ' + type[talkType] + ' at ' + eventName + location(eventLocation) + travelDistance(travelType) + '.'
} else if (!inviteType && talkType && eventName) {
return type2[talkType] + ' at ' + eventName + location(eventLocation) + travelDistance(travelType) + '.'
} else if (!inviteType && !talkType && eventName) {
return travelDistance(travelType, true) + ' to speak at ' + eventName + location(eventLocation) + '.'
} else if (!inviteType && talkType && !eventName && travelType) {
return travelDistance(travelType, false, true) + type3[talkType] + location(eventLocation) + '.'
} else if (!inviteType && talkType && !eventName && !travelType) {
return type2[talkType] + location(eventLocation) + '.'
} else if (inviteType && talkType && !eventName) {
return 'I ' + invite[inviteType] + ' ' + type[talkType] + location(eventLocation) + travelDistance(travelType) + '.'
} else if (inviteType && !talkType && !eventName) {
return 'I ' + invite[inviteType] + ' to speak' + location(eventLocation) + travelDistance(travelType) + '.'
} else if (inviteType && !talkType && eventName) {
return 'I ' + invite[inviteType] + ' to speak at ' + eventName + location(eventLocation) + travelDistance(travelType) + '.'
} else {
return ''
}
}
function travelDistance (travelType, separateSentence, separateSentence2) {
var type = {
international: ', so I travelled internationally to speak',
domestic: ', so I travelled domestically to speak',
local: '. This was a local event'
}
var type2 = {
international: ' I travelled internationally to speak',
domestic: ' I travelled domestically to speak',
local: ' I attended a local event'
}
var type3 = {
international: 'I travelled internationally',
domestic: 'I travelled domestically',
local: 'I attended a local event'
}
if (travelType && separateSentence) {
return type2[travelType]
} else if (travelType && separateSentence2) {
return type3[travelType]
} else if (travelType) {
return type[travelType]
}
return ''
}
function speakerBenefits (ticketType, fee, currency) {
var ticket = {
free: 'The event gave me a free ticket',
discount: 'The event offered me a discounted ticket to buy',
fullprice: 'The event asked me to buy a ticket at full price'
}
if (ticketType && fee) {
if (fee === '0') {
return ticket[ticketType] + ', and I was not paid to speak.'
} else {
return ticket[ticketType] + ', and I was paid ' + fee + ' ' + currency + ' to speak.'
}
} else if (!ticketType && fee) {
if (fee === '0') {
return 'I was not paid to speak.'
} else {
return 'I was paid ' + fee + ' ' + currency + ' to speak.'
}
} else if (ticketType && !fee) {
return ticket[ticketType] + '.'
} else {
return ''
}
}
function speakerTravel (travelAssistance) {
var assistance = {
full: 'My travel and accommodation was fully covered by the event.',
partial: 'The event assisted with part of my travel and accommodation.',
none: 'The event did not pay for my travel and accommodation.'
}
if (travelAssistance) {
return assistance[travelAssistance]
}
return ''
}
function employer (travelAssistance, timeOff) {
var assistance = {
full: 'paid all of',
partial: 'paid some of',
none: 'did not pay'
}
var off = {
working: 'I was working while speaking at the event.',
paid_timeoff: 'I used my PTO to speak.',
unpaid_timeoff: 'I took unpaid time off to speak.',
unemployed: 'I was unemployed when I spoke at the event.',
student: 'I was a student when I spoke at the event.'
}
if (travelAssistance && timeOff) {
return 'My employer ' + assistance[travelAssistance] + ' my travel expenses, and ' + off[timeOff]
} else if (!travelAssistance && timeOff) {
return off[timeOff]
} else if (travelAssistance && !timeOff) {
return 'My employer ' + assistance[travelAssistance] + ' my travel expenses.'
} else {
return ''
}
}
function experience (exp, singleSentence) {
if (exp && singleSentence) {
return 'I had a ' + exp + ' time.'
} else if (exp) {
return ', and I had a ' + exp + ' time'
}
return ''
}
function timeCommitment (speakingSlot, speakingSlotUnit, prepTime, prepTimeUnit, exp) {
if (speakingSlot && prepTime) {
return 'It took me ' + prepTime + ' ' + checkSingular(prepTime, prepTimeUnit) + ' to prepare for my ' + speakingSlot + ' ' + checkSingular(speakingSlot, speakingSlotUnit) + ' speaking slot' + experience(exp) + '.'
} else if (!speakingSlot && prepTime) {
return 'It took me ' + prepTime + ' ' + checkSingular(prepTime, prepTimeUnit) + ' to prepare for this event' + experience(exp) + '.'
} else if (speakingSlot && !prepTime) {
return 'My speaking slot was ' + speakingSlot + ' ' + checkSingular(speakingSlot, speakingSlotUnit) + ' for this event' + experience(exp) + '.'
} else {
return experience(exp, true)
}
}
function aboutSpeaker (gender, speakingYears, unit) {
if (!gender && speakingYears) {
return "I've been speaking for " + speakingYears + ' ' + checkSingular(speakingYears, unit) + '.'
} else if (speakingYears) {
return "I'm a " + gender + ' who has been speaking for ' + speakingYears + ' ' + checkSingular(speakingYears, unit) + '.'
}
return ''
}
function aboutEvent (type) {
if (type) {
return 'This was a ' + type + ' event.'
}
return ''
}
function also (additionalInfo) {
if (additionalInfo) {
return 'Also, ' + additionalInfo
}
return ''
}
function generate (data) {
return [
eventDetail(data.invite_type, data.talk_type, data.event_name, data.event_location, data.travel_type),
speakerBenefits(data.ticket_type, data.fee, data.currency),
speakerTravel(data.travel_assistance),
employer(data.travel_assistance_by_employer, data.time_off),
timeCommitment(data.speaking_slot, data.speaking_slot_unit, data.prep_time, data.prep_time_unit, data.experience),
aboutSpeaker(data.gender, data.speaking_years, data.speaking_years_unit),
aboutEvent(data.event_type),
also(data.additional_info)
].filter(function (n) { return n !== '' })
}
exports.generate = generate