python-ballchasing 0.5.4__py3-none-any.whl → 0.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,286 +1,23 @@
1
- from dataclasses import dataclass, field
2
- from typing import Optional, List
3
-
4
- from ballchasing.typed.shared import _DictToTypeMixin, BasePlayer, BaseReplay, BaseTeam, _BaseModel
5
-
6
-
7
- @dataclass
8
- class CameraSettings(_BaseModel):
9
- fov: int = 0
10
- height: int = 0
11
- pitch: int = 0
12
- distance: int = 0
13
- stiffness: float = 0.0
14
- swivel_speed: float = 0.0
15
- transition_speed: int = 0
16
-
17
-
18
- @dataclass
19
- class TeamBallStatsDR(_BaseModel):
20
- possession_time: float = 0.0
21
- time_in_side: float = 0.0
22
-
23
-
24
- @dataclass
25
- class TeamCoreStatsDR(_BaseModel):
26
- shots: int = 0
27
- shots_against: int = 0
28
- goals: int = 0
29
- goals_against: int = 0
30
- saves: int = 0
31
- assists: int = 0
32
- score: int = 0
33
- shooting_percentage: int = 0
34
-
35
-
36
- @dataclass
37
- class PlayerCoreStatsDR(_BaseModel):
38
- shots: int = 0
39
- shots_against: int = 0
40
- goals: int = 0
41
- goals_against: int = 0
42
- saves: int = 0
43
- assists: int = 0
44
- score: int = 0
45
- mvp: bool = False
46
- shooting_percentage: int = 0
47
-
48
-
49
- @dataclass
50
- class TeamBoostStatsDR(_BaseModel):
51
- bpm: int = 0
52
- bcpm: float = 0.0
53
- avg_amount: float = 0.0
54
- amount_collected: int = 0
55
- amount_stolen: int = 0
56
- amount_collected_big: int = 0
57
- amount_stolen_big: int = 0
58
- amount_collected_small: int = 0
59
- amount_stolen_small: int = 0
60
- count_collected_big: int = 0
61
- count_stolen_big: int = 0
62
- count_collected_small: int = 0
63
- count_stolen_small: int = 0
64
- amount_overfill: int = 0
65
- amount_overfill_stolen: int = 0
66
- amount_used_while_supersonic: int = 0
67
- time_zero_boost: float = 0.0
68
- time_full_boost: float = 0.0
69
- time_boost_0_25: float = 0.0
70
- time_boost_25_50: float = 0.0
71
- time_boost_50_75: float = 0.0
72
- time_boost_75_100: float = 0.0
73
-
74
-
75
- @dataclass
76
- class PlayerBoostStatsDR(_BaseModel):
77
- bpm: int = 0
78
- bcpm: float = 0.0
79
- avg_amount: float = 0.0
80
- amount_collected: int = 0
81
- amount_stolen: int = 0
82
- amount_collected_big: int = 0
83
- amount_stolen_big: int = 0
84
- amount_collected_small: int = 0
85
- amount_stolen_small: int = 0
86
- count_collected_big: int = 0
87
- count_stolen_big: int = 0
88
- count_collected_small: int = 0
89
- count_stolen_small: int = 0
90
- amount_overfill: int = 0
91
- amount_overfill_stolen: int = 0
92
- amount_used_while_supersonic: int = 0
93
- time_zero_boost: float = 0.0
94
- percent_zero_boost: float = 0.0
95
- time_full_boost: float = 0.0
96
- percent_full_boost: float = 0.0
97
- time_boost_0_25: float = 0.0
98
- time_boost_25_50: float = 0.0
99
- time_boost_50_75: float = 0.0
100
- time_boost_75_100: float = 0.0
101
- percent_boost_0_25: float = 0.0
102
- percent_boost_25_50: float = 0.0
103
- percent_boost_50_75: float = 0.0
104
- percent_boost_75_100: float = 0.0
105
-
106
-
107
- @dataclass
108
- class TeamMovementStatsDR(_BaseModel):
109
- total_distance: int = 0
110
- time_supersonic_speed: float = 0.0
111
- time_boost_speed: float = 0.0
112
- time_slow_speed: float = 0.0
113
- time_ground: float = 0.0
114
- time_low_air: float = 0.0
115
- time_high_air: float = 0.0
116
- time_powerslide: float = 0.0
117
- count_powerslide: int = 0
118
-
119
-
120
- @dataclass
121
- class PlayerMovementStatsDR(_BaseModel):
122
- avg_speed: int = 0
123
- total_distance: int = 0
124
- time_supersonic_speed: float = 0.0
125
- time_boost_speed: float = 0.0
126
- time_slow_speed: float = 0.0
127
- time_ground: float = 0.0
128
- time_low_air: float = 0.0
129
- time_high_air: float = 0.0
130
- time_powerslide: float = 0.0
131
- count_powerslide: int = 0
132
- avg_powerslide_duration: float = 0.0
133
- avg_speed_percentage: float = 0.0
134
- percent_slow_speed: float = 0.0
135
- percent_boost_speed: float = 0.0
136
- percent_supersonic_speed: float = 0.0
137
- percent_ground: float = 0.0
138
- percent_low_air: float = 0.0
139
- percent_high_air: float = 0.0
140
-
141
-
142
- @dataclass
143
- class TeamPositioningStatsDR(_BaseModel):
144
- time_defensive_third: float = 0.0
145
- time_neutral_third: float = 0.0
146
- time_offensive_third: float = 0.0
147
- time_defensive_half: float = 0.0
148
- time_offensive_half: float = 0.0
149
- time_behind_ball: float = 0.0
150
- time_infront_ball: float = 0.0
151
-
152
-
153
- @dataclass
154
- class PlayerPositioningStatsDR(_BaseModel):
155
- avg_distance_to_ball: int = 0
156
- avg_distance_to_ball_possession: int = 0
157
- avg_distance_to_ball_no_possession: int = 0
158
- avg_distance_to_mates: int = 0
159
- time_defensive_third: float = 0.0
160
- time_neutral_third: float = 0.0
161
- time_offensive_third: float = 0.0
162
- time_defensive_half: float = 0.0
163
- time_offensive_half: float = 0.0
164
- time_behind_ball: float = 0.0
165
- time_infront_ball: float = 0.0
166
- time_most_back: float = 0.0
167
- time_most_forward: float = 0.0
168
- time_closest_to_ball: float = 0.0
169
- time_farthest_from_ball: float = 0.0
170
- percent_defensive_third: float = 0.0
171
- percent_offensive_third: float = 0.0
172
- percent_neutral_third: float = 0.0
173
- percent_defensive_half: float = 0.0
174
- percent_offensive_half: float = 0.0
175
- percent_behind_ball: float = 0.0
176
- percent_infront_ball: float = 0.0
177
- percent_most_back: float = 0.0
178
- percent_most_forward: float = 0.0
179
- percent_closest_to_ball: float = 0.0
180
- percent_farthest_from_ball: float = 0.0
181
- goals_against_while_last_defender: int = 0
182
-
183
-
184
- @dataclass
185
- class TeamDemoStatsDR(_BaseModel):
186
- inflicted: int = 0
187
- taken: int = 0
188
-
189
-
190
- @dataclass
191
- class PlayerDemoStatsDR(_BaseModel):
192
- inflicted: int = 0
193
- taken: int = 0
194
-
195
-
196
- @dataclass
197
- class TeamStatsDR(_BaseModel, _DictToTypeMixin):
198
- ball: Optional[TeamBallStatsDR] = None
199
- core: Optional[TeamCoreStatsDR] = None
200
- boost: Optional[TeamBoostStatsDR] = None
201
- movement: Optional[TeamMovementStatsDR] = None
202
- positioning: Optional[TeamPositioningStatsDR] = None
203
- demo: Optional[TeamDemoStatsDR] = None
204
-
205
-
206
- @dataclass
207
- class PlayerStatsDR(_BaseModel, _DictToTypeMixin):
208
- core: Optional[PlayerCoreStatsDR] = None
209
- boost: Optional[PlayerBoostStatsDR] = None
210
- movement: Optional[PlayerMovementStatsDR] = None
211
- positioning: Optional[PlayerPositioningStatsDR] = None
212
- demo: Optional[PlayerDemoStatsDR] = None
213
-
214
-
215
- @dataclass
216
- class PlayerDR(BasePlayer):
217
- # start_time: float = 0.0
218
- # end_time: float = 0.0
219
- # name: str = ""
220
- # id: Optional[PlayerID] = None
221
- # pro: bool = False
222
- # mvp: bool = False
223
- # rank: Optional[Rank] = None
224
- car_id: int = 0
225
- car_name: str = ""
226
- camera: Optional[CameraSettings] = None
227
- steering_sensitivity: float = 0
228
- stats: Optional[PlayerStatsDR] = None
229
-
230
-
231
- @dataclass
232
- class TeamDR(BaseTeam):
233
- # name: str = ""
234
- color: str = ""
235
- players: List[PlayerDR] = field(default_factory=list)
236
- stats: Optional[TeamStatsDR] = None
237
-
238
-
239
- @dataclass
240
- class Server(_BaseModel):
241
- name: str = ""
242
- region: str = ""
243
-
244
-
245
- @dataclass
246
- class DeepReplay(BaseReplay):
247
- # id: str = ""
248
- # link: str = ""
249
- # rocket_league_id: str = ""
250
- # recorder: str = ""
251
- # map_code: str = ""
252
- # map_name: str = ""
253
- # playlist_id: str = ""
254
- # playlist_name: str = ""
255
- # duration: int = 0
256
- # overtime: bool = False
257
- # overtime_seconds: int = 0
258
- # season: int = 0
259
- # season_type: str = ""
260
- # date: Optional[datetime] = None
261
- # visibility: str = ""
262
- # created: Optional[datetime] = None
263
- # uploader: Optional[User] = None
264
- # min_rank: Optional[Rank] = None
265
- # max_rank: Optional[Rank] = None
266
- # groups: List[BaseGroup] = field(default_factory=list)
267
- title: str = "" # replay_title in shallow replay
268
- date_has_timezone: bool = False # date_has_tz in shallow replay
269
- status: str = ""
270
- match_guid: str = ""
271
- match_type: str = ""
272
- team_size: int = 0
273
- blue: Optional[TeamDR] = None
274
- orange: Optional[TeamDR] = None
275
- server: Optional[Server] = None
276
-
277
- def scoreline(self):
278
- try:
279
- bg = self.blue.stats.core.goals
280
- except AttributeError:
281
- bg = 0
282
- try:
283
- og = self.orange.stats.core.goals
284
- except AttributeError:
285
- og = 0
286
- return bg, og
1
+ """Former home of the full replay classes, kept for compatibility: they are generated into models.py now."""
2
+ from ballchasing.typed.models import BasePlayer, BaseReplay, BaseTeam # noqa: F401
3
+ from ballchasing.typed.models import ( # noqa: F401
4
+ Camera, DeepReplay, Demo, PlayerBoost, PlayerCore, PlayerMovement, PlayerPositioning, PlayerStats, ReplayPlayer,
5
+ ReplayTeam, Server, TeamBall, TeamBoost, TeamCore, TeamMovement, TeamPositioning, TeamStats,
6
+ )
7
+
8
+ CameraSettings = Camera
9
+ TeamBallStatsDR = TeamBall
10
+ TeamCoreStatsDR = TeamCore
11
+ PlayerCoreStatsDR = PlayerCore
12
+ TeamBoostStatsDR = TeamBoost
13
+ PlayerBoostStatsDR = PlayerBoost
14
+ TeamMovementStatsDR = TeamMovement
15
+ PlayerMovementStatsDR = PlayerMovement
16
+ TeamPositioningStatsDR = TeamPositioning
17
+ PlayerPositioningStatsDR = PlayerPositioning
18
+ TeamDemoStatsDR = Demo
19
+ PlayerDemoStatsDR = Demo
20
+ TeamStatsDR = TeamStats
21
+ PlayerStatsDR = PlayerStats
22
+ PlayerDR = ReplayPlayer
23
+ TeamDR = ReplayTeam
@@ -0,0 +1,145 @@
1
+ """
2
+ Hand-written methods of the typed response objects.
3
+
4
+ The classes in models.py are generated from the OpenAPI document and inherit these mixins (see METHODS in
5
+ scripts/generate_models.py). Mixins only hold methods, no fields. A mixin defining __eq__ or __repr__ makes the
6
+ generator turn off the dataclass's own, so the mixin's is used.
7
+ """
8
+ from functools import total_ordering
9
+
10
+
11
+ class UserMethods:
12
+ def __eq__(self, other):
13
+ if isinstance(other, UserMethods):
14
+ return self.steam_id == other.steam_id
15
+ return False
16
+
17
+
18
+ class PlayerIdMethods:
19
+ def __repr__(self):
20
+ if self.player_number == 0:
21
+ return f"{self.platform}:{self.id}"
22
+ return f"{self.platform}:{self.id}#{self.player_number}"
23
+
24
+
25
+ @total_ordering
26
+ class RankMethods:
27
+ def __eq__(self, other):
28
+ if not isinstance(other, RankMethods):
29
+ return NotImplemented # E.g. a player with a rank compared to one without (None)
30
+ return self.tier == other.tier and self.division == other.division
31
+
32
+ def __lt__(self, other):
33
+ if not isinstance(other, RankMethods):
34
+ return NotImplemented
35
+ return (self.tier, self.division) < (other.tier, other.division)
36
+
37
+ @classmethod
38
+ def from_id(cls, rank_id: str):
39
+ """
40
+ Create a Rank object from a rank ID string, e.g. "grand-champion-1"
41
+ """
42
+ from ballchasing.constants import Rank as RankConstants
43
+ ranks = [r for r in RankConstants.ALL if r != "grand-champion"]
44
+ if rank_id == RankConstants.GRAND_CHAMPION_LEGACY:
45
+ rank_id = RankConstants.GRAND_CHAMPION_1
46
+ try:
47
+ tier = ranks.index(rank_id)
48
+ division = 0 # Division 0 is not really a thing but ID doesn't include it
49
+ name = rank_id.replace("-", " ").title().strip()
50
+ name = name.replace("1", "I").replace("2", "II").replace("3", "III")
51
+ name = name + " Division 0"
52
+ return cls(tier=tier, division=division, name=name, id=rank_id)
53
+ except ValueError:
54
+ raise ValueError(f"Invalid rank ID: {rank_id}. Must be one of {ranks}.")
55
+
56
+ @classmethod
57
+ def from_name(cls, rank_name: str):
58
+ numerals = {"i": "1", "ii": "2", "iii": "3"} # E.g. "Champion II Division 3" -> "champion-2", division 3
59
+ rank_id = "-".join(numerals.get(part, part) for part in rank_name.lower().split())
60
+ if "-division-" in rank_id:
61
+ rank_id, division = rank_id.split("-division-")
62
+ division = int(division)
63
+ else:
64
+ division = 0
65
+
66
+ res = cls.from_id(rank_id)
67
+ res.division = division
68
+ res.name = rank_name
69
+ return res
70
+
71
+
72
+ class BasePlayerMethods:
73
+ def __eq__(self, other):
74
+ if isinstance(other, BasePlayerMethods):
75
+ return self.id == other.id
76
+ return NotImplemented
77
+
78
+ def is_bot(self):
79
+ return self.id is None or (self.id.id == "" and self.id.platform == "")
80
+
81
+
82
+ class BaseTeamMethods:
83
+ def __eq__(self, other):
84
+ # Teams are equal if all players are the same
85
+ if isinstance(other, BaseTeamMethods):
86
+ for p1 in self.players:
87
+ for p2 in other.players:
88
+ if p1 == p2:
89
+ break
90
+ else:
91
+ return False
92
+ return True
93
+ return NotImplemented
94
+
95
+
96
+ class BasicGroupMethods:
97
+ def __eq__(self, other):
98
+ if isinstance(other, BasicGroupMethods):
99
+ return self.id == other.id
100
+ return NotImplemented
101
+
102
+
103
+ class BaseReplayMethods:
104
+ def players(self):
105
+ blue = self.blue.players if self.blue else []
106
+ orange = self.orange.players if self.orange else []
107
+ return blue + orange
108
+
109
+ def teams(self):
110
+ teams = []
111
+ if self.blue:
112
+ teams.append(self.blue)
113
+ if self.orange:
114
+ teams.append(self.orange)
115
+ return teams
116
+
117
+ def team_sizes(self):
118
+ bs = len(self.blue.players) if self.blue else 0
119
+ os = len(self.orange.players) if self.orange else 0
120
+ return bs, os
121
+
122
+ def __eq__(self, other):
123
+ if isinstance(other, BaseReplayMethods):
124
+ return self.id == other.id or self.rocket_league_id == other.rocket_league_id
125
+ return NotImplemented
126
+
127
+
128
+ class DeepReplayMethods:
129
+ def scoreline(self):
130
+ try:
131
+ bg = self.blue.stats.core.goals
132
+ except AttributeError:
133
+ bg = 0
134
+ try:
135
+ og = self.orange.stats.core.goals
136
+ except AttributeError:
137
+ og = 0
138
+ return bg, og
139
+
140
+
141
+ class ShallowReplayMethods:
142
+ def scoreline(self):
143
+ bg = self.blue.goals if self.blue else 0
144
+ og = self.orange.goals if self.orange else 0
145
+ return bg, og