libs.functions.compose.badge
libs/functions/compose/badge.py
1""" 2libs/functions/compose/badge.py 3""" 4 5import math 6 7import libs.global_value as g 8from libs.domain import aggregate 9 10 11def degree(game_count: int = 0) -> str: 12 """ 13 プレイしたゲーム数に対して表示される称号を返す 14 15 Args: 16 game_count (int, optional): ゲーム数. Defaults to 0. 17 18 Returns: 19 str: 表示する称号 20 21 """ 22 badge: str = "" 23 24 if g.adapter.conf.badge_degree: 25 if degree_list := g.cfg.setting.main_parser.get("degree", "badge", fallback=""): 26 degree_badge = degree_list.split(",") 27 else: 28 return "" 29 if counter_list := g.cfg.setting.main_parser.get("degree", "counter", fallback=""): 30 degree_counter = list(map(int, counter_list.split(","))) 31 for idx, val in enumerate(degree_counter): 32 if game_count >= val: 33 badge = degree_badge[idx] 34 35 return badge 36 37 38def status(game_count: int = 0, win: int = 0) -> str: 39 """ 40 勝率に対して付く調子バッジを返す 41 42 Args: 43 game_count (int, optional): ゲーム数. Defaults to 0. 44 win (int, optional): 勝ち数. Defaults to 0. 45 46 Returns: 47 str: 表示する称号 48 49 """ 50 badge: str = "" 51 52 if g.adapter.conf.badge_status: 53 if status_list := g.cfg.setting.main_parser.get("status", "badge", fallback=""): 54 status_badge = status_list.split(",") 55 else: 56 return badge 57 58 if status_step := g.cfg.setting.main_parser.getfloat("status", "step", fallback=""): 59 if not isinstance(status_step, float): 60 return badge 61 if game_count == 0: 62 index = 0 63 else: 64 winper = win / game_count * 100 65 index = 3 66 for i in (1, 2, 3): 67 if winper <= 50 - status_step * i: 68 index = 4 - i 69 if winper >= 50 + status_step * i: 70 index = 2 + i 71 72 badge = status_badge[index] 73 74 return badge 75 76 77def grade(name: str, detail: bool = True) -> str: 78 """ 79 段位表示 80 81 Args: 82 name (str): 対象プレイヤー名 83 detail (bool, optional): 昇段ポイントの表示. Defaults to True. 84 85 Returns: 86 str: 称号 87 88 """ 89 if name not in g.cfg.member.lists: # レギュラーメンバー以外 90 return "" 91 92 if not g.cfg.badge.grade.table_name or not g.cfg.badge.grade.table: # テーブル未定義 93 return "" 94 95 if not g.adapter.conf.badge_grade: # 非表示 96 return "" 97 98 # 初期値 99 point: int = 0 # 昇段ポイント 100 grade_level: int = 0 # レベル(段位) 101 g.params.player_name = name 102 103 result_df = g.params.read_data("SELECT_ALL_RESULTS") 104 addition_expression = g.cfg.badge.grade.table.get("addition_expression", "0") 105 for _, data in result_df.iterrows(): 106 rank = data["rank"] 107 rpoint = data["rpoint"] 108 addition_point = math.ceil(eval(addition_expression.format(rpoint=rpoint, origin_point=g.params.origin_point))) 109 point, grade_level = aggregate.grade_promotion_check(grade_level, point + addition_point, rank) 110 111 next_point = g.cfg.badge.grade.table["table"][grade_level]["point"][1] 112 grade_name = g.cfg.badge.grade.table["table"][grade_level]["grade"] 113 point_detail = f" ({point}/{next_point})" if detail else "" 114 115 return f"{grade_name}{point_detail}"
def
degree(game_count: int = 0) -> str:
12def degree(game_count: int = 0) -> str: 13 """ 14 プレイしたゲーム数に対して表示される称号を返す 15 16 Args: 17 game_count (int, optional): ゲーム数. Defaults to 0. 18 19 Returns: 20 str: 表示する称号 21 22 """ 23 badge: str = "" 24 25 if g.adapter.conf.badge_degree: 26 if degree_list := g.cfg.setting.main_parser.get("degree", "badge", fallback=""): 27 degree_badge = degree_list.split(",") 28 else: 29 return "" 30 if counter_list := g.cfg.setting.main_parser.get("degree", "counter", fallback=""): 31 degree_counter = list(map(int, counter_list.split(","))) 32 for idx, val in enumerate(degree_counter): 33 if game_count >= val: 34 badge = degree_badge[idx] 35 36 return badge
プレイしたゲーム数に対して表示される称号を返す
Arguments:
- game_count (int, optional): ゲーム数. Defaults to 0.
Returns:
str: 表示する称号
def
status(game_count: int = 0, win: int = 0) -> str:
39def status(game_count: int = 0, win: int = 0) -> str: 40 """ 41 勝率に対して付く調子バッジを返す 42 43 Args: 44 game_count (int, optional): ゲーム数. Defaults to 0. 45 win (int, optional): 勝ち数. Defaults to 0. 46 47 Returns: 48 str: 表示する称号 49 50 """ 51 badge: str = "" 52 53 if g.adapter.conf.badge_status: 54 if status_list := g.cfg.setting.main_parser.get("status", "badge", fallback=""): 55 status_badge = status_list.split(",") 56 else: 57 return badge 58 59 if status_step := g.cfg.setting.main_parser.getfloat("status", "step", fallback=""): 60 if not isinstance(status_step, float): 61 return badge 62 if game_count == 0: 63 index = 0 64 else: 65 winper = win / game_count * 100 66 index = 3 67 for i in (1, 2, 3): 68 if winper <= 50 - status_step * i: 69 index = 4 - i 70 if winper >= 50 + status_step * i: 71 index = 2 + i 72 73 badge = status_badge[index] 74 75 return badge
勝率に対して付く調子バッジを返す
Arguments:
- game_count (int, optional): ゲーム数. Defaults to 0.
- win (int, optional): 勝ち数. Defaults to 0.
Returns:
str: 表示する称号
def
grade(name: str, detail: bool = True) -> str:
78def grade(name: str, detail: bool = True) -> str: 79 """ 80 段位表示 81 82 Args: 83 name (str): 対象プレイヤー名 84 detail (bool, optional): 昇段ポイントの表示. Defaults to True. 85 86 Returns: 87 str: 称号 88 89 """ 90 if name not in g.cfg.member.lists: # レギュラーメンバー以外 91 return "" 92 93 if not g.cfg.badge.grade.table_name or not g.cfg.badge.grade.table: # テーブル未定義 94 return "" 95 96 if not g.adapter.conf.badge_grade: # 非表示 97 return "" 98 99 # 初期値 100 point: int = 0 # 昇段ポイント 101 grade_level: int = 0 # レベル(段位) 102 g.params.player_name = name 103 104 result_df = g.params.read_data("SELECT_ALL_RESULTS") 105 addition_expression = g.cfg.badge.grade.table.get("addition_expression", "0") 106 for _, data in result_df.iterrows(): 107 rank = data["rank"] 108 rpoint = data["rpoint"] 109 addition_point = math.ceil(eval(addition_expression.format(rpoint=rpoint, origin_point=g.params.origin_point))) 110 point, grade_level = aggregate.grade_promotion_check(grade_level, point + addition_point, rank) 111 112 next_point = g.cfg.badge.grade.table["table"][grade_level]["point"][1] 113 grade_name = g.cfg.badge.grade.table["table"][grade_level]["grade"] 114 point_detail = f" ({point}/{next_point})" if detail else "" 115 116 return f"{grade_name}{point_detail}"
段位表示
Arguments:
- name (str): 対象プレイヤー名
- detail (bool, optional): 昇段ポイントの表示. Defaults to True.
Returns:
str: 称号