|
@@ -1,8 +1,10 @@
|
|
|
import collections
|
|
import collections
|
|
|
-import fileinput
|
|
|
|
|
|
|
|
|
|
-# https://docs.google.com/spreadsheets/d/1FzYvO825t1de0UpzL3ovzkXE3cRiXGZetLt1zCzzWjE/edit#gid=0
|
|
|
|
|
|
|
+import client
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
+# https://docs.google.com/spreadsheets/d/1FzYvO825t1de0UpzL3ovzkXE3cRiXGZetLt1zCzzWjE/edit#gid=0
|
|
|
|
|
+# https://docs.google.com/spreadsheets/d/1JMP9QsXdPbvIVL01LFRAMqkMQZRL17gs_ZjKFBJjI8E/edit#gid=0
|
|
|
|
|
|
|
|
class Color(object):
|
|
class Color(object):
|
|
|
_ENDC = '\033[0m'
|
|
_ENDC = '\033[0m'
|
|
@@ -71,9 +73,14 @@ def _block_shared(columns):
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
-def parse():
|
|
|
|
|
- lines = [x for x in fileinput.input()]
|
|
|
|
|
- lines.reverse()
|
|
|
|
|
|
|
+def load_config(wc_config):
|
|
|
|
|
+ # staff: [{"name": string, "hours": float, "driver": bool, "gender": string}]
|
|
|
|
|
+ # reqs: [[string]], e.g. [[], ["7/9", "12/21"]]
|
|
|
|
|
+ # roster: {name: [string], "dows": [string], "dates": [int]}
|
|
|
|
|
+ # blocked: [[name1, name2, ...], ...]
|
|
|
|
|
+
|
|
|
|
|
+ rows = wc_config.get_all_values()
|
|
|
|
|
+ rows.reverse()
|
|
|
|
|
|
|
|
roster = {}
|
|
roster = {}
|
|
|
staff = []
|
|
staff = []
|
|
@@ -82,37 +89,38 @@ def parse():
|
|
|
|
|
|
|
|
func = None
|
|
func = None
|
|
|
|
|
|
|
|
- while lines:
|
|
|
|
|
- line = lines.pop().rstrip('\n').lstrip('"')
|
|
|
|
|
-
|
|
|
|
|
- if not line.strip():
|
|
|
|
|
|
|
+ while rows:
|
|
|
|
|
+ row = rows.pop()
|
|
|
|
|
+ if not any(row):
|
|
|
continue
|
|
continue
|
|
|
- if line.startswith('#'):
|
|
|
|
|
|
|
+
|
|
|
|
|
+ row = [x.strip() for x in row]
|
|
|
|
|
+ first_cell = row[0]
|
|
|
|
|
+
|
|
|
|
|
+ if first_cell.startswith('#'):
|
|
|
continue
|
|
continue
|
|
|
- if line.startswith('END'):
|
|
|
|
|
|
|
+ if first_cell.startswith('END'):
|
|
|
break
|
|
break
|
|
|
- if line.startswith('Roster'):
|
|
|
|
|
|
|
+ if first_cell.startswith('Roster'):
|
|
|
func = _parse_roster
|
|
func = _parse_roster
|
|
|
- elif line.startswith('Name'):
|
|
|
|
|
|
|
+ elif first_cell.startswith('Name'):
|
|
|
func = _parse_staff
|
|
func = _parse_staff
|
|
|
- elif line.startswith('Shift requirements'):
|
|
|
|
|
|
|
+ elif first_cell.startswith('Shift requirements'):
|
|
|
func = _parse_reqs
|
|
func = _parse_reqs
|
|
|
- elif line.startswith('Block shared shifts'):
|
|
|
|
|
|
|
+ elif first_cell.startswith('Block shared shifts'):
|
|
|
func = _block_shared
|
|
func = _block_shared
|
|
|
else:
|
|
else:
|
|
|
- columns = line.split('\t')
|
|
|
|
|
-
|
|
|
|
|
if func == _parse_reqs:
|
|
if func == _parse_reqs:
|
|
|
- for i, v in func(columns).iteritems():
|
|
|
|
|
|
|
+ for i, v in func(row).iteritems():
|
|
|
reqs[i].append(v)
|
|
reqs[i].append(v)
|
|
|
elif func == _parse_roster:
|
|
elif func == _parse_roster:
|
|
|
- roster.update(_parse_roster(columns))
|
|
|
|
|
|
|
+ roster.update(_parse_roster(row))
|
|
|
elif func == _parse_staff:
|
|
elif func == _parse_staff:
|
|
|
- staff.append(_parse_staff(columns))
|
|
|
|
|
|
|
+ staff.append(_parse_staff(row))
|
|
|
elif func == _block_shared:
|
|
elif func == _block_shared:
|
|
|
- blocked.append([c for c in columns if c])
|
|
|
|
|
|
|
+ blocked.append([c for c in row if c])
|
|
|
|
|
|
|
|
- reqs = [reqs[i] for i in range(max(reqs.keys())+1)]
|
|
|
|
|
|
|
+ reqs = [reqs[i] for i in range(max(reqs.keys()) + 1)]
|
|
|
|
|
|
|
|
return staff, reqs, roster, blocked
|
|
return staff, reqs, roster, blocked
|
|
|
|
|
|
|
@@ -154,7 +162,7 @@ def _parse_shift(shift):
|
|
|
if shift.startswith('T/'):
|
|
if shift.startswith('T/'):
|
|
|
return None, None, float(shift[2:])
|
|
return None, None, float(shift[2:])
|
|
|
if shift == 'N':
|
|
if shift == 'N':
|
|
|
- return 21, 21+12, 12
|
|
|
|
|
|
|
+ return 21, 21 + 12, 12
|
|
|
if shift == 'R':
|
|
if shift == 'R':
|
|
|
return None, None, None
|
|
return None, None, None
|
|
|
if shift[0].isdigit():
|
|
if shift[0].isdigit():
|
|
@@ -175,6 +183,7 @@ def _get_staff_delta(member, roster):
|
|
|
|
|
|
|
|
return total_hours, total_hours - member['hours']
|
|
return total_hours, total_hours - member['hours']
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def get_cover(staff, roster):
|
|
def get_cover(staff, roster):
|
|
|
cover = collections.defaultdict(int)
|
|
cover = collections.defaultdict(int)
|
|
|
|
|
|
|
@@ -221,7 +230,7 @@ def print_covers(covers, roster, colormap):
|
|
|
print hr_str
|
|
print hr_str
|
|
|
|
|
|
|
|
|
|
|
|
|
-def evaluate(staff, reqs, roster):
|
|
|
|
|
|
|
+def evaluate(staff, reqs, roster, blocked):
|
|
|
total_abs_deltas = 0
|
|
total_abs_deltas = 0
|
|
|
|
|
|
|
|
for member in staff:
|
|
for member in staff:
|
|
@@ -238,16 +247,6 @@ def evaluate(staff, reqs, roster):
|
|
|
print color % ('\tHours: %s (%s%s)' % (total_hours, '+' if delta >= 0 else '', delta))
|
|
print color % ('\tHours: %s (%s%s)' % (total_hours, '+' if delta >= 0 else '', delta))
|
|
|
print ''
|
|
print ''
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-def run():
|
|
|
|
|
- staff, reqs, roster, blocked = parse()
|
|
|
|
|
-
|
|
|
|
|
- # staff: [{"name": string, "hours": float, "driver": bool, "gender": string}]
|
|
|
|
|
- # reqs: [[string]], e.g. [[], ["7/9", "12/21"]]
|
|
|
|
|
- # roster: {name: [string], "dows": [string], "dates": [int]}
|
|
|
|
|
-
|
|
|
|
|
- evaluate(staff, reqs, roster)
|
|
|
|
|
-
|
|
|
|
|
print ''
|
|
print ''
|
|
|
covers = [
|
|
covers = [
|
|
|
('Cover (overall)', get_cover(staff, roster)),
|
|
('Cover (overall)', get_cover(staff, roster)),
|
|
@@ -261,24 +260,20 @@ def run():
|
|
|
}
|
|
}
|
|
|
print_covers(covers, roster, colormap)
|
|
print_covers(covers, roster, colormap)
|
|
|
print ''
|
|
print ''
|
|
|
-
|
|
|
|
|
|
|
|
|
|
print ''
|
|
print ''
|
|
|
covers = []
|
|
covers = []
|
|
|
for i, names in enumerate(blocked):
|
|
for i, names in enumerate(blocked):
|
|
|
_staff = [s for s in staff if s['name'] in names]
|
|
_staff = [s for s in staff if s['name'] in names]
|
|
|
- covers.append(('Blocked (%i)' % (i+1), get_cover(_staff, roster)))
|
|
|
|
|
|
|
+ covers.append(('Blocked (%i)' % (i + 1), get_cover(_staff, roster)))
|
|
|
colormap = {
|
|
colormap = {
|
|
|
1: Color.BLUE,
|
|
1: Color.BLUE,
|
|
|
None: Color.RED,
|
|
None: Color.RED,
|
|
|
}
|
|
}
|
|
|
print_covers(covers, roster, colormap)
|
|
print_covers(covers, roster, colormap)
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
-
|
|
|
|
|
print ''
|
|
print ''
|
|
|
print ''
|
|
print ''
|
|
|
extra, missing = _get_req_deltas(reqs, roster, staff)
|
|
extra, missing = _get_req_deltas(reqs, roster, staff)
|
|
@@ -291,4 +286,26 @@ def run():
|
|
|
print '\t', date, v
|
|
print '\t', date, v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def run():
|
|
|
|
|
+
|
|
|
|
|
+ sheet = client.get_sheet('1JMP9QsXdPbvIVL01LFRAMqkMQZRL17gs_ZjKFBJjI8E', False)
|
|
|
|
|
+ if not sheet:
|
|
|
|
|
+ return
|
|
|
|
|
+ if not client.validate_sheet(sheet):
|
|
|
|
|
+ print 'Sheet is invalid. Aborting.'
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ ws_config, ws_eval = client.get_worksheets(sheet)
|
|
|
|
|
+
|
|
|
|
|
+ while True:
|
|
|
|
|
+ print ''
|
|
|
|
|
+ staff, reqs, roster, blocked = load_config(ws_config)
|
|
|
|
|
+ evaluate(staff, reqs, roster, blocked)
|
|
|
|
|
+ print ''
|
|
|
|
|
+
|
|
|
|
|
+ cmd = raw_input('> ')
|
|
|
|
|
+ if cmd == 'q':
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
run()
|
|
run()
|