Beispiel #1
0
def get_good_against(query, hero=None, early_update=False):
    if hero is None:
        query = query.split()
        hero = ' '.join(query[1:])
        hero = hero.strip()
    found_hero, hero_name = find_hero_name(hero)
    if not found_hero:
        return False, hero_name, ''
    image_path = os.path.join(constant.GOOD_HERO_IMAGE_PATH,
                              hero_name + '.png')

    threshold_update_time = constant.GOOD_HERO_UPDATE_TIME_THRESHOLD
    if early_update:
        threshold_update_time = threshold_update_time - constant.EARLY_BY
    if not is_file_old(image_path, threshold_update_time):
        return True, hero_name, image_path

    hero_info = scrap_heroes_info(hero_name)
    good_against_info = hero_info[1]
    good_against_heroes = good_against_info['Hero']
    good_against_heroes_list = list(good_against_heroes)
    good_against_heroes_image_path = get_icon_path(good_against_heroes_list,
                                                   icon_size='big')
    hero_image_path = get_icon_path([hero_name], icon_size='big')[0]
    image = make_hero_images(hero_image_path, good_against_heroes_image_path,
                             constant.GOOD_BG_IMAGE_PATH)
    cv2.imwrite(image_path, image)
    return True, hero_name, image_path
Beispiel #2
0
async def get_skill_build(query, hero=None, early_update=False):
    if hero is None:
        query = query.split()
        hero = ' '.join(query[1:])
        hero = hero.strip()
    found_hero, hero_name = find_hero_name(hero)
    if not found_hero:
        return False, hero_name, ''

    guide_image_path = os.path.join(constant.GUIDE_SAVE_PATH,
                                    hero_name + '.jpg')

    threshold_update_time = constant.GUIDE_THRESHOLD_IMAGE_UPDATE
    if early_update:
        threshold_update_time = threshold_update_time - constant.EARLY_BY
    if not is_file_old(guide_image_path, threshold_update_time):
        return True, hero_name, guide_image_path

    url = constant.GUIDE_URL.replace('<hero_name>', hero_name)

    talent_filename = hero + '_talent.jpg'
    talent_screenshot_path = os.path.join(constant.TEMP_IMAGE_PATH,
                                          talent_filename)
    await get_screenshot(constant.TALENT_SELECTOR, url, talent_screenshot_path)

    skill_filename = hero + '_skill.jpg'
    skill_screenshot_path = os.path.join(constant.TEMP_IMAGE_PATH,
                                         skill_filename)

    await get_screenshot(constant.SKILL_SELECTOR, url, skill_screenshot_path)

    talent_image = cv2.imread(talent_screenshot_path)
    talent_crop = crop_image(talent_image, constant.TALENT_CROP_COORDS)

    skill_image = cv2.imread(skill_screenshot_path)
    skill_crop = crop_image(skill_image, constant.SKILL_CROP_COORDS)

    hero_icon_path = os.path.join(constant.ICON_PATH_BIG, hero_name + '.png')
    hero_icon = cv2.imread(hero_icon_path)
    background_image = cv2.imread(constant.GUIDE_BACKGROUND_PATH)
    background_image = cv2.resize(background_image,
                                  (constant.GUIDE_BACKGROUND_SHAPE[1],
                                   constant.GUIDE_BACKGROUND_SHAPE[0]))
    background_image[
        constant.GUIDE_HERO_ICON_X_Y[0]:constant.GUIDE_HERO_ICON_X_Y[0] +
        hero_icon.shape[0],
        constant.GUIDE_HERO_ICON_X_Y[1]:constant.GUIDE_HERO_ICON_X_Y[1] +
        hero_icon.shape[1]] = hero_icon
    background_image = add_border_to_image(background_image,
                                           bordersize=10,
                                           rgb=[0, 0, 0])
    background_image = cv2.resize(background_image,
                                  (constant.GUIDE_BACKGROUND_SHAPE[1],
                                   constant.GUIDE_BACKGROUND_SHAPE[0]))
    final_image = np.concatenate([talent_crop, background_image, skill_crop],
                                 axis=0)
    cv2.imwrite(guide_image_path, final_image)
    return True, hero_name, guide_image_path
