| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- import collections
- import fileinput
- import string
- class Color:
- HEADER = '\033[95m'
- OKBLUE = '\033[94m'
- OKGREEN = '\033[92m'
- WARNING = '\033[93m'
- FAIL = '\033[91m'
- ENDC = '\033[0m'
- BOLD = '\033[1m'
- UNDERLINE = '\033[4m'
- COLORS = {
- 1: Color.OKBLUE + '%s' + Color.ENDC,
- 2: Color.OKGREEN + '%s' + Color.ENDC,
- 3: Color.WARNING + '%s' + Color.ENDC,
- 3: Color.FAIL + '%s' + Color.ENDC,
- 4: Color.FAIL + '%s' + Color.ENDC,
- 5: Color.FAIL + '%s' + Color.ENDC,
- 6: Color.FAIL + '%s' + Color.ENDC,
- 7: Color.FAIL + '%s' + Color.ENDC,
- 8: Color.FAIL + '%s' + Color.ENDC,
- 9: Color.FAIL + '%s' + Color.ENDC,
- 10: Color.FAIL + '%s' + Color.ENDC,
- }
- _HRS = {
- 'N': (21, 9),
- }
- _IGNORED = {
- 'R',
- }
- _LEAVE_CODES = {
- 'AL',
- 'A/L',
- 'SD',
- 'BH',
- }
- _COLUMNS = list(string.ascii_uppercase[2:]) + ['AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH']
- _DRIVERS = {
- 'John Garbo PPIM/SN',
- 'Nonyelum Ifediora SCW',
- 'Katie Coyle SCW',
- 'Stanford Sokole SCW',
- 'Keith Duffy HCA',
- }
- totals_by_day = collections.defaultdict(int)
- totals_by_hours = {}
- drivers_by_hours = {}
- for line in fileinput.input():
- fs = line.split('\t')
- fs = [x.strip() for x in fs]
- if not any(fs):
- continue
-
- try:
- target = float(fs[1])
- except ValueError, e:
- print 'bad target hrs: %s' % fs
- continue
- name = fs[0].strip()
- driver = name in _DRIVERS
- total = 0
- prev_end = None
- errors = []
- for i, k in enumerate(fs[2:]):
- if not k:
- prev_end = None
- continue
- start = 0
- end = 0
- if k in _LEAVE_CODES:
- total += 8
- prev_end = None
- continue
- elif k in _IGNORED:
- prev_end = None
- continue
- elif k in _HRS:
- start, end = _HRS[k]
- elif k.startswith('T/'):
- hrs = float(k[2:])
- total += hrs
- continue
- elif '/' in k:
- start, end = k.split('/')
- start = int(start.strip())
- end = int(end.strip())
-
- else:
- errors.append('\tUnrecognized code: %s' % k)
- prev_end = None
- continue
- if end < start:
- end += 24
- total += end - start
- if end <= 24:
- hrs = [(i, j) for j in range(start, end)]
- else:
- hrs = [(i, j) for j in range(start, 24)] + [(i+1, j) for j in range(0, end-24)]
- for day, hr in hrs:
- totals_by_day[day] += 1
-
- if day not in totals_by_hours:
- totals_by_hours[day] = collections.defaultdict(int)
- drivers_by_hours[day] = collections.defaultdict(int)
-
- totals_by_hours[day][hr] += 1
- if driver:
- drivers_by_hours[day][hr] += 1
- if prev_end == 23 and start == 7:
- pass
- elif prev_end and (start + 24) < prev_end + 10:
- errors.append('\tWARNING: Possible bad start time for day %s' % _COLUMNS[i])
- prev_end = end
- delta = total-target
- delta_str = ('+' if delta > 0 else '') + str(delta)
- if -3 <= delta <= 4:
- print Color.OKGREEN + name + ': %s' % delta_str
- elif -6 <= delta <= 8:
- print Color.WARNING + name + ': %s' % delta_str
- else:
- print Color.FAIL + name + ': %s' % delta_str
- #print name
- # print '\tTarget: ', target
- # print '\tTotal: ', total
- # print '\tDelta: %s%s' % ('+' if delta > 0 else '', delta)
- print Color.ENDC
- if errors:
- print Color.FAIL
- for error in errors:
- print error
- print Color.ENDC
- print ''
- print ' Cover by hour Driver cover by hour Cover by day'
- for k, v in sorted(totals_by_day.items()):
- by_hr = ''.join([COLORS.get(totals_by_hours[k].get(hr), '%s') % totals_by_hours[k].get(hr, ' ') for hr in range(24)])
- drivers_by_hr = ''.join([COLORS.get(drivers_by_hours[k].get(hr), '%s') % drivers_by_hours[k].get(hr, ' ') for hr in range(24)])
- print ' '.join([
- _COLUMNS[k] + (' ' if len(_COLUMNS[k]) == 1 else ''),
- # '%02d' % v,
- by_hr,
- drivers_by_hr,
- '.' * (v/2),
- ])
- # print '%s%s %02d %s %s %s' % (_COLUMNS[k], v, by_hr, drivers_by_hr, '.' * (v/2))
|