forked from sc0v/binder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shift_picker.rb
132 lines (109 loc) · 14.1 KB
/
shift_picker.rb
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
# Org Shift Picker
# Use the Org Variables from the seeds file so that the output from this can just be used directly in seeds, should be in the order they submitted prefs
orgs = ['astro_org', 'aepi_org', 'kat_org', 'phidelt_org', 'sigep_org', 'dg_org', 'kkg_org', 'ssa_org', 'ddd_org', 'sae_org', 'math_org', 'axo_org', 'fringe_org', 'mcs_org', 'aphio_org', 'dtd_org', 'sdc_org', 'aphi_org', 'spirit_org', 'tsa_org', 'asa_org', 'kapsig_org', 'kgb_org', 'mayur_org', 'sigchi_org', 'earth_org']
# This should be how many shifts get assigned to that org, unfortunately it will fill up orgs who submitted prefs earlier first, so if it's not exact then remove a shift or two from the first couple orgs
size = [3, 6, 6, 6, 7, 7, 7, 7, 7, 7, 4, 7, 7, 4, 7, 7, 7, 7, 4, 7, 7, 7, 7, 4, 4, 4]
# This should be the org prefs, make sure the highestPref matches your form's highest
highestPref = 5
prefs =[
[2, 3, 3, 3, 3, 1, 1, 1, 3, 5, 5, 5, 5, 4, 4, 4, 1, 1, 1, 2, 5, 5, 4, 4, 2, 2, 2, 2, 1, 1, 1, 3, 3, 1, 1, 1, 4, 5, 2, 2, 1, 1, 1, 3, 3, 2, 1, 1, 1, 3, 4, 5, 2, 1, 1, 1, 4, 4, 5, 5, 4, 3, 3, 3, 2, 2, 2, 2, 3, 3, 5, 5, 3, 3, 1, 1, 1, 1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 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
]
# The Org's preference for Double Shifts. At one point I tried to double up if they wanted and tried not to if they didn't, but now it is just binary of whether or not I can
# I also make sure not to double shifts that don't want to be doubled
$doublePref = ['No', 'Yes', 'Meh', 'Meh', 'Yes', 'Meh', 'Yes', 'Meh', 'Meh', 'Meh', 'Yes', 'Yes', 'No', 'No', 'Meh', 'Meh', 'No', 'Meh', 'No', 'No', 'Meh', 'Meh', 'No', 'Yes', 'No', 'No']
# This is tricky, it should be the popularity of the shifts in reverse sorted order (from least to most) (i.e. if the first index is 78 it means the 1st shift is the 78th least popular)
# I suggest taking the geometric mean of the prefs for each timeslot and then sorting that list
popularity = [78, 90, 92, 91, 75, 77, 18, 30, 42, 54, 88, 89, 66, 17, 29, 41, 53, 43, 76, 79, 19, 31, 55, 102, 7, 64, 67, 80, 5, 6, 87, 16, 28, 40, 52, 99, 68, 93, 100, 4, 44, 101, 65, 74, 105, 56, 103, 63, 94, 106, 32, 104, 8, 85, 86, 73, 107, 20, 97, 108, 96, 95, 0, 1, 98, 39, 51, 82, 81, 15, 33, 45, 84, 3, 27, 83, 69, 70, 2, 46, 57, 72, 21, 36, 9, 11, 61, 60, 38, 47, 34, 58, 71, 10, 37, 50, 48, 35, 14, 49, 22, 62, 59, 12, 24, 25, 13, 26, 23]
#popularity = [66, 67, 75, 77, 78, 79, 90, 91, 102, 6, 7, 8, 18, 19, 30, 42, 43, 54, 55, 56, 65, 68, 74, 76, 80, 87, 88, 89, 92, 99, 100, 103, 5, 17, 20, 28, 29, 31, 32, 39, 40, 41, 44, 53, 64, 86, 101, 104, 4, 16, 51, 52, 63, 98, 27, 33, 45, 57, 73, 85, 93, 105, 106, 107, 108, 15, 69, 72, 97, 3, 46, 58, 59, 70, 71, 94, 96, 47, 60, 81, 83, 84, 95, 1, 2, 14, 34, 35, 38, 50, 61, 62, 82, 0, 21, 26, 36, 9, 10, 11, 48, 22, 25, 37, 49, 12, 13, 23, 24]
# How many shifts are required at each timeslot
required = [2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1]
numOrgs = orgs.length
standards = Array.new(numOrgs, highestPref)
numShifts = required.length
$shiftList = Array.new(numOrgs) { Array.new }
score = 0
scoreView = Array.new(numOrgs) { Array.new }
assigned = Array.new(numShifts, 0)
def canDouble?(shift, org)
if $shiftList[org].include?(shift) and $shiftList[org].index(shift) == $shiftList[org].rindex(shift)
#puts "Org: %d Shift: %d Shift Indexes: %d %d" % [org, shift, $shiftList[org].index(shift), $shiftList[org].rindex(shift)]
return $doublePref[org] != 'No'
elsif $shiftList[org].index(shift) != $shiftList[org].rindex(shift)
return false
end
return true
end
i = 0
org = 0
stop = 0
# This works by iterating through the total number of shifts which need to be assigned, looping through each org and assigning shifts one at a time
for i in 0..required.reduce(:+)-1
# Check to make sure the org isn't already full and skip it if it is
while $shiftList[org].length>=size[org] do org = (org + 1) % numOrgs end
shift = 0
# Now go through the shifts in reverse popularity order (from least popular to most) until you find a shift that isn't full, is highest pref for the org, and that the org isn't already double booked on.
while assigned[popularity[shift]] >= required[popularity[shift]] or prefs[org][popularity[shift]] != standards[org] or not(canDouble?(popularity[shift], org))
# If you get to the end of the list assume you didn't find anything at your highest pref and lower your standards and loop around
if ( shift + 1 ) % numShifts == 0
standards[org]-=1
shift = (shift + 1) % numShifts
#puts "lower standards: %d" % standards[org]
# Otherwise just look at the next shift (making sure to loop around)
else
shift = (shift + 1) % numShifts
#puts "next shift: %d" % shift
end
end
assigned[popularity[shift]]+=1
# add the shift to the orgs's list of shifts
$shiftList[org].push(popularity[shift])
# Add the score to the scoreView
scoreView[org].push(prefs[org][popularity[shift]])
score += standards[org]
#puts "Org: %d, Shift: %d, Standard: %d" % [org, popularity[shift], standards[org]]
#puts org
i+=1
org = (org + 1) % numOrgs
end
puts "Total Slots: %d, Total Assigned: %d" % [required.reduce(:+), assigned.reduce(:+)]
puts
puts "Shift List:"
p $shiftList
puts
puts "Scores:"
p scoreView
puts
puts "Total Score: %d" % score
puts
org = 0
for i in $shiftList
for j in i
puts "Shift.create({ shift_type: ShiftType.find_by_name('Watch Shift'), organization: %s, starts_at: move_on + 17.hours + %d.hours , ends_at: move_on + 17.hours + %d.hours, required_number_of_participants: 2 })" % [orgs[org], j * 2, (j + 1) * 2]
end
org+=1
end