Пример #1
0
Файл: game.py Проект: sjf/ana
    def get_game_for_client(self, client_id):
        # Check if client is already in active game
        game_state = self.db.get_client_game(client_id)
        if game_state:
            #log('Client in game', game_state.id)
            if game_state and game_state.end_time > lib.now():
                if game_state.has_client(client_id):
                    client = game_state.client(client_id)
                else:
                    client = ClientState(client_id)
                    self.db.add_client_to_game(game_state, client)
                return game_state, client

        # Try to add to the client to the most recently started game
        minimum_end_time = lib.now() + config.MIN_TIME_LEFT_MS
        game_state = self.db.get_latest_game(minimum_end_time)
        if not game_state:
            # Start a new game for the client
            game_state = self._new_game()
        else:
            log('Add client to existing game', game_state.id)

        log('Adding client to game ', game_state.id)
        client = ClientState(client_id)
        game_state = self.db.add_client_to_game(game_state, client)
        return game_state, client
Пример #2
0
def run_table_tickers():
    time = lib.now()
    tickers = get_table_tickers()
    time_ticker = lib.now()
    print 'Started Running: %s' % time_ticker
    count = 0
    pages_hit = 0
    reached = False
    try:
        for ticker in tickers:
            print ticker
            pages_hit += run_ticker(ticker)
            count += 1
            lib.sleep(count)
        db.close_db()
    finally:
        print 'Finished. Timing for getting tickers: %s, Timing for getting data: %s, Sleep count: %s, Pages Hit: %s' % (time_ticker - time, lib.now() - time_ticker, count/lib.sleep_mod, pages_hit)
Пример #3
0
def main():
    board = Board()

    import atexit
    original_terminal_state = lib.set_terminal_mode()
    atexit.register(lib.restore_terminal, original_terminal_state)

    # game loop
    while board.alive:
        board.draw()
        delay = board.stats.delay

        # if nothing's falling, wait a bit then spawn a piece
        if board.kind is None:
            lib.get_input(lib.now() + delay)
            if board.clear_lines():
                lib.get_input(lib.now() + delay)
            board.spawn()
            continue

        # let the player shift and rotate freely before the next down-step
        deadline = lib.now() + delay
        key = None
        while key != 'down':
            key = lib.get_input(deadline)
            if key == 'left':
                board.shift(-1)
            elif key == 'right':
                board.shift(1)
            elif key == 'up':
                board.rotate()
            elif key == 'space':
                board.hard_drop()
                break
            else:
                break

        # down-step
        if board.kind is not None:
            board.descend()

    board.draw()
    print()
    print('GAME OVER!')
Пример #4
0
def run_nasdaq_nyse():
    nasdaq, nyse = get_nasdaq_nyse_data()
    time = lib.now()
    print 'Started Running: %s' % time
    count = 0
    print 'Nasdaq Commencing: %s' % lib.now()
    for ticker in nasdaq:
        print ticker
        run_ticker(ticker)
        count += 1
        lib.sleep(count)
    nasdaq_time = lib.now()
    print 'Nasdaq Finished, count: %s' % count
    print 'NYSE Commencing: %s' % lib.now()
    for ticker in nyse:
        print ticker
        run_ticker(ticker)
        count += 1
        lib.sleep(count)
    nyse_time = lib.now()
    print 'NYSE Finished, count: %s' % count
    db.close_db()
    print 'Finished. Timing for nasdaq: %s, Timing for nyse: %s' % (nasdaq_time - time, nyse_time - nasdaq_time)
Пример #5
0
 def remaining_secs(self):
   return (self.end_time - now()) // 1000
Пример #6
0
Файл: game.py Проект: sjf/ana
 def _new_game(self):
     word, subs = self._pick_word()
     time = lib.now()
     game_state = GameState(time, time + config.TIME_LIMIT_MS, word, subs)
     self.db.put(game_state)
     return game_state
Пример #7
0
            lib.returnTicker(forceUpdate = True)
            lib.tradeHistory(forceUpdate = True)
        """

    if did_act:
        next_act[currency] = lib.unixtime() + wait_before_next_trade

    if index == 0:
        oldline = ""
        line = ""
        for i in range(max(ui_update * subtime, 1), 0, -1):
            if line != oldline:
                print(line)
                oldline = line

            line = ("\033[0;0H {} {:35} {:.3f}{:>" + str(running.graph_len - 5) + "}  {}").format( time.strftime("%Y-%m-%d %H:%M:%S", lib.now()), "", margin_buy, "{:.3f}".format(margin_sell), wait_before_next_trade)
            lib.wait(1 / subtime)

            if select.select([sys.stdin,],[],[],0.0)[0]:
                kc = sys.stdin.read(1)
                if kc == 'w':
                    margin_buy -= 0.001 
                if kc == 'e': 
                    margin_buy += 0.001
                if kc == 's': 
                    margin_sell -= 0.001
                if kc == 'd': 
                    margin_sell += 0.001

                if kc == 'x': 
                    wait_before_next_trade -= 5
Пример #8
0
def record_options(calls, puts, ticker):
    now = lib.now()
    if len(calls) > 0:
        db.record_calls(calls, now, ticker)
    if len(puts) > 0:
        db.record_puts(puts, now, ticker)