libs.commands.results.summary

libs/commands/results/summary.py

  1"""
  2libs/commands/results/summary.py
  3"""
  4
  5from typing import TYPE_CHECKING
  6
  7import libs.global_value as g
  8from libs.domain import aggregate
  9from libs.domain.datamodels import GameInfo
 10from libs.functions import message
 11from libs.types import StyleOptions
 12from libs.utils import converter, formatter
 13
 14if TYPE_CHECKING:
 15    from integrations.protocols import MessageParserProtocol
 16    from libs.types import MessageType
 17
 18
 19def aggregation(m: "MessageParserProtocol") -> None:
 20    """
 21    各プレイヤーの通算ポイントを表示
 22
 23    Args:
 24        m (MessageParserProtocol): メッセージデータ
 25
 26    """
 27    # --- データ収集
 28    data: "MessageType"
 29    game_info = GameInfo()
 30    df_summary = aggregate.game_summary()
 31    df_game = g.params.read_data("SUMMARY_DETAILS")
 32    df_remarks = g.params.read_data("REMARKS_INFO")
 33
 34    current_rule: str = ""
 35    for rule in g.params.rule_list:
 36        current_rule = rule
 37
 38    # インデックスの振りなおし
 39    df_summary.reset_index(inplace=True, drop=True)
 40    df_summary.index += 1
 41
 42    if g.params.anonymous:
 43        mapping_dict = formatter.anonymous_mapping(df_game["name"].unique().tolist())
 44        df_game["name"] = df_game["name"].replace(mapping_dict)
 45        df_summary["name"] = df_summary["name"].replace(mapping_dict)
 46        df_remarks["name"] = df_remarks["name"].replace(mapping_dict)
 47
 48    # 情報ヘッダ
 49    if g.params.individual:  # 個人集計
 50        headline_title = "成績サマリ"
 51    else:  # チーム集計
 52        headline_title = "チーム成績サマリ"
 53
 54    # ルール別
 55    add_text = "" if g.cfg.rule.get_ignore_flying(current_rule) else f" / トバされた人(延べ):{df_summary['flying'].sum()} 人"
 56    header_text = message.header(game_info, m, add_text, 1)
 57    m.set_headline(header_text, StyleOptions(title=headline_title))
 58
 59    if df_summary.empty:
 60        m.set_headline(message.random_reply(m, "no_hits"), StyleOptions())
 61        m.status.result = False
 62        return
 63
 64    # 通算ポイント
 65    options = StyleOptions(
 66        title="通算ポイント",
 67        codeblock=False,
 68        rename_type=StyleOptions.RenameType.SHORT,
 69        data_kind=StyleOptions.DataKind.POINTS_TOTAL,
 70    )
 71    match g.params.format.lower():
 72        case "csv":
 73            options.format_type = "csv"
 74        case "txt" | "text":
 75            options.format_type = "txt"
 76        case _:
 77            options.format_type = "default"
 78
 79    header_list = ["name", "total_point", "avg_point", "rank_distr3", "rank_distr4", "flying"]
 80    filter_list = [
 81        "name",
 82        "count",
 83        "total_point",
 84        "avg_point",
 85        "diff_from_above",
 86        "diff_from_top",
 87        "rank1",
 88        "rank2",
 89        "rank3",
 90        "rank4",
 91        "rank_avg",
 92        "flying",
 93    ]
 94
 95    if g.cfg.rule.get_ignore_flying(current_rule) or g.cfg.rule.dropitems(g.params.rule_version) & g.cfg.dropitems.flying:  # トビカウントなし
 96        header_list.remove("flying")
 97        filter_list.remove("flying")
 98
 99    if options.format_type == "default":
