Example #1
0
def test_ocr_valu36():  # ok
    log = logging.getLogger(__name__)
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    table_scraper = TableScraper(table_dict)

    table_scraper.screenshot = Image.open(
        os.path.join(os.environ['test_test'], '5.png'))
    table_scraper.crop_from_top_left_corner2(select_table=2)
    if is_debug:
        # table_scraper.screenshot.save('log/pics/table1.png')
        file_name = get_dir(os.path.join('log', 'pics', 'table_label.png'))
        save_table_rectangle_cv2(table_scraper.screenshot, table_dict,
                                 file_name)
    table_scraper.get_pots()
    table_scraper.get_players_funds()
    table_scraper.get_player_pots()
    log.info(f"{table_scraper.total_pot}")
    log.info(f"{table_scraper.player_funds}")
    log.info(f"{table_scraper.player_pots}")
    pytest.assume(table_scraper.total_pot == 12.0)
    pytest.assume(
        table_scraper.player_funds == [145.5, 100.0, 20.0, 18.0, 187.5, 94.5])
    pytest.assume(
        table_scraper.player_pots == [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0])
Example #2
0
def test_ocr_valu22():  # ok
    # init_logger(screenlevel=logging.DEBUG, filename='test-ocr', logdir='log')
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    table_scraper = TableScraper(table_dict)

    table_scraper.screenshot = Image.open(
        os.path.join(os.environ['test_test'], '2.png'))
    table_scraper.crop_from_top_left_corner2(select_table=3)
    if is_debug:
        # table_scraper.screenshot.save('log/pics/table1.png')
        file_name = get_dir(os.path.join('log', 'pics', 'table_label.png'))
        save_table_rectangle_cv2(table_scraper.screenshot, table_dict,
                                 file_name)
    table_scraper.get_pots()
    table_scraper.get_players_funds()
    table_scraper.get_player_pots()
    log.info(f"{table_scraper.total_pot}")
    log.info(f"{table_scraper.player_funds}")
    log.info(f"{table_scraper.player_pots}")
    pytest.assume(table_scraper.total_pot == 12.5)
    pytest.assume(
        table_scraper.player_funds == [154.0, 104.5, 90.0, 95.0, 20.0, 190.0])
    pytest.assume(table_scraper.player_pots == [
        2.0, 0.5, 10.0, -1.0, -1.0, -1.0
    ])  # [2.0, 0.5, 10.0, -1.0, 4.0, -1.0]
Example #3
0
def test_ocr_valu10():  # ok
    log = logging.getLogger(__name__)
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    table_scraper = TableScraper(table_dict)

    table_scraper.screenshot = Image.open(
        os.path.join(os.environ['test_src'], '1.png'))
    table_scraper.crop_from_top_left_corner2(select_table=3)
    if is_debug:
        # table_scraper.screenshot.save('log/pics/table1.png')
        file_name = get_dir(os.path.join('log', 'pics', 'table_label.png'))
        save_table_rectangle_cv2(table_scraper.screenshot, table_dict,
                                 file_name)
    table_scraper.get_pots()
    table_scraper.get_players_funds()
    table_scraper.get_player_pots()
    log.info(f"{table_scraper.total_pot}")
    log.info(f"{table_scraper.player_funds}")
    log.info(f"{table_scraper.player_pots}")
    pytest.assume(table_scraper.total_pot == 5.0)  # 73.0
    pytest.assume(table_scraper.player_funds == [
        25.0, 11.0, 98.0, 188.5, 50.5, 100.0
    ])  # [29.0, 6.0, 98.0, 108.9, 30.5, 10.0]
    pytest.assume(table_scraper.player_pots == [
        -1.0, -1.0, 2.0, 2.0, 1.0, -1.0
    ])  # [-1.0, -1.0, 25.0, -1.0, 1.0, -1.0]
