Skip to content

Commit e870aa7

Browse files
committed
group attendees by languages and distribute them to event groups
1 parent 18e9d16 commit e870aa7

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

app/controllers/admin/groups_controller.rb

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,35 @@ def fill_groups
4242

4343
# add one attendee to each group as long as there are attendees in array
4444
@attendees = @event.applications.application_selected.confirmed.to_a
45-
@attendees.each do |attendee|
46-
@event.event_groups.each do |event_group|
47-
attendee_group = @attendees.pop(1)
48-
event_group.applications << attendee_group unless attendee_group.empty?
49-
end
45+
46+
groupped_attendes_by_language = @attendees.group_by do |element|
47+
[element.language_de, element.language_en]
48+
end
49+
50+
attendees_de = groupped_attendes_by_language[[true, false]]
51+
attendees_en = groupped_attendes_by_language[[false, true]]
52+
attendees_de_en = groupped_attendes_by_language[[true, true]]
53+
54+
de_groups = attendees_de.in_groups_of(6, false)
55+
en_groups = attendees_en.in_groups_of(6, false)
56+
57+
if (de_groups.last.size < 6)
58+
de_groups.last.concat(attendees_de_en.pop(6 - de_groups.last.size))
59+
end
60+
61+
if (en_groups.last.size < 6)
62+
en_groups.last.concat(attendees_de_en.pop(6 - en_groups.last.size))
63+
end
64+
65+
de_en_groups = attendees_de_en.in_groups_of(6, false)
66+
67+
all_groups = de_groups + en_groups + de_en_groups
68+
69+
# FIXME: This can cause attendees to not be assigned to event groups
70+
@event.event_groups.each do |event_group|
71+
group_to_add = all_groups.pop(1)
72+
break if group_to_add.nil?
73+
event_group.applications << group_to_add
5074
end
5175
end
5276

app/models/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Application < ApplicationRecord
2121
scope :cancelled, -> { where(state: :cancelled) }
2222
scope :not_marked_as_selected, -> { where(selected_on: nil) }
2323
scope :confirmed, -> { where(attendance_confirmed: true) }
24+
scope :language_de, -> { where(language_de: true) }
2425

2526
enum state: { rejected: 0, waiting_list: 1, application_selected: 2, cancelled: 3 }
2627

0 commit comments

Comments
 (0)