cls.types

cls/types.py

  1"""
  2cls/types.py
  3"""
  4
  5from collections.abc import Mapping
  6from datetime import datetime
  7from typing import TYPE_CHECKING, Callable, Literal, TypedDict, Union
  8
  9if TYPE_CHECKING:
 10    from cls.timekit import ExtendedDatetime
 11    from cls.score import GameResult
 12
 13
 14class GameInfoDict(TypedDict):
 15    """ゲーム集計情報格納辞書"""
 16    game_count: int
 17    """ゲーム数"""
 18    first_game: "ExtendedDatetime"
 19    """記録されている最初のゲーム時間"""
 20    last_game: "ExtendedDatetime"
 21    """記録されている最後のゲーム時間"""
 22    first_comment: str | None
 23    """記録されている最初のゲームコメント"""
 24    last_comment: str | None
 25    """記録されている最後のゲームコメント"""
 26
 27
 28class TeamDataDict(TypedDict):
 29    """チーム情報格納辞書"""
 30    id: int
 31    team: str
 32    member: list[str]
 33
 34
 35class ScoreDataDict(TypedDict, total=False):
 36    """スコアデータ格納用辞書"""
 37    ts: str
 38    p1_name: str
 39    p1_str: str
 40    p1_rpoint: int
 41    p1_point: float
 42    p1_rank: int
 43    p2_name: str
 44    p2_str: str
 45    p2_rpoint: int
 46    p2_point: float
 47    p2_rank: int
 48    p3_name: str
 49    p3_str: str
 50    p3_rpoint: int
 51    p3_point: float
 52    p3_rank: int
 53    p4_name: str
 54    p4_str: str
 55    p4_rpoint: int
 56    p4_point: float
 57    p4_rank: int
 58    comment: str | None
 59    deposit: int
 60    rpoint_sum: int
 61    rule_version: str
 62
 63
 64class RemarkDict(TypedDict):
 65    """メモ格納用辞書"""
 66    thread_ts: str
 67    """ゲーム終了時間"""
 68    event_ts: str
 69    """メモ記録時間"""
 70    name: str
 71    matter: str
 72
 73
 74class ComparisonDict(TypedDict, total=False):
 75    """メモ突合用辞書"""
 76    mismatch: str
 77    """差分"""
 78    missing: str
 79    """追加"""
 80    delete: str
 81    """削除"""
 82    remark_mod: str
 83    """メモの修正(追加/削除)"""
 84    remark_del: str
 85    """削除"""
 86    invalid_score: str
 87    """素点合計不一致"""
 88    pending: list[str]
 89    """保留"""
 90
 91
 92class SlackSearchData(TypedDict, total=False):
 93    """slack検索結果格納辞書"""
 94    text: str
 95    """検索にヒットした本文の内容"""
 96    channel_id: str
 97    """見つけたチャンネルID"""
 98    user_id: str
 99    """投稿者のユーザID"""
100    event_ts: str | None
101    """ポストされた時間"""
102    thread_ts: str | None
103    """スレッドになっている場合、スレッド元の時間"""
104    edited_ts: str | None
105    """最後に編集された時間"""
106    reaction_ok: list
107    """botが付けたOKリアクション"""
108    reaction_ng: list
109    """botが付けたNGリアクション"""
110    in_thread: bool
111    """スレッドになっていればTrue(スレッド元は除く)"""
112    score: "GameResult"
113    """スコア報告なら結果"""
114    remarks: list
115    """メモならその内容"""
116
117
118class DateRangeSpec(TypedDict):
119    """日付範囲変換キーワード用辞書"""
120    keyword: list[str]
121    range: Callable[[datetime], list[datetime]]
122
123
124class RankTableDict(TypedDict):
125    """昇段ポイント計算テーブル用辞書"""
126    grade: str
127    point: list
128    acquisition: list
129    demote: bool
130
131
132class GradeTableDict(TypedDict, total=False):
133    """段位テーブル用辞書"""
134    name: str
135    addition_expression: str
136    table: list[RankTableDict]
137
138
139# CommandParser用
140CommandResult = Mapping[str, Union[str, int, bool, tuple[str, ...]]]
141CommandAction = Callable[[Union[str, tuple[str, ...]]], CommandResult]
142
143
144class CommandSpec(TypedDict, total=False):
145    """コマンドマッピング"""
146    match: list[str]
147    action: CommandAction
148    type: Literal["int", "str", "sql", "filename"]
class GameInfoDict(typing.TypedDict):
15class GameInfoDict(TypedDict):
16    """ゲーム集計情報格納辞書"""
17    game_count: int
18    """ゲーム数"""
19    first_game: "ExtendedDatetime"
20    """記録されている最初のゲーム時間"""
21    last_game: "ExtendedDatetime"
22    """記録されている最後のゲーム時間"""
23    first_comment: str | None
24    """記録されている最初のゲームコメント"""
25    last_comment: str | None
26    """記録されている最後のゲームコメント"""

ゲーム集計情報格納辞書

game_count: int

ゲーム数

記録されている最初のゲーム時間

記録されている最後のゲーム時間

first_comment: str | None

記録されている最初のゲームコメント

last_comment: str | None

記録されている最後のゲームコメント

class TeamDataDict(typing.TypedDict):
29class TeamDataDict(TypedDict):
30    """チーム情報格納辞書"""
31    id: int
32    team: str
33    member: list[str]

チーム情報格納辞書