Beispiel #3
0
def get_current_trend():
    if not is_file_old(CT_IMAGE_PATH, CT_IMAGE_UPDATE_TIME_THRESHOLD):
        return CT_IMAGE_PATH

    current_trend_dataframe = get_current_hero_trends()
    current_trend_dataframe = current_trend_dataframe[:10]
    hero_name_df = current_trend_dataframe[current_trend_dataframe.columns[0]]
    numeric_df = current_trend_dataframe[current_trend_dataframe.columns[1:]]
    numeric_df = round_df_digits(numeric_df)
    heroes_list = hero_name_df.values.tolist()
    icon_path_list = get_icon_path(heroes_list)
    current_trend_dataframe = pd.concat([hero_name_df, numeric_df], axis=1)

    title = 'Current Heroes Trend \n\nWR: Win Rate                              PR: Pick Rate'
    image_path = render_mpl_table(current_trend_dataframe,
                                  icon_list=icon_path_list,
                                  header_columns=0,
                                  col_width=2.6,
                                  title=title,
                                  font_size=20)
    return image_path
Beispiel #4
0
def get_item_build(query, hero=None, early_update=False):
    if hero is None:
        query = query.split()
        hero = ' '.join(query[1:])
        hero = hero.strip()
    found_hero, hero_name = find_hero_name(hero)
    if not found_hero:
        return False, hero_name, ''

    item_build_path = os.path.join(constant.ITEM_IMAGE_PATH,
                                   hero_name + '.jpg')

    threshold_update_time = constant.ITEM_THRESHOLD_UPDATE
    if early_update:
        threshold_update_time = threshold_update_time - constant.EARLY_BY
    if not is_file_old(item_build_path, threshold_update_time):
        return True, hero_name, item_build_path

    item_build_info = scrap_item_info(hero_name)
    item_image = make_item_image(item_build_info, hero_name)
    cv2.imwrite(item_build_path, item_image,
                [int(cv2.IMWRITE_JPEG_QUALITY), 50])
    return True, hero_name, item_build_path
Beispiel #5
0
def get_top_games(length=10):
    """
	Creates a table image of current top live games
	:param length:
	:return: table image path
	"""
    # If TLG image already exist and hasnt been modified in given Threshold second return the same image
    if not is_file_old(constant.TLG_IMAGE_PATH,
                       constant.TLG_IMAGE_UPDATE_TIME_THRESHOLD):
        return constant.TLG_IMAGE_PATH

    game_list = dota_api.get_top_live_games()
    game_list = game_list['game_list']

    notable_player_dict = get_notable_hero_from_d2pt()
    results = []
    results.append(constant.TLG_CUSTOM_COLUMNS)
    for game in game_list:
        avg_mmr = game[constant.KEYWORD_AVERAGE_MMR]
        game_mode = GAME_MODE[game[constant.KEYWORD_GAME_MODE]]
        game_time = game[constant.KEYWORD_GAME_TIME]
        hour, sec = game_time // 60, game_time % 60
        game_time = str(hour) + ":" + str(sec)
        n_spectators = int(game[constant.KEYWORD_SPECTATORS])
        r_team_name = "Unknown"
        d_team_name = "Unknown"
        gold_lead = f"Radiant:{game[constant.KEYWORD_RADIANT_LEAD]}" if int(game[constant.KEYWORD_RADIANT_LEAD]) > 0\
             else f"Dire:{abs(int(game[constant.KEYWORD_RADIANT_LEAD]))}"
        r_kills = game[constant.KEYWORD_RADIANT_SCORE]
        d_kills = game[constant.KEYWORD_DIRE_SCORE]
        if constant.KEYWORD_RADIANT_TEAM in game:
            r_team_name = game[constant.KEYWORD_RADIANT_TEAM]
        if constant.KEYWORD_DIRE_TEAM in game:
            d_team_name = game[constant.KEYWORD_DIRE_TEAM]

        match_id = game[constant.KEYWORD_MATCH_ID]
        notable_players = '' if match_id not in notable_player_dict else notable_player_dict[
            match_id]
        results.append([
            notable_players, r_team_name, d_team_name, avg_mmr, game_mode,
            n_spectators, game_time, r_kills, d_kills, gold_lead
        ])

    results = [results[0]] + sorted(
        results[1:], key=lambda x: (x[4]), reverse=True)
    results = results[:length]
    results = pd.DataFrame(results[1:], columns=results[0])
    image_path = render_mpl_table(results,
                                  image_path=constant.TLG_IMAGE_PATH,
                                  header_columns=0,
                                  col_width=2.2,
                                  row_height=0.8,
                                  title='TOP LIVE GAMES',
                                  font_size=14,
                                  header_color='#4B4C51',
                                  row_colors=['#8c98b5', '#9dabcc'],
                                  edge_color='#464c5a')
    # image_path = DataFrame_to_image(results)
    image = cv2.imread(image_path)
    image = image[:, int(image.shape[1] * .09):-(int(image.shape[1] * .07))]
    cv2.imwrite(image_path, image)
    return image_path