-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler.py
114 lines (101 loc) · 3.48 KB
/
scheduler.py
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
# Python Imports
from random import randint
class Scheduler():
def __init__(self):
self._weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
self._headings = [''] + self._weekdays # empty space for axis titles
self._days = 7
self.total_shifts = 4
self.max_employees_per_shift = 4
#self.setSchedule()
def _setShiftNumbers(self):
"""
Determines number of employees per shift.
:return: None
"""
self._shift_employees = {}
for x in range(1, self.total_shifts + 1):
# self._shift_employees[x] = randint(2, self.max_employees_per_shift)
self._shift_employees[x] = self.max_employees_per_shift
return None
# Sets the employees to a spepcic Shift Block for the day
def _setShiftBlock(self, shift_pos, day):
"""
List of employees per shift.
:return:
"""
total_employees = self._shift_employees[shift_pos]
# STRANGE THINGS GOING ON HERE
#shift_block = [f'{self._weekdays[day][:2]}: Employee {id} S{shift_pos}' for id in range(total_employees)]
shift_block = [f'{self._weekdays[day][:2]} S{shift_pos} Emp. {id}' for id in range(total_employees)]
#shift_block = [f'Emp. {id}' for id in range(total_employees)]
# change employee num based on previous' rows max number of employees
#new_employee_number = shift_num
return shift_block
def _createLayout(self):
"""
Creates header and table for Weekly Schedule.
:return: None
"""
# num_shifts = number of shifts in a day
# num_days = number of days
# num_emps = number of employees per shift
# num_shifts x num_days x num_emps matrix
num_shifts, num_days, num_emps = self.total_shifts, self._days, self.max_employees_per_shift
self.table = [[self._setShiftBlock(shift_pos+1, day) for day in range(self._days)]
for shift_pos in range(self.total_shifts)]
# reshape format of table
# from: [shift_number][day][employees per day]
# to: [shift_number][employees_id][day]
self.schedule = [transpose(matrix) for matrix in self.table]
#self.layout = [self._headings] + [table]
return None
def _display(self):
"""
Print the schedule to the Command Line.
Later, show the GUI for schedule.
:return: None
"""
print_header(self._weekdays)
print_schedule(self.schedule)
return None
def setSchedule(self):
"""
Layout for Week Schedule.
:return: None
"""
self._setShiftNumbers()
self._createLayout()
self._display()
return None
def transpose(matrix):
"""
Transpose matrix.
:return: T (2D array)
"""
zipped = zip(*matrix)
T = [list(row) for row in zipped]
return T
def print_schedule(schedule):
"""
Print schedule.
:return: None
"""
for shift in schedule:
print(f"Shift {schedule.index(shift)+1}:")
for emp_row in shift:
print(" ", end='')
for emp_id in emp_row:
print(f"{emp_id.center(13)}", end=' ')
print()
print()
return None
def print_header(header):
"""
Print header: Days of Week
:return: None
"""
for x in header:
print(f"{x.center(18)}", end='')
print()
return None