"""Review-pass checks (added in revision 2). 1. Re-validate the four rows of output/schedule.csv directly against inputs/. 2. Sensitivity: allow the follow-up to start any time after the review (not only directly after) as long as review + follow-up stay in one availability window. 3. Sensitivity: show what the 10:00 Room B slot fails on, with and without the update.txt rule that the room must be free during setup. """ import csv, os, sys here = os.path.dirname(os.path.abspath(__file__)) def find(p): for base in ('.', '..', here, os.path.join(here, '..')): q = os.path.join(base, p) if os.path.exists(q): return q sys.exit('cannot find ' + p) def m(t): h, mm = t.split(':'); return int(h) * 60 + int(mm) def f(x): return '%02d:%02d' % (x // 60, x % 60) avail, rooms = {}, {} for r in csv.DictReader(open(find('inputs/availability.csv'))): avail.setdefault(r['person'], []).append((m(r['available_start']), m(r['available_end']))) for r in csv.DictReader(open(find('inputs/rooms.csv'))): rooms.setdefault(r['room'], []).append((m(r['available_start']), m(r['available_end']))) def win(wins, s, e): for w in wins: if w[0] <= s and e <= w[1]: return w return None def day_ok(s, e): return 540 <= s and e <= 1020 and (e <= 720 or s >= 780) def feasible(room, s, fu_start, setup_needs_room=True): e = s + 45 if not all(day_ok(a, b) for a, b in ((s - 30, s), (s - 10, s), (s, e), (fu_start, fu_start + 15))): return False if not all(win(avail[p], s, e) for p in ('Maya', 'Theo', 'Jules')): return False if not win(avail['Theo'], s - 30, e): return False if not win(rooms[room], s - 10 if setup_needs_room else s, e): return False if fu_start < e: return False return all(win(avail[p], s, fu_start + 15) for p in ('Maya', 'Jules')) # 1. validate schedule.csv rows = {r['item']: r for r in csv.DictReader(open(os.path.join(here, 'schedule.csv')))} prep, setup, rev, fu = (rows[k] for k in ('Theo prep', 'Room setup', 'Main launch review', 'Decision follow-up')) s = m(rev['start_pacific']) assert m(rev['end_pacific']) == s + 45 assert (m(prep['start_pacific']), m(prep['end_pacific'])) == (s - 30, s) assert (m(setup['start_pacific']), m(setup['end_pacific'])) == (s - 10, s) assert m(fu['end_pacific']) - m(fu['start_pacific']) == 15 room = rev['location'].replace('Room ', '') assert setup['location'] == rev['location'] and room in ('B', 'C') assert feasible(room, s, m(fu['start_pacific'])) print('1. schedule.csv rows satisfy all encoded constraints: review %s Room %s' % (f(s), room)) # 2. gap-tolerant follow-up found = [] for st in range(540, 1020): for rm in sorted(rooms): if any(feasible(rm, st, g) for g in range(st + 45, 1020)): found.append((st, rm)) print('2. follow-up may start any time after review: earliest', f(found[0][0]), 'Room', found[0][1], '| morning feasible:', [(f(a), b) for a, b in found if a < 720], '| latest', f(found[-1][0]), 'Room', found[-1][1]) assert found[0] == (s, room) # 3. the 10:00 Room B slot print('3. 10:00 Room B with update.txt setup rule:', feasible('B', 600, 645), '| if setup did NOT need the room calendar:', feasible('B', 600, 645, setup_needs_room=False)) print(' 10:01-10:09 Room B feasible (any):', any(feasible('B', t, t + 45) for t in range(601, 610)))