id: int
team: str
member: list[str]
class ScoreDataDict(typing.TypedDict):
36class ScoreDataDict(TypedDict, total=False):
37    """スコアデータ格納用辞書"""
38    ts: str
39    p1_name: str
40    p1_str: str
41    p1_rpoint: int
42    p1_point: float
43    p1_rank: int
44    p2_name: str
45    p2_str: str
46    p2_rpoint: int
47    p2_point: float
48    p2_rank: int
49    p3_name: str
50    p3_str: str
51    p3_rpoint: int
52    p3_point: float
53    p3_rank: int
54    p4_name: str
55    p4_str: str
56    p4_rpoint: int
57    p4_point: float
58    p4_rank: int
59    comment: str | None
60    deposit: int
61    rpoint_sum: int
62    rule_version: str

スコアデータ格納用辞書

ts: str
p1_name: str
p1_str: str
p1_rpoint: int
p1_point: float
p1_rank: int
p2_name: str
p2_str: str
p2_rpoint: int
p2_point: float
p2_rank: int
p3_name: str
p3_str: str
p3_rpoint: int
p3_point: float
p3_rank: int
p4_name: str
p4_str: str
p4_rpoint: int
p4_point: float
p4_rank: int
comment: str | None
deposit: int
rpoint_sum: int
rule_version: str
class RemarkDict(typing.TypedDict):
65class RemarkDict(TypedDict):
66    """メモ格納用辞書"""
67    thread_ts: str
68    """ゲーム終了時間"""
69    event_ts: str
70    """メモ記録時間"""
71    name: str
72    matter: str

メモ格納用辞書

thread_ts: str

ゲーム終了時間

event_ts: str

メモ記録時間

name: str
matter: str
class ComparisonDict(typing.TypedDict):
75class ComparisonDict(TypedDict, total=False):
76    """メモ突合用辞書"""
77    mismatch: str
78    """差分"""
79    missing: str
80    """追加"""
81    delete: str
82    """削除"""
83    remark_mod: str
84    """メモの修正(追加/削除)"""
85    remark_del: str
86    """削除"""
87    invalid_score: str
88    """素点合計不一致"""
89    pending: list[str]
90    """保留"""

メモ突合用辞書

mismatch: str

差分

missing: str

追加

delete: str

削除

remark_mod: str

メモの修正(追加/削除)

remark_del: str

削除

invalid_score: str

素点合計不一致

pending: list[str]

保留

class SlackSearchData(typing.TypedDict):
 93class SlackSearchData(TypedDict, total=False):
 94    """slack検索結果格納辞書"""
 95    text: str
 96    """検索にヒットした本文の内容"""
 97    channel_id: str
 98    """見つけたチャンネルID"""
 99    user_id: str
100    """投稿者のユーザID"""
101    event_ts: str | None
102    """ポストされた時間"""
103    thread_ts: str | None
104    """スレッドになっている場合、スレッド元の時間"""
105    edited_ts: str | None
106    """最後に編集された時間"""
107    reaction_ok: list
108    """botが付けたOKリアクション"""
109    reaction_ng: list
110    """botが付けたNGリアクション"""
111    in_thread: bool
112    """スレッドになっていればTrue(スレッド元は除く)"""
113    score: "GameResult"
114    """スコア報告なら結果"""
115    remarks: list
116    """メモならその内容"""

slack検索結果格納辞書

text: str

検索にヒットした本文の内容

channel_id: str

見つけたチャンネルID

user_id: str

投稿者のユーザID

event_ts: str | None

ポストされた時間

thread_ts: str | None

スレッドになっている場合、スレッド元の時間

edited_ts: str | None

最後に編集された時間

reaction_ok: list

botが付けたOKリアクション

reaction_ng: list

botが付けたNGリアクション

in_thread: bool

スレッドになっていればTrue(スレッド元は除く)

スコア報告なら結果

remarks: list

メモならその内容

class DateRangeSpec(typing.TypedDict):
119class DateRangeSpec(TypedDict):
120    """日付範囲変換キーワード用辞書"""
121    keyword: list[str]
122    range: Callable[[datetime], list[datetime]]

日付範囲変換キーワード用辞書

keyword: list[str]
range: Callable[[datetime.datetime], list[datetime.datetime]]
class RankTableDict(typing.TypedDict):
125class RankTableDict(TypedDict):
126    """昇段ポイント計算テーブル用辞書"""
127    grade: str
128    point: list
129    acquisition: list
130    demote: bool

昇段ポイント計算テーブル用辞書

grade: str
point: list
acquisition: list
demote: bool
class GradeTableDict(typing.TypedDict):
133class GradeTableDict(TypedDict, total=False):
134    """段位テーブル用辞書"""
135    name: str
136    addition_expression: str
137    table: list[RankTableDict]

段位テーブル用辞書

name: str
addition_expression: str
table: list[RankTableDict]
CommandResult = collections.abc.Mapping[str, typing.Union[str, int, bool, tuple[str, ...]]]
CommandAction = typing.Callable[[typing.Union[str, tuple[str, ...]]], collections.abc.Mapping[str, typing.Union[str, int, bool, tuple[str, ...]]]]
class CommandSpec(typing.TypedDict):
145class CommandSpec(TypedDict, total=False):
146    """コマンドマッピング"""
147    match: list[str]
148    action: CommandAction
149    type: Literal["int", "str", "sql", "filename"]

コマンドマッピング

match: list[str]
action: Callable[[Union[str, tuple[str, ...]]], Mapping[str, Union[str, int, bool, tuple[str, ...]]]]
type: Literal['int', 'str', 'sql', 'filename']