"""Checks for Task 8 deliverables. Run from the workspace root (needs inputs/ and output/). Standard library only. Prints results; changes no files.""" import csv, re, datetime def m(t): h, mi = t.split(':') return int(h) * 60 + int(mi) def f(x): return f"{x // 60:02d}:{x % 60:02d}" avail = {} for r in csv.DictReader(open('inputs/availability.csv')): avail.setdefault(r['person'], []).append((m(r['available_start']), m(r['available_end']))) rooms = {} for r in csv.DictReader(open('inputs/rooms.csv')): rooms.setdefault(r['room'], []).append((m(r['available_start']), m(r['available_end']))) DAY0, DAY1, L0, L1 = m('09:00'), m('17:00'), m('12:00'), m('13:00') def win(wins, s, e): for a, b in wins: if a <= s and e <= b: return (a, b) return None def ok_day(s, e): return DAY0 <= s and e <= DAY1 and not (s < L1 and e > L0) def check(room, S): """Return (list of violated hard constraints, earliest follow-up start or None).""" E = S + 45 reasons = [] for p in ('Maya', 'Theo', 'Jules'): if not win(avail[p], S, E): reasons.append(f'{p} not available for review {f(S)}-{f(E)}') if not win(avail['Theo'], S - 30, S): reasons.append(f'Theo prep {f(S-30)}-{f(S)} outside his window') if not win(rooms[room], S - 10, E): reasons.append(f'Room {room} not free for setup+review {f(S-10)}-{f(E)}') wm, wj = win(avail['Maya'], S, E), win(avail['Jules'], S, E) fu = None if wm and wj: for F in range(E, DAY1): if wm[0] <= F and F + 15 <= wm[1] and wj[0] <= F and F + 15 <= wj[1] and ok_day(F, F + 15): fu = F break if fu is None: reasons.append(f'no 15-min follow-up after {f(E)} inside Maya {f(wm[0])}-{f(wm[1])} and Jules {f(wj[0])}-{f(wj[1])}') for s, e, n in ((S - 30, S, 'prep'), (S - 10, S, 'setup'), (S, E, 'review')): if not ok_day(s, e): reasons.append(f'{n} violates work hours/lunch') return reasons, fu feasible = [] for room in sorted(rooms): for S in range(DAY0, DAY1): r, fu = check(room, S) if not r: feasible.append((S, room, fu)) feasible.sort() print('Feasible review starts (1-minute grid, 09:00-17:00):') for room in sorted(rooms): ss = [S for S, rm, _ in feasible if rm == room] print(' Room', room, f(min(ss)) + ' to ' + f(max(ss)) if ss else 'none') print(' Any feasible start before 12:00:', any(S < L0 for S, _, _ in feasible)) print(' Earliest:', f(feasible[0][0]), 'Room', feasible[0][1], 'follow-up', f(feasible[0][2])) print('\nCandidates named in risk-note.md:') for room, t in (('B', '10:00'), ('B', '10:10'), ('C', '09:45'), ('C', '10:00'), ('C', '13:55'), ('B', '14:00'), ('B', '14:10')): r, fu = check(room, m(t)) nora = bool(win(avail['Nora'], m(t), m(t) + 45)) print(f' Room {room} {t}: Nora free={nora};', r if r else f'FEASIBLE (follow-up {f(fu)})') print(' Nora free for chosen 14:00 review:', bool(win(avail['Nora'], m('14:00'), m('14:45')))) print('\nschedule.csv:') S, room, fu = feasible[0] expected = { 'Theo prep': (S - 30, S), 'Room setup': (S - 10, S), 'Main launch review': (S, S + 45), 'Decision follow-up': (fu, fu + 15), } with open('output/schedule.csv', newline='') as fh: raw = list(csv.reader(fh)) print(' field counts per line:', [len(x) for x in raw]) rows = list(csv.DictReader(open('output/schedule.csv', newline=''))) allok = len(rows) == 4 and len(set(len(x) for x in raw)) == 1 for r in rows: s, e = m(r['start_pacific']), m(r['end_pacific']) d = datetime.date.fromisoformat(r['date']) def utc(t): dt = datetime.datetime.combine(d, datetime.time(t // 60, t % 60)) + datetime.timedelta(hours=7) return dt.strftime('%Y-%m-%dT%H:%MZ') ok = ((s, e) == expected[r['block']] and r['start_utc'] == utc(s) and r['end_utc'] == utc(e) and int(r['duration_min']) == e - s and d.strftime('%A') == 'Tuesday') allok &= ok print(' ', r['block'], r['start_pacific'], r['end_pacific'], r['start_utc'], r['end_utc'], 'OK' if ok else 'MISMATCH') rev = [r for r in rows if r['block'] == 'Main launch review'][0] allok &= rev['location'] == 'Room ' + room and rev['required_people'] == 'Maya; Theo; Jules' print(' review location/required:', rev['location'], '|', rev['required_people']) print(' RESULT:', 'ALL OK' if allok else 'PROBLEM') txt = open('output/risk-note.md').read() print('\nrisk-note.md word count (whitespace split, includes table pipes):', len(txt.split())) inv = open('output/invitation-draft.txt').read() print('\ninvitation-draft.txt string checks:') for k in ('NOT SENT', 'Required: Maya (lead), Theo (engineer), Jules (design)', 'Optional: Nora', 'Room C', 'Agenda', '14:00-14:45 Pacific / 21:00-21:45 UTC', '14:45-15:00 Pacific / 21:45-22:00 UTC', 'security owner'): print(' ', repr(k), k in inv) # every "HH:MM-HH:MM Pacific / HH:MM-HH:MM UTC" pair in the invitation must differ by exactly 7h pairs = re.findall(r'(\d\d:\d\d)-(\d\d:\d\d) Pacific(?: /| \()\s*(\d\d:\d\d)-(\d\d:\d\d) UTC', inv) print(' Pacific/UTC pairs found:', len(pairs), 'all +7h:', all(m(c) - m(a) == 420 and m(d) - m(b) == 420 for a, b, c, d in pairs)) fb, fbfu = check('B', m('14:10')) print(' fallback Room B 14:10 feasible:', not fb, 'follow-up', f(fbfu) if fbfu else None)