def main(): parser = argparse.ArgumentParser(description='SM Room Timer') parser.add_argument('-f', '--file', dest='filename', default=None) parser.add_argument('--rooms', dest='rooms_filename', default='rooms.json') parser.add_argument('--doors', dest='doors_filename', default='doors.json') parser.add_argument('--segment', dest='segments', action='append', default=[]) parser.add_argument('--split', dest='splits', action='append', default=[]) parser.add_argument('--splits', dest='splits_filename') parser.add_argument('--brief', action='store_true') args = parser.parse_args() rooms = Rooms.read(args.rooms_filename) doors = Doors.read(args.doors_filename, rooms) history = read_transition_log(args.filename, rooms, doors) # ids = build_route(history) if args.build_route else history.keys() route = build_route(history) # TODO: Needed? split_names = args.splits if args.splits_filename is not None: with open(args.splits_filename) as f: lines = [ line for line in f.readlines() if not line.startswith('#') and not line.isspace() ] split_names.extend([ line.strip() for line in lines ]) segments = [ segment_from_name(name, rooms, route) for name in args.segments ] splits = [ transition_from_name(name, rooms, route) for name in split_names ] segments.extend(segments_from_splits(route, splits)) if not args.brief: segment_history = build_segment_history(segments, history) print_room_stats(history, segment_history, segments) print_segment_stats(history, segments)
def main(): parser = argparse.ArgumentParser(description='SM Room Timer') parser.add_argument('-f', '--file', dest='filename', default=None) parser.add_argument('--rooms', dest='rooms_filename', default='rooms.json') parser.add_argument('--doors', dest='doors_filename', default='doors.json') parser.add_argument('--debug', dest='debug', action='store_true') parser.add_argument('--debug-log', dest='debug_log_filename') parser.add_argument('--verbose', dest='verbose', action='store_true') parser.add_argument('--usb2snes', action='store_true') parser.add_argument('--route', action='store_true') parser.add_argument('--rebuild', action='store_true') # parser.add_argument('--segment', action='append', required=True) args = parser.parse_args() rooms = Rooms.read(args.rooms_filename) doors = Doors.read(args.doors_filename, rooms) route = Route() if args.route else DummyRoute() if args.filename and need_rebuild(args.filename): if not args.rebuild: print( "File needs to be rebuilt before it can be used; run rebuild_history.py or pass --rebuild to this script." ) sys.exit(1) backup_and_rebuild(rooms, doors, args.filename) if args.debug_log_filename: debug_log = open(args.debug_log_filename, 'a') verbose = True elif args.debug: debug_log = sys.stdout verbose = True else: debug_log = None verbose = args.verbose frontend = SegmentTimerTerminalFrontend(verbose=verbose, debug_log=debug_log) if args.filename is not None and os.path.exists(args.filename): history = read_transition_log(args.filename, rooms, doors) else: history = History() for tid in history: route.record(tid) if route.complete: break print('Route is %s' % ('complete' if route.complete else 'incomplete')) transition_log = FileTransitionLog( args.filename) if args.filename is not None else NullTransitionLog() tracker = SegmentTimeTracker(history, transition_log, route, on_new_room_time=frontend.new_room_time) state_reader = ThreadedStateReader(rooms, doors, usb2snes=args.usb2snes, logger=frontend) state_reader.start() try: timer = SegmentTimer(frontend, state_reader, on_transitioned=tracker.transitioned, on_state_change=frontend.state_changed, on_reset=tracker.room_reset) while state_reader.is_alive(): timer.poll() finally: state_reader.stop()
parser.add_argument('--rooms', dest='rooms_filename', default='rooms.json') parser.add_argument('--doors', dest='doors_filename', default='doors.json') parser.add_argument('--route', dest='build_route', action='store_true') parser.add_argument('--start', dest='start_room', default=None) parser.add_argument('--end', dest='end_room', default=None) parser.add_argument('--items', action='store_true') parser.add_argument('--beams', action='store_true') parser.add_argument('--iqr', action='store_true') parser.add_argument('--most-recent', action='store_true') parser.add_argument('--exclude-doors', action='store_true') parser.add_argument('--doors-only', action='store_true') args = parser.parse_args() rooms = Rooms.read(args.rooms_filename) doors = Doors.read(args.doors_filename, rooms) history = read_transition_log(args.filename, rooms, doors) ids = build_route(history) if args.build_route else history.keys() printing = False if args.start_room else True all_stats = [] num_rooms = 0 for id in ids: if args.start_room == id.room.name: printing = True if args.end_room == id.room.name: break if not printing: continue num_rooms += 1 # TODO: We should keep stats for real+door, rather than keeping # those separately
def main(): parser = argparse.ArgumentParser(description='SM Room Timer') parser.add_argument('-f', '--file', dest='filename', default=None) parser.add_argument('--rooms', dest='rooms_filename', default='rooms.json') parser.add_argument('--doors', dest='doors_filename', default='doors.json') parser.add_argument('--debug', dest='debug', action='store_true') parser.add_argument('--debug-log', dest='debug_log_filename') parser.add_argument('--verbose', dest='verbose', action='store_true') parser.add_argument('--usb2snes', action='store_true') parser.add_argument('--route', action='store_true') parser.add_argument('--rebuild', action='store_true') parser.add_argument('--port', type=int, default=15000) parser.add_argument('--headless', action='store_true') # parser.add_argument('--segment', action='append', required=True) args = parser.parse_args() rooms = Rooms.read(args.rooms_filename) doors = Doors.read(args.doors_filename, rooms) route = Route() if args.route else DummyRoute() if args.filename and need_rebuild(args.filename): if not args.rebuild: print( "File needs to be rebuilt before it can be used; run rebuild_history.py or pass --rebuild to this script." ) sys.exit(1) backup_and_rebuild(rooms, doors, args.filename) if args.debug_log_filename: debug_log = open(args.debug_log_filename, 'a') verbose = True elif args.debug: debug_log = sys.stdout verbose = True else: debug_log = None verbose = args.verbose shutdown = [] try: server = WebsocketServer(port=args.port) server.start() shutdown.append(server.stop) json_generator = JsonEventGenerator(verbose=verbose, debug_log=debug_log, on_event=server.broadcast) if args.filename is not None and os.path.exists(args.filename): history = read_transition_log(args.filename, rooms, doors) else: history = History() for tid in history: route.record(tid) if route.complete: break print('Route is %s' % ('complete' if route.complete else 'incomplete')) transition_log = FileTransitionLog( args.filename) if args.filename is not None else NullTransitionLog( ) tracker = SegmentTimeTracker( history, transition_log, route, on_new_room_time=json_generator.new_room_time) timer_thread = TimerThread(history, rooms, doors, transition_log, route, json_generator, server, usb2snes=args.usb2snes) timer_thread.start() shutdown.append(timer_thread.stop) if args.headless: timer_thread.join() else: dirname = os.path.dirname(os.path.realpath(__file__)) filename = 'sm_web_timer.html' port = args.port url = 'file://%s/%s?port=%s' % (dirname, filename, port) browser = Browser(sys.argv, url) sys.exit(browser.run()) finally: for f in reversed(shutdown): try: f() except Exception as e: print(e)