Skip to content

Commit

Permalink
Add entity sorting
Browse files Browse the repository at this point in the history
Initially sort entities by number of restrictions (most to least) and then by compromises (most to least) each loop. Additionally adds the debug output so users can see the distribution easily.
  • Loading branch information
willowv committed Jun 19, 2021
1 parent 357b5fe commit 1603f1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion calculateShifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ def toString(self):
numEntities = len(arrEntities)
shiftsPerEntity = ceil(numShifts / numEntities)
daysPerShift = ceil(numDays / shiftsPerEntity)
timeWindow = timedelta(daysPerShift + 2)
timeWindow = timedelta(daysPerShift)

# Initial entity sort - sort by day restrictions, most to least
def sortByRestrictions(entity):
return len(entity.daysUnavailable)

arrEntities.sort(reverse=True, key=sortByRestrictions)

# Assign shifts
entitiesRemaining = True
Expand Down Expand Up @@ -140,6 +146,16 @@ def balanceExistingDays(shift):

# Assign the chosen shift!
shiftCandidates[0].assign(entity)

# Sort entities by compromises
def sortByCompromises(entity):
return entity.numCompromises

arrEntities.sort(reverse=True, key=sortByCompromises)

# Debug output
for entity in arrEntities:
print(entity.toStringDebug())

# Write the schedule
with open('output.csv', 'w') as outputFile:
Expand Down
1 change: 1 addition & 0 deletions sampleEntities.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Steves,6-3,sun
Schaefer,6-3,fri;sat
Boncic,6-8,sat;sun
Cooney,6-12,fri;sun
Clarity,6-7,

0 comments on commit 1603f1f

Please sign in to comment.