100        options.codeblock = True
101        data = df_summary.filter(items=header_list)
102    else:
103        options.title = headline_title
104        options.base_name = "summary"
105        df_summary = df_summary.filter(items=filter_list).fillna("*****")
106        data = converter.save_output(df_summary, options, m.post.headline, "summary")
107    m.set_message(data, StyleOptions(**options.asdict))
108
109    # メモ(役満和了)
110    if not g.cfg.rule.dropitems(g.params.rule_version) & g.cfg.dropitems.yakuman:
111        options.title = "役満和了"
112        options.data_kind = StyleOptions.DataKind.REMARKS_YAKUMAN
113        df_yakuman = df_remarks.query("type == 0").drop(columns=["type", "ex_point"])
114
115        if options.format_type == "default":
116            options.codeblock = False
117            data = df_yakuman
118        else:
119            options.base_name = "yakuman"
120            data = converter.save_output(df_yakuman, options, m.post.headline, "yakuman")
121        m.set_message(data, StyleOptions(**options.asdict))
122
123    # メモ(卓外清算)
124    if not g.cfg.rule.dropitems(g.params.rule_version) & g.cfg.dropitems.regulation:
125        options.title = "卓外清算"
126        options.data_kind = StyleOptions.DataKind.REMARKS_REGULATION
127
128        if g.params.individual:  # 個人集計
129            df_regulations = df_remarks.query("type == 2").drop(columns=["type"])
130        else:  # チーム集計
131            df_regulations = df_remarks.query("type == 2 or type == 3").drop(columns=["type"])
132
133        if options.format_type == "default":
134            options.codeblock = False
135            data = df_regulations
136        else:
137            options.base_name = "regulations"
138            data = converter.save_output(df_regulations, options, m.post.headline, "regulations")
139        m.set_message(data, StyleOptions(**options.asdict))
140
141    # メモ(その他)
142    if not g.cfg.rule.dropitems(g.params.rule_version) & g.cfg.dropitems.other:
143        options.title = "その他"
144        options.data_kind = StyleOptions.DataKind.REMARKS_OTHER
145        df_others = df_remarks.query("type == 1").drop(columns=["type", "ex_point"])
146
147        if options.format_type == "default":
148            data = df_others
149        else:
150            options.base_name = "others"
151            data = converter.save_output(df_others, options, m.post.headline, "others")
152        m.set_message(data, StyleOptions(**options.asdict))
153
154
155def difference(m: "MessageParserProtocol") -> None:
156    """
157    各プレイヤーのポイント差分を表示
158
159    Args:
160        m (MessageParserProtocol): メッセージデータ
161
162    """
163    # データ収集
164    data: "MessageType"
165    game_info = GameInfo()
166    df_summary = aggregate.game_summary()
167    df_game = g.params.read_data("SUMMARY_DETAILS")
168
169    # インデックスの振りなおし
170    df_summary.reset_index(inplace=True, drop=True)
171    df_summary.index += 1
172
173    if g.params.anonymous:
174        mapping_dict = formatter.anonymous_mapping(df_game["name"].unique().tolist())
175        df_game["name"] = df_game["name"].replace(mapping_dict)
176        df_summary["name"] = df_summary["name"].replace(mapping_dict)
177
178    # 情報ヘッダ
179    if g.params.individual:  # 個人集計
180        headline_title = "成績サマリ"
181    else:  # チーム集計
182        headline_title = "チーム成績サマリ"
183
184    add_text = "" if g.params.ignore_flying else f" / トバされた人(延べ):{df_summary['flying'].sum()} 人"
185    header_text = message.header(game_info, m, add_text, 1)
186    m.set_headline(header_text, StyleOptions(title=headline_title))
187
188    if df_summary.empty:
189        m.set_headline(message.random_reply(m, "no_hits"), StyleOptions())
190        m.status.result = False
191        return
192
193    options = StyleOptions(
194        title="通算ポイント(差分)",
195        base_name="summary",
196        codeblock=True,
197        summarize=True,
198        rename_type=StyleOptions.RenameType.SHORT,
199        data_kind=StyleOptions.DataKind.POINTS_DIFF,
200    )
201    match g.params.format.lower():
202        case "csv":
203            options.format_type = "csv"
204        case "txt" | "text":
205            options.format_type = "txt"
206        case _:
207            options.format_type = "default"
208
209    # 集計結果
210    header_list = ["#", "name", "total_point", "diff_from_above", "diff_from_top"]
211    filter_list = ["name", "count", "total_point", "diff_from_above", "diff_from_top"]
212
213    if options.format_type == "default":
214        data = df_summary.filter(items=header_list)
215    else:
216        options.title = headline_title
217        data = converter.save_output(df_summary.filter(items=filter_list).fillna("*****"), options, m.post.headline)
218    m.set_message(data, StyleOptions(**options.asdict))
def aggregation(m: integrations.protocols.MessageParserProtocol) -> None:
 20def aggregation(m: "MessageParserProtocol") -> None:
 21    """
 22    各プレイヤーの通算ポイントを表示
 23
 24    Args:
 25        m (MessageParserProtocol): メッセージデータ
 26
 27    """
 28    # --- データ収集
 29    data: "MessageType"
 30    game_info = GameInfo()
 31    df_summary = aggregate.game_summary()
 32    df_game = g.params.read_data("SUMMARY_DETAILS")
 33    df_remarks = g.params.read_data("REMARKS_INFO")
 34
 35    current_rule: str = ""
 36    for rule in g.params.rule_list:
 37        current_rule = rule
 38
 39    # インデックスの振りなおし
 40    df_summary.reset_index(inplace=True, drop=True)
 41    df_summary.index += 1
 42
 43    if g.params.anonymous:
 44        mapping_dict = formatter.anonymous_mapping(df_game["name"].unique().tolist())
 45        df_game["name"] = df_game["name"].replace(mapping_dict)
 46        df_summary["name"] = df_summary["name"].replace(mapping_dict)
 47        df_remarks["name"] = df_remarks["name"].replace(mapping_dict)
 48
 49    # 情報ヘッダ
 50    if g.params.individual:  # 個人集計
 51        headline_title = "成績サマリ"
 52    else:  # チーム集計
 53        headline_title = "チーム成績サマリ"
 54
 55    # ルール別
 56    add_text = "" if g.cfg.rule.get_ignore_flying(current_rule) else f" / トバされた人(延べ):{df_summary['flying'].sum()} 人"
 57    header_text = message.header(game_info, m, add_text, 1)
 58    m.set_headline(header_text, StyleOptions(title=headline_title))
 59
 60    if df_summary.empty:
 61        m.set_headline(message.random_reply(m, "no_hits"), StyleOptions())
 62        m.status.result = False
 63        return
 64
 65    # 通算ポイント
 66    options = StyleOptions(
 67        title="通算ポイント",
 68        codeblock=False,
 69        rename_type=StyleOptions.RenameType.SHORT,
 70        data_kind=StyleOptions.DataKind.POINTS_TOTAL,
 71    )
 72    match g.params.format.lower():
 73        case "csv":
 74            options.format_type = "csv"
 75        case "txt" | "text":
 76            options.format_type = "txt"
 77        case _:
 78            options.format_type = "default"
 79
 80    header_list = ["name", "total_point", "avg_point", "rank_distr3", "rank_distr4", "flying"]
 81    filter_list = [
 82        "name",
 83        "count",
 84        "total_point",
 85        "avg_point",
 86        "diff_from_above",
 87        "diff_from_top",
 88        "rank1",
 89        "rank2",
 90        "rank3",
 91        "rank4",
 92        "rank_avg",
 93        "flying",
 94    ]
 95
 96    if g.cfg.rule.get_ignore_flying(current_rule) or g.cfg.rule.dropitems(g.params.rule_version) & g.cfg.dropitems.flying:  # トビカウントなし
 97        header_list.remove("flying")
 98        filter_list.remove("flying")
 99