Example #4
0
def test_ocr_valu8():  # ok
    log = logging.getLogger(__name__)
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    table_scraper = TableScraper(table_dict)

    table_scraper.screenshot = Image.open(
        os.path.join(os.environ['test_src'], '1.png'))
    table_scraper.crop_from_top_left_corner2(select_table=0)
    if is_debug:
        # table_scraper.screenshot.save('log/pics/table1.png')
        file_name = get_dir(os.path.join('log', 'pics', 'table_label.png'))
        save_table_rectangle_cv2(table_scraper.screenshot, table_dict,
                                 file_name)
    table_scraper.get_pots()
    table_scraper.get_players_funds()
    table_scraper.get_player_pots()

    pytest.assume(table_scraper.total_pot == 12.5)
    pytest.assume(
        table_scraper.player_funds == [23.0, 100.0, 42.0, 23.0, 97.5,
                                       102.0])  # pass
    pytest.assume(
        table_scraper.player_pots == [-1.0, -1.0, 6.0, -1.0, -1.0,
                                      -1.0])  # Ghost number
Example #5
0
def test_ocr_valu6():  # ok
    log = logging.getLogger(__name__)
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    table_scraper = TableScraper(table_dict)

    table_scraper.screenshot = Image.open(
        os.path.join(os.environ['test_src1'], '9.png'))
    table_scraper.crop_from_top_left_corner2(select_table=0)
    if is_debug:
        # table_scraper.screenshot.save('log/pics/table1.png')
        file_name = get_dir(os.path.join('log', 'pics', 'table_label.png'))
        save_table_rectangle_cv2(table_scraper.screenshot, table_dict,
                                 file_name)
    table_scraper.get_pots()
    table_scraper.get_players_funds()
    table_scraper.get_player_pots()
    log.info(f"{table_scraper.total_pot}")
    log.info(f"{table_scraper.player_funds}")
    log.info(f"{table_scraper.player_pots}")
    # assert table_scraper.total_pot == 4
    pytest.assume(table_scraper.total_pot == 4.0)  # 0.4 == 4.0 capture err
    pytest.assume(
        table_scraper.player_funds == [16.5, 23.5, 225.0, 65.5, 101.5, 100.0])
    pytest.assume(
        table_scraper.player_pots == [-1.0, 0.5, 1.0, 2.5, -1.0, -1.0])
Example #6
0
def test_4ocr_valu44():  # ok
    log = logging.getLogger(__name__)
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    table_scraper = TableScraper(table_dict)
    file_name = get_dir(os.path.join('log', 'pics', 'table_b_16.png'))

    table_scraper.screenshot = Image.open(file_name)
    # table_scraper.crop_from_top_left_corner2(select_table=0)
    if is_debug:
        # table_scraper.screenshot.save('log/pics/table1.png')
        file_name = get_dir(os.path.join('log', 'pics', 'table_label.png'))
        save_table_rectangle_cv2(table_scraper.screenshot, table_dict,
                                 file_name)
    table_scraper.get_pots()
    table_scraper.get_players_funds()
    table_scraper.get_player_pots()
    log.info(f"{table_scraper.total_pot}")
    log.info(f"{table_scraper.current_round_pot}")
    log.info(f"{table_scraper.player_funds}")
    log.info(f"{table_scraper.player_pots}")
    # pytest.assume(table_scraper.total_pot == 4.0)
    # assert table_scraper.total_pot == 4.0
    # pytest.assume(table_scraper.player_pots == [-1.0, -1.0, -1.0, 0.5, -1.0, 1.0])
    pytest.assume(table_scraper.current_round_pot == 2.0)
