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('--segment', dest='segments', action='append', default=[]) parser.add_argument('--split', dest='splits', action='append', default=[]) parser.add_argument('--splits', dest='splits_filename') args = parser.parse_args() rooms = Rooms.read(args.rooms_filename) doors = Doors.read(args.doors_filename, rooms) with open(args.filename) as csvfile: tailer = Tailer(csvfile) history_reader = read_transition_log_csv_incrementally( tailer, rooms, doors) while not tailer.at_eof(): history, transition = next(history_reader) # 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)) old_stats = SegmentStats(history, segments) old_rendered_stats = None while True: stats = SegmentStats(history, segments) rendered_stats = render_segment_stats(old_stats, stats) if rendered_stats != old_rendered_stats: print() print(rendered_stats) old_rendered_stats = rendered_stats old_stats = stats history, transition = next(history_reader)
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()
l = by_room_and_exit.get(key) if l: if len(l) == 1: print("Fixing entry door on line %d" % n) transition.id.entry_door = list( l.keys())[0].entry_door else: print( "More than one entry door found for %s to $s (line %d): %s" % (transition.id.room, transition.id.exit_room, n, repr(l))) else: # print("No entry door found for %s to %s (line %d)" % # (transition.id.room, transition.id.exit_room, n)) pass writer.writerow(transition.as_csv_row()) if __name__ == '__main__': parser = argparse.ArgumentParser(description='SM Room Timer') parser.add_argument('-i', '--input', dest='inputs', action='append') parser.add_argument('-o', '--output', dest='output', default=None) parser.add_argument('--rooms', dest='rooms_filename', default='rooms.json') parser.add_argument('--doors', dest='doors_filename', default='doors.json') args = parser.parse_args() rooms = Rooms.read(args.rooms_filename) doors = Doors.read(args.doors_filename, rooms) rebuild_history(rooms, doors, args.inputs, args.output)
from engine import Engine from curses_ui import UI from clock import Clock from autotracker import Autotracker if __name__ == '__main__': parser = argparse.ArgumentParser(description='Zebbo Probability Engine') parser.add_argument('--autotrack', dest='autotrack', action='store_true', default=False) parser.add_argument('--clock', dest='clock', action='store_true', default=False) args = parser.parse_args() items = Items.read('items.json') locations = Locations.read('locations.json') geography = Geography.read(locations, 'geography.json') rooms = Rooms.read('rooms.json') seeds = Seeds.read(items, locations, 'seeds.json') engine = Engine(items, locations, geography, rooms, seeds) if args.clock: clock = Clock() else: clock = None if args.autotrack: autotracker = Autotracker(engine, clock) poll = autotracker.poll else: poll = lambda: None UI.run(items=items, engine=engine, poll=poll, clock=clock)
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)