| 1234567891011121314151617181920212223242526272829303132 |
- import collections
- def parse_shift(shift):
- if shift in ['ML', 'AL', 'A/L', 'BH', 'SD']:
- return None, None, 8
- if shift.startswith('T/'):
- return None, None, float(shift[2:])
- if shift == 'N':
- return 21, 21 + 12, 12
- if shift == 'R':
- return None, None, None
- if shift[0].isdigit():
- start, end = shift.split('/')
- return float(start), float(end), float(end) - float(start)
- return None, None, None
- def get_cover(staff, roster):
- cover = collections.defaultdict(int)
- for member in staff:
- for date, shift in zip(roster['dates'], roster[member['name']]):
- if shift:
- start, end, _ = parse_shift(shift)
- if start is not None:
- for hr in range(int(start), int(end)):
- _date = date if hr < 24 else date + 1
- cover[_date, hr % 24] += 1
- return cover
|