Example #7
0
def test_get_table_delta1():
    p = StrategyHandler()
    p.read_strategy()
    p.read_strategy()
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    gui_signals = MagicMock()
    gui_signals.select_table = 0  # select table
    game_logger = GameLogger()
    version = 4.21

    log_file = get_dir(os.path.join("log", 'delta.txt'))
    f = open(log_file, "a")
    f.write("New Project\n")
    f.close()
    count = 0
    while True:
        t = TableScreenBased(p, table_dict, gui_signals, game_logger, version)
        ready = False
        while (not ready):
            ready = t.take_screenshot(True, p) and \
                    t.get_top_left_corner(p, gui_signals) and \
                    t.get_gg_poker()
        log.debug(f"Top left corner: {t.tlc}")
        log.debug(f"GG Poker : {t.gg_poker}")
        x, y = get_table_delta()
        update_delta(x, y)

        delta_x = 308 + (t.tlc[0] - t.gg_poker[0])
        delta_y = 287 + (t.tlc[1] - t.gg_poker[1])
        f = open(log_file, "a")
        f.write(f"delta_x, delta_y : {delta_x}, {delta_y} ")
        f.write("\n")
        f.write("---------------------------------------------------")
        f.write("\n")
        f.close()
        log.debug(f"delta_x, delta_y : {delta_x}, {delta_y} ")
        file_name = get_dir(os.path.join('log', 'pics', 'table_update_delta.png'))
        file_name1 = get_dir(os.path.join('log', 'pics', 'table_default_delta.png'))
        file_name2 = get_dir(os.path.join('log', 'pics', 'table_default_origin.png'))
        """
        Move table by delta_x = -8 , delta_y = -5 from config.ini
        """
        save_table_rectangle_cv2(t.screenshot, table_dict, file_name)
        reset_delta()
        save_table_rectangle_cv2(t.screenshot, table_dict, file_name1)
        t.screenshot.save(file_name2)
        count += 1
        if count >=1:
            reset_delta()
            break

    return True
Example #8
0
def test_get_table_delta_rel2():
    p = StrategyHandler()
    p.read_strategy()
    p.read_strategy()
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    gui_signals = MagicMock()
    gui_signals.select_table = 0  # select table
    game_logger = GameLogger()
    version = 4.21
    log_file = get_dir(os.path.join("log", 'delta.txt'))
    f = open(log_file, "a")
    f.write("New Project\n")
    f.close()
    count = 0
    prefix = 'e'

    while True:
        t = TableScreenBased(p, table_dict, gui_signals, game_logger, version)

        t.screenshot = Image.open(get_dir(os.path.join('log', 'pics', 'table_' + prefix + '0.png')))
        t.get_gg_poker_rel()

        x = 308 - t.gg_poker_rel[0]
        y = 287 - t.gg_poker_rel[1]
        update_delta(x, y)  # update delta in config.ini
        f = open(log_file, "a")
        f.write(f"delta_x, delta_y : {x}, {y} ")
        f.write("\n")
        f.write("---------------------------------------------------")
        f.write("\n")
        f.close()
        log.debug(f"delta_x, delta_y : {x}, {y} ")
        file_name = get_dir(os.path.join('log', 'pics', 'table_update_delta.png'))
        file_name1 = get_dir(os.path.join('log', 'pics', 'table_default_delta.png'))
        """
        Move table by delta_x = -8 , delta_y = -5 from config.ini
        """
        save_table_rectangle_cv2(t.screenshot, table_dict, file_name)
        # reset delta to default in config.ini
        reset_delta()
        save_table_rectangle_cv2(t.screenshot, table_dict, file_name1)
        count += 1
        if count >=1:
            break

    return True
Example #9
0
def test_label_pos0():  # ok
    log = logging.getLogger(__name__)
    mongo = MongoManager()
    table_dict = mongo.get_table('GG_6TABLE')
    table_scraper = TableScraper(table_dict)
    prefix = 'b_16'
    table_scraper.screenshot = Image.open(get_dir(os.path.join('log', 'pics', 'table_' + prefix + '.png')))
    for i in [0]:
        for j in [0]:
            # table_scraper.crop_from_top_left_corner2(select_table=0)
            if is_debug:
                file_name = get_dir(os.path.join('log', 'pics', 'table_label_pos_' + str(i) + '_' + str(j) + '.png'))
                """
                Move table by delta_x = -8 , delta_y = -5 from config.ini
                """
                save_table_rectangle_cv2(table_scraper.screenshot, table_dict, file_name)
    return True