|
@@ -0,0 +1,182 @@
|
|
|
|
|
+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))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|