ucf_messages 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ucf_messages.rb +278 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2748d9b5ab8838e5ace4a57d1d804f747c1c1c07639831b259376e40daecc354
|
4
|
+
data.tar.gz: 6f38d12c95bbc1ef5cb6a1040a44f791e983bc6312928319db6b2c6581a71871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3892f43d5f208976beb8de97fe659a8dea68751a5dddcc895e8202005e614d0d3df6a0d6bc68a247969988da25b8b5b3022533115f74697fa997202a1f9e1765
|
7
|
+
data.tar.gz: 541355e76b06638bfa0a2c769eef3ca3a744822087b1dab8c05c4c9fd55236e513510f68668a6a2e4792d4cc830295fe453e55fd7d057d616f6a36c7ee062ea1
|
data/lib/ucf_messages.rb
CHANGED
@@ -1,5 +1,281 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class UcfMessages
|
2
|
-
|
3
|
-
|
4
|
+
MAX_REWARD_THRESHOLD = 5000
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def message(response)
|
8
|
+
@protocol = response.protocol_subscription.protocol
|
9
|
+
@protocol_completion = response.protocol_subscription.protocol_completion
|
10
|
+
@curidx = current_index
|
11
|
+
pooled_message
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# TODO: check this calculation! Why is there two rewards?
|
17
|
+
def streak_size
|
18
|
+
@protocol&.rewards&.second&.threshold || 3
|
19
|
+
end
|
20
|
+
|
21
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
22
|
+
def pooled_message
|
23
|
+
sms_pool = []
|
24
|
+
|
25
|
+
# Is this the first invitation? (= are we sending an invite for the first response in the prot sub?)
|
26
|
+
sms_pool += first_invitation_pool if first_invitation?
|
27
|
+
sms_pool += missed_previous_response if missed_previous_response? && sms_pool.empty?
|
28
|
+
sms_pool += rejoined_after_missing_some if rejoined_after_missing_some? && sms_pool.empty?
|
29
|
+
sms_pool += threshold_conditions if sms_pool.empty?
|
30
|
+
sms_pool += streak_conditions if sms_pool.empty?
|
31
|
+
sms_pool += default_pool if sms_pool.empty?
|
32
|
+
|
33
|
+
sms_pool.sample
|
34
|
+
end
|
35
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
36
|
+
|
37
|
+
def threshold_conditions
|
38
|
+
current_protocol_completion = truncated_protocol_completion
|
39
|
+
rewards_before = @protocol.calculate_reward(current_protocol_completion, false)
|
40
|
+
rewards_after = @protocol.calculate_reward(current_protocol_completion, true)
|
41
|
+
|
42
|
+
sms_pool = []
|
43
|
+
1000.step(MAX_REWARD_THRESHOLD, 1000) do |threshold|
|
44
|
+
# 1000 = 10 euro
|
45
|
+
sms_pool += rewards_threshold_pool(threshold) if rewards_before < threshold && rewards_after >= threshold
|
46
|
+
end
|
47
|
+
sms_pool
|
48
|
+
end
|
49
|
+
|
50
|
+
# rubocop:disable Metrics/MethodLength
|
51
|
+
def rewards_threshold_pool(threshold)
|
52
|
+
case threshold
|
53
|
+
when 1000 # 10 euro
|
54
|
+
[
|
55
|
+
'Whoop! Na deze vragenlijst heb je al €10 euro verdiend. Ga zo door!'
|
56
|
+
]
|
57
|
+
when 2000 # 20 euro
|
58
|
+
[
|
59
|
+
'Je gaat hard! Na deze vragenlijst heb je al €20 euro gespaard.'
|
60
|
+
]
|
61
|
+
when 3000 # 30 euro
|
62
|
+
[
|
63
|
+
'De teller blijft lopen! Na deze vragenlijst passeer jij de €30 euro :D'
|
64
|
+
]
|
65
|
+
when 4000 # 40 euro
|
66
|
+
[
|
67
|
+
'Geweldig, na deze vragenlijst heb je al 40 euro verdiend!'
|
68
|
+
]
|
69
|
+
when 5000 # 50 euro
|
70
|
+
[
|
71
|
+
'Wat heb jij je ontzettend goed ingezet! Inmiddels heb je al bijna 50 euro verdiend!'
|
72
|
+
]
|
73
|
+
else
|
74
|
+
[]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
# rubocop:enable Metrics/MethodLength
|
78
|
+
|
79
|
+
def streak_conditions
|
80
|
+
sms_pool = []
|
81
|
+
|
82
|
+
# Streak about to be 3
|
83
|
+
sms_pool += about_to_be_on_streak_pool if @protocol_completion[@curidx][:streak] == streak_size
|
84
|
+
|
85
|
+
# On bonus streak (== on streak > 3)
|
86
|
+
sms_pool += on_streak_pool if @protocol_completion[@curidx][:streak] > streak_size && sms_pool.empty?
|
87
|
+
|
88
|
+
sms_pool
|
89
|
+
end
|
90
|
+
|
91
|
+
def about_to_be_on_streak_pool
|
92
|
+
[
|
93
|
+
'Je bent goed bezig {{deze_student}}! Vul deze vragenlijst in en bereik een bonus-streak!'
|
94
|
+
]
|
95
|
+
end
|
96
|
+
|
97
|
+
def on_streak_pool
|
98
|
+
[
|
99
|
+
'Fijn dat je zo behulpzaam bent, {{deze_student}}! Vul je opnieuw de vragenlijst in?',
|
100
|
+
'Je zit nog steeds in je bonus-streak! Je u-can-feel spaarpotje raakt al behoorlijk vol ;)',
|
101
|
+
'Bedankt voor je inzet! Ga zo door :D',
|
102
|
+
'{{deze_student}}, je bent een topper! Bedankt voor je goede hulp!',
|
103
|
+
'Goed bezig met je bonus-streak, ga zo door!',
|
104
|
+
'Super dat je de vragenlijst al zo vaak achter elkaar hebt ingevuld, bedankt en ga zo door!',
|
105
|
+
'Hoi {{deze_student}}! Vul je de vragenlijst weer in om geld te verdienen?'
|
106
|
+
]
|
107
|
+
end
|
108
|
+
|
109
|
+
def first_invitation_pool
|
110
|
+
[
|
111
|
+
'Welkom bij het u-can-feel dagboekonderzoek! Doe je ook mee? We vragen je om elke week in een paar ' \
|
112
|
+
'minuten wat vragen te beantwoorden over hoe het met je gaat. Daarmee help j eons met ons onderzoek ' \
|
113
|
+
'én kun je geld verdienen. Via de link kun j emeer informatie krijgen en de eerste vragenlijst ' \
|
114
|
+
'invullen.'
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
def default_pool
|
119
|
+
[
|
120
|
+
'Hoi {{deze_student}}! Er staat een vragenlijst voor je klaar, vul je hem weer in? :D',
|
121
|
+
'Een u-can-feel tip: vul drie weken achter elkaar een vragenlijst in en verdien een bonus voor elke ' \
|
122
|
+
'vragenlijst!',
|
123
|
+
'Hoi {{deze_student}}! Vul direct de vovlgende vragenlijst in. Het kost je maar een paar minuten en je helpt ' \
|
124
|
+
'ons enorm!',
|
125
|
+
'Hallo {{deze_student}}, verdien een euro! Vul nu de vragenlijst in!',
|
126
|
+
'Fijn dat jij meedoet! Door jou kunnen leerlingen met wie het niet zo goed gaat nog betere begeleiding ' \
|
127
|
+
'krijgen in de toekomst!',
|
128
|
+
'Help {{je_school}} nog beter te worden in wat ze doen en vul nu de vragenlijst in!',
|
129
|
+
'Heel fijn dat je meedoet! Hiermee help je {{je_school}} om leerlingen nog beter te begeleiden!'
|
130
|
+
]
|
131
|
+
end
|
132
|
+
|
133
|
+
def not_everything_missed
|
134
|
+
[
|
135
|
+
'Je hebt ons al enorm geholpen met de vragenlijsten die je hebt ingevuld, {{deze_student}}. Wil je ons ' \
|
136
|
+
'weer helpen én daarmee geld verdienen?'
|
137
|
+
]
|
138
|
+
end
|
139
|
+
|
140
|
+
def missed_everything
|
141
|
+
[
|
142
|
+
'Je bent nog niet gestart met het u-can-feel dagboekonderzoek, {{deze_student}}! Doe je alsnog mee? We ' \
|
143
|
+
'vragen je om elke week een paar minuten wat vragen te beantwoorden over hoe het met je gaat. Daarmee help ' \
|
144
|
+
'je ons met ons onderzoek én kun je geld verdienen. Via de link kun je meer informatie krijgen en de eerste ' \
|
145
|
+
'vragenlijst invullen.'
|
146
|
+
]
|
147
|
+
end
|
148
|
+
|
149
|
+
def missed_one_after_streak
|
150
|
+
[
|
151
|
+
'Je was heel goed bezig met het u-can-feel onderzoek {{deze_student}}. Probeer je opnieuw de bonus-streak ' \
|
152
|
+
'te halen om extra geld te verdienen?'
|
153
|
+
]
|
154
|
+
end
|
155
|
+
|
156
|
+
def missed_one_not_after_streak
|
157
|
+
[
|
158
|
+
'We hebben je gemist vorige week. Help je deze week weer mee met het u-can-feel onderzoek? Het kost maar ' \
|
159
|
+
'een paar minuten van je tijd. Je helpt ons en je school. Én je verdient er een euro mee.'
|
160
|
+
]
|
161
|
+
end
|
162
|
+
|
163
|
+
def rejoined_after_missing_one
|
164
|
+
[
|
165
|
+
'Na een weekje rust ben je er sinds vorige week weer bij. Heel fijn dat je weer mee doet met het u-can-feel ' \
|
166
|
+
'onderzoek! Daarmee help je ons enorm.'
|
167
|
+
]
|
168
|
+
end
|
169
|
+
|
170
|
+
def rejoined_after_missing_multiple
|
171
|
+
[
|
172
|
+
'Sinds vorige week doe je weer mee aan het u-can-feel onderzoek! Super! Vul nog twee vragenlijsten in en je ' \
|
173
|
+
'krijgt een bonus!'
|
174
|
+
]
|
175
|
+
end
|
176
|
+
|
177
|
+
def rejoined_after_missing_some
|
178
|
+
sms_pool = []
|
179
|
+
|
180
|
+
sms_pool += rejoined_after_missing_one if rejoined_after_missing_one?
|
181
|
+
sms_pool += rejoined_after_missing_multiple if sms_pool.empty?
|
182
|
+
|
183
|
+
sms_pool
|
184
|
+
end
|
185
|
+
|
186
|
+
def missed_previous_response
|
187
|
+
sms_pool = []
|
188
|
+
# [missed] only the last?
|
189
|
+
sms_pool += missed_last_only if missed_last_only?
|
190
|
+
sms_pool += missed_everything if missed_everything? && sms_pool.empty?
|
191
|
+
sms_pool += not_everything_missed if sms_pool.empty?
|
192
|
+
|
193
|
+
sms_pool
|
194
|
+
end
|
195
|
+
|
196
|
+
def missed_last_only
|
197
|
+
sms_pool = []
|
198
|
+
|
199
|
+
sms_pool += missed_one_after_streak if missed_one_after_streak?
|
200
|
+
sms_pool += missed_one_not_after_streak if sms_pool.empty?
|
201
|
+
|
202
|
+
sms_pool
|
203
|
+
end
|
204
|
+
|
205
|
+
def truncated_protocol_completion
|
206
|
+
@protocol_completion[0..@curidx]
|
207
|
+
end
|
208
|
+
|
209
|
+
def current_index
|
210
|
+
# -1 in case there are no other measurements
|
211
|
+
@protocol_completion.find_index { |entry| entry[:future] } || -1
|
212
|
+
end
|
213
|
+
|
214
|
+
def first_invitation?
|
215
|
+
@curidx.zero?
|
216
|
+
end
|
217
|
+
|
218
|
+
def completed_some?
|
219
|
+
@protocol_completion.pluck(:completed).any?
|
220
|
+
end
|
221
|
+
|
222
|
+
def missed_previous_response?
|
223
|
+
# Minimal pattern: .C (X = completed, C = current)
|
224
|
+
# index: 01
|
225
|
+
@curidx.positive? &&
|
226
|
+
!@protocol_completion[@curidx - 1][:completed]
|
227
|
+
end
|
228
|
+
|
229
|
+
def missed_last_only?
|
230
|
+
# Minimal pattern: X.C (X = completed, C = current)
|
231
|
+
# index: 012
|
232
|
+
@curidx > 1 &&
|
233
|
+
!@protocol_completion[@curidx - 1][:completed] &&
|
234
|
+
@protocol_completion[@curidx - 2][:completed]
|
235
|
+
end
|
236
|
+
|
237
|
+
def missed_one_after_streak?
|
238
|
+
# Minimal pattern: XXX.C (X = completed, C = current)
|
239
|
+
# index: 01234
|
240
|
+
@curidx > 2 && # only make sure that we can check the index at curidx-2.
|
241
|
+
!@protocol_completion[@curidx - 1][:completed] &&
|
242
|
+
@protocol_completion[@curidx - 2][:completed] &&
|
243
|
+
@protocol_completion[@curidx - 2][:streak] >= streak_size
|
244
|
+
end
|
245
|
+
|
246
|
+
# missed more than one in a row (but not all) prior to the current response
|
247
|
+
def missed_more_than_one?
|
248
|
+
# Minimal pattern: X..C (X = completed, C = current)
|
249
|
+
# index: 0123
|
250
|
+
@curidx > 2 &&
|
251
|
+
!@protocol_completion[@curidx - 1][:completed] &&
|
252
|
+
!@protocol_completion[@curidx - 2][:completed] &&
|
253
|
+
@protocol_completion[0..(@curidx - 3)].pluck(:completed).any?
|
254
|
+
end
|
255
|
+
|
256
|
+
def missed_everything?
|
257
|
+
# Minimal pattern: .C (X = completed, C = current)
|
258
|
+
# index: 01
|
259
|
+
@curidx.positive? &&
|
260
|
+
@protocol_completion[0..(@curidx - 1)].pluck(:completed).none?
|
261
|
+
end
|
262
|
+
|
263
|
+
def rejoined_after_missing_one?
|
264
|
+
# Minimal pattern: X.XC (X = completed, C = current)
|
265
|
+
# index: 0123
|
266
|
+
@curidx > 2 &&
|
267
|
+
@protocol_completion[@curidx - 1][:completed] &&
|
268
|
+
!@protocol_completion[@curidx - 2][:completed] &&
|
269
|
+
@protocol_completion[@curidx - 3][:completed]
|
270
|
+
end
|
271
|
+
|
272
|
+
def rejoined_after_missing_some?
|
273
|
+
# Minimal pattern: X.XC (X = completed, C = current)
|
274
|
+
# index: 0123
|
275
|
+
@curidx > 2 &&
|
276
|
+
@protocol_completion[@curidx - 1][:completed] &&
|
277
|
+
!@protocol_completion[@curidx - 2][:completed] &&
|
278
|
+
@protocol_completion[0..(@curidx - 3)].pluck(:completed).any?
|
279
|
+
end
|
4
280
|
end
|
5
281
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ucf_messages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ando Emerencia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: library for determining which invitation text to use
|
14
14
|
email: info@compsy.ch
|
@@ -17,7 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/ucf_messages.rb
|
20
|
-
homepage: https://
|
20
|
+
homepage: https://github.com/compsy/ucf_messages
|
21
21
|
licenses:
|
22
22
|
- MIT
|
23
23
|
metadata: {}
|
@@ -29,7 +29,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0'
|
32
|
+
version: '3.0'
|
33
33
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
35
|
- - ">="
|