libs.commands.report.matrix

libs/commands/report/matrix.py

 1"""
 2libs/commands/report/matrix.py
 3"""
 4
 5from typing import TYPE_CHECKING
 6
 7import libs.global_value as g
 8from libs.data import aggregate
 9from libs.datamodels import GameInfo
10from libs.functions import message
11from libs.types import StyleOptions
12from libs.utils import formatter, textutil
13
14if TYPE_CHECKING:
15    from integrations.protocols import MessageParserProtocol
16
17
18def plot(m: "MessageParserProtocol"):
19    """対局対戦マトリックスの表示
20
21    Args:
22        m (MessageParserProtocol): メッセージデータ
23    """
24
25    # データ集計
26    title: str = "対局対戦マトリックス"
27    game_info = GameInfo()
28    df = aggregate.matrix_table()
29    if g.params.get("anonymous"):
30        mapping_dict = formatter.anonymous_mapping(df.index.tolist())
31        df = df.rename(columns=mapping_dict, index=mapping_dict)
32
33    if df.empty:
34        m.post.headline = {title: message.random_reply(m, "no_hits")}
35        m.status.result = False
36        return
37
38    if str(g.params.get("format", "default")).lower() == "csv":
39        file_path = textutil.save_file_path("matrix.csv", True)
40        df.to_csv(file_path)
41    else:
42        file_path = textutil.save_file_path("matrix.txt", True)
43        df.to_markdown(file_path, tablefmt="outline")
44
45    m.post.headline = {title: message.header(game_info, m, "", 1)}
46    match g.adapter.interface_type:
47        case "slack":
48            m.set_data(title, file_path, StyleOptions(use_comment=True, header_hidden=True))
49        case "web":
50            m.set_data("", df, StyleOptions(show_index=True))
19def plot(m: "MessageParserProtocol"):
20    """対局対戦マトリックスの表示
21
22    Args:
23        m (MessageParserProtocol): メッセージデータ
24    """
25
26    # データ集計
27    title: str = "対局対戦マトリックス"
28    game_info = GameInfo()
29    df = aggregate.matrix_table()
30    if g.params.get("anonymous"):
31        mapping_dict = formatter.anonymous_mapping(df.index.tolist())
32        df = df.rename(columns=mapping_dict, index=mapping_dict)
33
34    if df.empty:
35        m.post.headline = {title: message.random_reply(m, "no_hits")}
36        m.status.result = False
37        return
38
39    if str(g.params.get("format", "default")).lower() == "csv":
40        file_path = textutil.save_file_path("matrix.csv", True)
41        df.to_csv(file_path)
42    else:
43        file_path = textutil.save_file_path("matrix.txt", True)
44        df.to_markdown(file_path, tablefmt="outline")
45
46    m.post.headline = {title: message.header(game_info, m, "", 1)}
47    match g.adapter.interface_type:
48        case "slack":
49            m.set_data(title, file_path, StyleOptions(use_comment=True, header_hidden=True))
50        case "web":
51            m.set_data("", df, StyleOptions(show_index=True))

対局対戦マトリックスの表示

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