100    if options.format_type == "default":
101        options.codeblock = True
102        data = df_summary.filter(items=header_list)
103    else:
104        options.title = headline_title
105        options.base_name = "summary"
106        df_summary = df_summary.filter(items=filter_list).fillna("*****")
107        data = converter.save_output(df_summary, options, m.post.headline, "summary")
108    m.set_message(data, StyleOptions(**options.asdict))
109
110    # メモ(役満和了)
111    if not g.cfg.rule.dropitems(g.params.rule_version) & g.cfg.dropitems.yakuman:
112        options.title = "役満和了"
113        options.data_kind = StyleOptions.DataKind.REMARKS_YAKUMAN
114        df_yakuman = df_remarks.query("type == 0").drop(columns=["type", "ex_point"])
115
116        if options.format_type == "default":
117            options.codeblock = False
118            data = df_yakuman
119        else:
120            options.base_name = "yakuman"
121            data = converter.save_output(df_yakuman, options, m.post.headline, "yakuman")
122        m.set_message(data, StyleOptions(**options.asdict))
123
124    # メモ(卓外清算)
125    if not g.cfg.rule.dropitems(g.params.rule_version) & g.cfg.dropitems.regulation:
126        options.title = "卓外清算"
127        options.data_kind = StyleOptions.DataKind.REMARKS_REGULATION
128
129        if g.params.individual:  # 個人集計
130            df_regulations = df_remarks.query("type == 2").drop(columns=["type"])
131        else:  # チーム集計
132            df_regulations = df_remarks.query("type == 2 or type == 3").drop(columns=["type"])
133
134        if options.format_type == "default":
135            options.codeblock = False
136            data = df_regulations
137        else:
138            options.base_name = "regulations"
139            data = converter.save_output(df_regulations, options, m.post.headline, "regulations")
140        m.set_message(data, StyleOptions(**options.asdict))
141
142    # メモ(その他)
143    if not g.cfg.rule.dropitems(g.params.rule_version) & g.cfg.dropitems.other:
144        options.title = "その他"
145        options.data_kind = StyleOptions.DataKind.REMARKS_OTHER
146        df_others = df_remarks.query("type == 1").drop(columns=["type", "ex_point"])
147
148        if options.format_type == "default":
149            data = df_others
150        else:
151            options.base_name = "others"
152            data = converter.save_output(df_others, options, m.post.headline, "others")
153        m.set_message(data, StyleOptions(**options.asdict))

