|
@@ -183,7 +183,42 @@ class Activity < ApplicationRecord
|
183
|
183
|
self.delay(run_at: self.reminder_at).send_reminder
|
184
|
184
|
end
|
185
|
185
|
|
|
186
|
+
|
|
187
|
+ def assign_subgroups!
|
|
188
|
+
|
|
189
|
+ return unless self.subgroups.any?
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+ ps = self
|
|
193
|
+ .participants
|
|
194
|
+ .where(attending: true)
|
|
195
|
+ .where(subgroup: nil)
|
|
196
|
+ .to_a
|
|
197
|
+
|
|
198
|
+ ps.shuffle!
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+ groups = self
|
|
202
|
+ .subgroups
|
|
203
|
+ .where(is_assignable: true)
|
|
204
|
+ .to_a
|
|
205
|
+ .map { |sg| [sg.participants.count, sg] }
|
|
206
|
+
|
|
207
|
+ ps.each do |p|
|
|
208
|
+
|
|
209
|
+ groups.sort!
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+ p.subgroup = groups.first.second
|
|
213
|
+ p.save
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+ groups.first[0] += 1
|
|
217
|
+ end
|
|
218
|
+ end
|
|
219
|
+
|
186
|
220
|
private
|
|
221
|
+
|
187
|
222
|
|
188
|
223
|
|
189
|
224
|
def deadline_before_start
|