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