各プレイヤーの通算ポイントを表示

Arguments:
  • m (MessageParserProtocol): メッセージデータ
def difference(m: integrations.protocols.MessageParserProtocol) -> None:
156def difference(m: "MessageParserProtocol") -> None:
157    """
158    各プレイヤーのポイント差分を表示
159
160    Args:
161        m (MessageParserProtocol): メッセージデータ
162
163    """
164    # データ収集
165    data: "MessageType"
166    game_info = GameInfo()
167    df_summary = aggregate.game_summary()
168    df_game = g.params.read_data("SUMMARY_DETAILS")
169
170    # インデックスの振りなおし
171    df_summary.reset_index(inplace=True, drop=True)
172    df_summary.index += 1
173
174    if g.params.anonymous:
175        mapping_dict = formatter.anonymous_mapping(df_game["name"].unique().tolist())
176        df_game["name"] = df_game["name"].replace(mapping_dict)
177        df_summary["name"] = df_summary["name"].replace(mapping_dict)
178
179    # 情報ヘッダ
180    if g.params.individual:  # 個人集計
181        headline_title = "成績サマリ"
182    else:  # チーム集計
183        headline_title = "チーム成績サマリ"
184
185    add_text = "" if g.params.ignore_flying else f" / トバされた人(延べ):{df_summary['flying'].sum()} 人"
186    header_text = message.header(game_info, m, add_text, 1)
187    m.set_headline(header_text, StyleOptions(title=headline_title))
188
189    if df_summary.empty:
190        m.set_headline(message.random_reply(m, "no_hits"), StyleOptions())
191        m.status.result = False
192        return
193
194    options = StyleOptions(
195        title="通算ポイント(差分)",
196        base_name="summary",
197        codeblock=True,
198        summarize=True,
199        rename_type=StyleOptions.RenameType.SHORT,
200        data_kind=StyleOptions.DataKind.POINTS_DIFF,
201    )
202    match g.params.format.lower():
203        case "csv":
204            options.format_type = "csv"
205        case "txt" | "text":
206            options.format_type = "txt"
207        case _:
208            options.format_type = "default"
209
210    # 集計結果
211    header_list = ["#", "name", "total_point", "diff_from_above", "diff_from_top"]
212    filter_list = ["name", "count", "total_point", "diff_from_above", "diff_from_top"]
213
214    if options.format_type == "default":
215        data = df_summary.filter(items=header_list)
216    else:
217        options.title = headline_title
218        data = converter.save_output(df_summary.filter(items=filter_list).fillna("*****"), options, m.post.headline)
219    m.set_message(data, StyleOptions(**options.asdict))

各プレイヤーのポイント差分を表示

Arguments:
  • m (MessageParserProtocol): メッセージデータ