python-ballchasing 0.5.3__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,18 +1,3 @@
1
- from dataclasses import dataclass
2
- from typing import Optional
3
-
4
- from ballchasing.typed.shared import User, BaseGroup
5
-
6
-
7
- @dataclass
8
- class ShallowGroup(BaseGroup):
9
- # id: str = ""
10
- # link: str = ""
11
- # name: str = ""
12
- # created: Optional[datetime] = None
13
- # player_identification: str = ""
14
- # team_identification: str = ""
15
- # shared: bool = False
16
- direct_replays: int = 0
17
- indirect_replays: int = 0
18
- user: Optional[User] = None
1
+ """Former home of the group list class, kept for compatibility: it is generated into models.py now."""
2
+ from ballchasing.typed.models import BaseGroup, User # noqa: F401
3
+ from ballchasing.typed.models import ShallowGroup # noqa: F401
@@ -1,67 +1,6 @@
1
- from dataclasses import dataclass, field
2
- from typing import Optional, List
1
+ """Former home of the replay list 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 ReplaySummaryPlayer, ReplaySummaryTeam, ShallowReplay # noqa: F401
3
4
 
4
- from ballchasing.typed.shared import _DictToTypeMixin, BasePlayer, BaseTeam, BaseReplay
5
-
6
-
7
- @dataclass
8
- class PlayerSR(BasePlayer):
9
- # start_time: float = 0.0
10
- # end_time: float = 0.0
11
- # name: str = ""
12
- # id: Optional[PlayerID] = None
13
- # pro: bool = False
14
- # mvp: bool = False
15
- # rank: Optional[Rank] = None
16
- score: int = 0
17
-
18
-
19
- @dataclass
20
- class TeamSR(BaseTeam):
21
- # name: str = ""
22
- goals: int = 0
23
- players: List[PlayerSR] = field(default_factory=list)
24
-
25
- def __eq__(self, other):
26
- if isinstance(other, TeamSR):
27
- for p1 in self.players:
28
- for p2 in other.players:
29
- if p1 == p2:
30
- break
31
- else:
32
- return False
33
- return True
34
- return NotImplemented
35
-
36
-
37
- @dataclass
38
- class ShallowReplay(BaseReplay):
39
- # id: str = ""
40
- # link: str = ""
41
- # rocket_league_id: str = ""
42
- # recorder: str = ""
43
- # map_code: str = ""
44
- # map_name: str = ""
45
- # playlist_id: str = ""
46
- # playlist_name: str = ""
47
- # duration: int = 0
48
- # overtime: bool = False
49
- # overtime_seconds: int = 0
50
- # season: int = 0
51
- # season_type: str = ""
52
- # date: Optional[datetime] = None
53
- # visibility: str = ""
54
- # created: Optional[datetime] = None
55
- # uploader: Optional[User] = None
56
- # min_rank: Optional[Rank] = None
57
- # max_rank: Optional[Rank] = None
58
- # groups: List[BaseGroup] = field(default_factory=list)
59
- replay_title: str = "" # title in deep replay
60
- date_has_tz: bool = False # date_has_timezone in deep replay
61
- blue: Optional[TeamSR] = None
62
- orange: Optional[TeamSR] = None
63
-
64
- def scoreline(self):
65
- bg = self.blue.goals if self.blue else 0
66
- og = self.orange.goals if self.orange else 0
67
- return bg, og
5
+ PlayerSR = ReplaySummaryPlayer
6
+ TeamSR = ReplaySummaryTeam
@@ -1,244 +1,7 @@
1
- from dataclasses import dataclass, fields, field
2
- from datetime import datetime
3
- from functools import total_ordering
4
- from typing import get_args, Optional, List
1
+ """Former home of the shared typed classes, kept for compatibility: they are generated into models.py now."""
2
+ from ballchasing.typed._base import _BaseModel, _DictToTypeMixin, model # noqa: F401
3
+ from ballchasing.typed.models import ( # noqa: F401
4
+ BaseGroup, BasePlayer, BaseReplay, BaseTeam, BasicGroup, PlayerId, Rank, User,
5
+ )
5
6
 
6
- from ballchasing.util.dates import from_rfc3339, to_rfc3339
7
-
8
-
9
- class _BaseModel:
10
- """
11
- Base model class for all dataclasses in this module.
12
- """
13
-
14
- def to_dict(self):
15
- """
16
- Convert (back) to a dict. Not a perfect recreation.
17
- """
18
- result = {}
19
- for field in fields(self):
20
- value = getattr(self, field.name)
21
- if isinstance(value, _BaseModel):
22
- result[field.name] = value.to_dict()
23
- elif isinstance(value, list):
24
- if len(value) > 0:
25
- result[field.name] = [item.to_dict() if isinstance(item, _BaseModel) else item for item in value]
26
- elif isinstance(value, datetime):
27
- # Convert datetime objects to rfc3339 formatted strings
28
- result[field.name] = to_rfc3339(value)
29
- elif value is not None:
30
- # Include non-None values, preserving valid 0 and False values
31
- result[field.name] = value
32
- return result
33
-
34
-
35
- class _DictToTypeMixin:
36
- """
37
- Mixin class to convert dicts to their respective types in dataclasses.
38
- """
39
-
40
- def __post_init__(self):
41
- for field in fields(self):
42
- value = getattr(self, field.name)
43
- actual_type = field.type
44
- if args := get_args(field.type):
45
- actual_type = args[0]
46
- if isinstance(value, dict):
47
- new_value = actual_type(**value)
48
- setattr(self, field.name, new_value)
49
- elif isinstance(value, list):
50
- new_value = [actual_type(**item) if isinstance(item, dict) else item for item in value]
51
- setattr(self, field.name, new_value)
52
- elif isinstance(value, str) and actual_type is datetime:
53
- # Load rfc3339 formatted strings as datetime objects
54
- new_value = from_rfc3339(value)
55
- setattr(self, field.name, new_value)
56
- # else: # For testing
57
- # # Check that the value has the type specified in the dataclass field
58
- # if value is not None and not isinstance(value, actual_type):
59
- # if isinstance(value, int) and actual_type is float:
60
- # pass # ints can be converted losslessly to floats
61
- # else:
62
- # raise TypeError(f"Expected {field.name} to be of type {actual_type}, got {type(value)}")
63
-
64
-
65
- @dataclass
66
- class User(_BaseModel):
67
- steam_id: str = ""
68
- name: str = ""
69
- profile_url: str = ""
70
- avatar: str = ""
71
-
72
- def __eq__(self, other):
73
- if isinstance(other, User):
74
- return self.steam_id == other.steam_id
75
- return False
76
-
77
-
78
- @dataclass
79
- class PlayerID(_BaseModel):
80
- platform: str = ""
81
- id: str = ""
82
- player_number: int = 0
83
-
84
- def __repr__(self):
85
- if self.player_number == 0:
86
- return f"{self.platform}:{self.id}"
87
- return f"{self.platform}:{self.id}#{self.player_number}"
88
-
89
-
90
- @total_ordering
91
- @dataclass
92
- class Rank(_BaseModel):
93
- tier: int = 0
94
- division: int = 0
95
- name: str = ""
96
- id: str = ""
97
-
98
- def __eq__(self, other):
99
- return self.tier == other.tier and self.division == other.division
100
-
101
- def __lt__(self, other):
102
- return (self.tier, self.division) < (other.tier, other.division)
103
-
104
- @classmethod
105
- def from_id(cls, rank_id: str):
106
- """
107
- Create a Rank object from a rank ID string, e.g. "grand-champion-1"
108
- """
109
- from ballchasing.constants import Rank as RankConstants
110
- ranks = [r for r in RankConstants.ALL if r != "grand-champion"]
111
- if rank_id == RankConstants.GRAND_CHAMPION_LEGACY:
112
- rank_id = RankConstants.GRAND_CHAMPION_1
113
- try:
114
- tier = ranks.index(rank_id)
115
- division = 0 # Division 0 is not really a thing but ID doesn't include it
116
- name = rank_id.replace("-", " ").title().strip()
117
- name = name.replace("1", "I").replace("2", "II").replace("3", "III")
118
- name = name + " Division 0"
119
- return cls(tier=tier, division=division, name=name, id=rank_id)
120
- except ValueError:
121
- raise ValueError(f"Invalid rank ID: {rank_id}. Must be one of {ranks}.")
122
-
123
- @classmethod
124
- def from_name(cls, rank_name: str):
125
- rank_id = rank_name.lower().replace(" ", "-")
126
- rank_id = rank_id.replace("i", "1").replace("ii", "2").replace("iii", "3")
127
- if "-division-" in rank_id:
128
- rank_id, division = rank_id.split("-division-")
129
- division = int(division)
130
- else:
131
- division = 0
132
-
133
- res = cls.from_id(rank_id)
134
- res.division = division
135
- res.name = rank_name
136
- return res
137
-
138
-
139
- @dataclass
140
- class BasePlayer(_BaseModel, _DictToTypeMixin):
141
- start_time: float = 0.0
142
- end_time: float = 0.0
143
- name: str = ""
144
- id: Optional[PlayerID] = None
145
- pro: bool = False
146
- mvp: bool = False
147
- rank: Optional[Rank] = None
148
-
149
- def __eq__(self, other):
150
- if isinstance(other, BasePlayer):
151
- return self.id == other.id
152
- return NotImplemented
153
-
154
- def is_bot(self):
155
- return self.id is None or (self.id.id == "" and self.id.platform == "")
156
-
157
-
158
- @dataclass
159
- class BaseTeam(_BaseModel, _DictToTypeMixin):
160
- name: str = ""
161
- # Further specified in subclasses, needed for methods:
162
- players: List[BasePlayer] = field(default_factory=list)
163
-
164
- def __eq__(self, other):
165
- # Teams are equal if all players are the same
166
- if isinstance(other, BaseTeam):
167
- for p1 in self.players:
168
- for p2 in other.players:
169
- if p1 == p2:
170
- break
171
- else:
172
- return False
173
- return True
174
- return NotImplemented
175
-
176
-
177
- @dataclass
178
- class BasicGroup(_BaseModel): # Shared between replays and shallow/deep groups
179
- id: str = ""
180
- name: str = ""
181
- link: str = ""
182
-
183
- def __eq__(self, other):
184
- if isinstance(other, BasicGroup):
185
- return self.id == other.id
186
- return NotImplemented
187
-
188
-
189
- @dataclass
190
- class BaseGroup(BasicGroup, _DictToTypeMixin): # Shared between shallow and deep groups
191
- created: Optional[datetime] = ""
192
- player_identification: str = ""
193
- team_identification: str = ""
194
- shared: bool = False
195
-
196
-
197
- @dataclass
198
- class BaseReplay(_BaseModel, _DictToTypeMixin): # Shared between shallow and deep replays
199
- id: str = ""
200
- link: str = ""
201
- rocket_league_id: str = ""
202
- recorder: str = ""
203
- map_code: str = ""
204
- map_name: str = ""
205
- playlist_id: str = ""
206
- playlist_name: str = ""
207
- duration: int = 0
208
- overtime: bool = False
209
- overtime_seconds: int = 0
210
- season: int = 0
211
- season_type: str = ""
212
- date: Optional[datetime] = None
213
- visibility: str = ""
214
- created: Optional[datetime] = None
215
- uploader: Optional[User] = None
216
- min_rank: Optional[Rank] = None
217
- max_rank: Optional[Rank] = None
218
- groups: List[BasicGroup] = field(default_factory=list)
219
- # Further specified in subclasses, needed for methods:
220
- blue: Optional[BaseTeam] = None
221
- orange: Optional[BaseTeam] = None
222
-
223
- def players(self):
224
- blue = self.blue.players if self.blue else []
225
- orange = self.orange.players if self.orange else []
226
- return blue + orange
227
-
228
- def teams(self):
229
- teams = []
230
- if self.blue:
231
- teams.append(self.blue)
232
- if self.orange:
233
- teams.append(self.orange)
234
- return teams
235
-
236
- def team_sizes(self):
237
- bs = len(self.blue.players) if self.blue else 0
238
- os = len(self.orange.players) if self.orange else 0
239
- return bs, os
240
-
241
- def __eq__(self, other):
242
- if isinstance(other, BaseReplay):
243
- return self.id == other.id or self.rocket_league_id == other.rocket_league_id
244
- return NotImplemented
7
+ PlayerID = PlayerId
@@ -68,7 +68,7 @@ def deduplicate(replays, check_dates=False):
68
68
  def _get_sorting_key_fn(sort_by, sort_dir):
69
69
  if sort_by == ReplaySortBy.REPLAY_DATE:
70
70
  key = "date"
71
- elif sort_by == ReplaySortBy.UPLOAD_DATE:
71
+ elif sort_by in (ReplaySortBy.CREATED, "upload-date"): # "upload-date" is the API's former name for it
72
72
  key = "created"
73
73
  else:
74
74
  raise ValueError(f"Unsupported sort_by: {sort_by}")
ballchasing/util/stats.py CHANGED
@@ -8,8 +8,8 @@ from .replays import get_pid
8
8
 
9
9
  @cache
10
10
  def get_stats_info():
11
- cur_path = Path(__file__).parent
12
- with open(cur_path / "stats_info.tsv") as stats_info:
11
+ cur_path = Path(__file__).parent.parent # stats_info.tsv lives in the ballchasing package root
12
+ with open(cur_path / "stats_info.tsv", encoding="utf-8") as stats_info:
13
13
  stats_info = [line.strip().split("\t") for line in stats_info]
14
14
 
15
15
  header = stats_info[0]
@@ -28,7 +28,7 @@ def get_stats_info():
28
28
  "datetime": datetime,
29
29
  }[v]
30
30
  stat_info[k] = v
31
- stats[stat_info["name"]] = stat_info
31
+ stats[stat_info["path"]] = stat_info # Not by name: team and player stats share names
32
32
  return stats
33
33
 
34
34
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-ballchasing
3
- Version: 0.5.3
3
+ Version: 0.6.0
4
4
  Summary: A Python wrapper around the Ballchasing API
5
5
  Author-email: Rolv-Arild Braaten <rolv_arild@hotmail.com>
6
6
  License: MIT License
@@ -94,7 +94,8 @@ for group in groups:
94
94
  ---
95
95
  Additionally, there's the option to put responses (replays, groups) into typed objects for better type hinting and validation.
96
96
  It also attempts to fill in missing variables not returned by ballchasing (e.g. if a team has 0 goals they won't have a "goal" entry in the response)
97
- The classes can also be found under the `typing` folder and used as a reference for what the API returns.
97
+ The classes are generated from the API's [OpenAPI document](https://ballchasing.com/doc/api/openapi.json) into
98
+ `ballchasing/typed/models.py`, with each field's description, and can be used as a reference for what the API returns.
98
99
 
99
100
  ```python
100
101
  # When creating the API, you can specify a default setting for typing (defaults to False)
@@ -107,3 +108,18 @@ print(replay.blue.players[0].name) # Example of easy attribute access
107
108
  group = api.get_group("g2-vs-bds-hwbf2eyolb", typed=True)
108
109
  print(group.players[0].name)
109
110
  ```
111
+
112
+ Fields the API adds after a release don't break the typed objects: they are kept in the object's `_extra` dict
113
+ (and included by `to_dict()`) until the classes get a field for them.
114
+
115
+ ---
116
+ The client is checked against a snapshot of the [OpenAPI document](https://ballchasing.com/doc/api/openapi.json) in
117
+ `tests/data/openapi.json`. To see what changed in the API since, update the snapshot and regenerate the typed models:
118
+
119
+ ```shell
120
+ python scripts/check_api_spec.py # exits with 1 if something changed
121
+ python scripts/check_api_spec.py --update # then run the tests to see what else the client is missing
122
+ python scripts/generate_models.py # regenerate models.py alone (e.g. after changing the generator)
123
+ ```
124
+
125
+ Methods of the typed classes are written by hand in `ballchasing/typed/methods.py`.
@@ -0,0 +1,25 @@
1
+ ballchasing/__init__.py,sha256=iH9IeimwznBAXqOAzeDnmcwmBpKRdIjZHoqQz-iPpgA,2856
2
+ ballchasing/api.py,sha256=qyWHebEVrTvAe9zbNOhvjF7UiDCJ_t29_IDTPrr5Lnc,41503
3
+ ballchasing/constants.py,sha256=dHI8uRJ6Vrz6pMzOcRbaGaWnyV1chhHEJriDMTQN0NM,13081
4
+ ballchasing/exceptions.py,sha256=Y_fdxe8-bxTuKJvlEFzQG0b_z7mjn5EATbg5VlMACcY,1616
5
+ ballchasing/rate_limit.py,sha256=QWpCnpbkm7exFI5IeHCOjAXyaZSmQ_rVLvAGodO9x7E,10263
6
+ ballchasing/stats_info.tsv,sha256=Ap-OW4OsrG_6C2pldBMvPG5kqupaeds-3gt9HZOcLAY,14831
7
+ ballchasing/typed/__init__.py,sha256=JDVUyRTXHkIvws9P-3cA2XWC6Ye985IYy2DVXfxO3T4,197
8
+ ballchasing/typed/_base.py,sha256=UQK6AbFXIOCn-Detgzc0XwgsFCP0MClgt4Onzw4jtYw,4529
9
+ ballchasing/typed/deep_group.py,sha256=7OIB6ykcA6xehGNVS07gfQ2aykphhzijS9QhH9eeVk0,1513
10
+ ballchasing/typed/deep_replay.py,sha256=-mDKUUFoT6k7gW07Jc_BtsE0zEy4iCMs16bgw6NWxv0,938
11
+ ballchasing/typed/methods.py,sha256=TSHqIbESx7TSVxweqVJLA-MgZLo6Rmin5qv18mXhco4,4735
12
+ ballchasing/typed/models.py,sha256=ykdpC5nalqgyYaTxA_-vQ45JWT2wzFtRI79agG3dGqo,29588
13
+ ballchasing/typed/shallow_group.py,sha256=xHAy-45N2OkogTXYxRfrHV9_Oxs2xSGrkZEIzlxuQ14,234
14
+ ballchasing/typed/shallow_replay.py,sha256=eRs1D9CyVTHz9iiSE8Zsoldm9fJvopD2jbS-Qn_Hw2A,357
15
+ ballchasing/typed/shared.py,sha256=pigqS6Vp3tj7TBd5M8p-nZKYIAKV00osB-NynbanGTs,355
16
+ ballchasing/util/__init__.py,sha256=ISyxzGEJy2_wzJnikHK5Qo0N4zU0U0YsVP9sOa9v5NI,90
17
+ ballchasing/util/dates.py,sha256=gUSldK6-jMNbGLaBiYwmiKUR0h0ulzPiiDCZdFbBq2s,883
18
+ ballchasing/util/iterators.py,sha256=P5uUocfv0vqoV4NKtxpGYS83MmfhntqNyNRbfcaU160,4258
19
+ ballchasing/util/replays.py,sha256=4OmDqrNrjHKz6G9iVVz01UWq3KGJGEYbWJ-nNaDqK0E,8380
20
+ ballchasing/util/stats.py,sha256=WhyLhKwUbHErjaabK5RhEL8nvDz-wCCE1HGxcZ9Ea0U,2592
21
+ python_ballchasing-0.6.0.dist-info/licenses/LICENSE,sha256=ua0R_J89EfdcyYXy_6TMz6BoSxABvyBYCfgfOKu12FE,1075
22
+ python_ballchasing-0.6.0.dist-info/METADATA,sha256=4poYYz_mhDWAD2CtfUyEiw4BIac0NZYUMzU6tk8JbgQ,4621
23
+ python_ballchasing-0.6.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
24
+ python_ballchasing-0.6.0.dist-info/top_level.txt,sha256=YmO-pVNVRUMdF138yyv1K23a2FVsiEEX1dtyfWPzwmI,12
25
+ python_ballchasing-0.6.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (84.0.0)
2
+ Generator: setuptools (84.2.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1 @@
1
+ ballchasing
@@ -1,26 +0,0 @@
1
- ballchasing/__init__.py,sha256=xEWxUkk8wQ5V2zjq8I7JccccrgPxu60jGgAL779JP5k,2770
2
- ballchasing/api.py,sha256=JPnkwt1XPEzh_ueNJa0l9HmE9Wf6ptJ-1YTwp7xfyHU,30850
3
- ballchasing/constants.py,sha256=BEVGNljc5K1AxkaXc1nyXwhGZ8ceHDLmA8hReOBikVQ,12705
4
- ballchasing/rate_limit.py,sha256=zr31_oo741xordFwG4oO42aPbec8Vu22zTcmeaMjgcQ,9489
5
- ballchasing/stats_info.tsv,sha256=IBvVe0CF5HsTvNJFQlVCT4zeq-RfiKvgtro5a8KMTis,12258
6
- ballchasing/typed/__init__.py,sha256=oHkYhNK4m1tNwq_E72CYi-mUpoqo9w2kgEF17SdcRP4,279
7
- ballchasing/typed/deep_group.py,sha256=WCl3oldYLn0ogXn9sQXIZcck9Sr5bl6rM_EJiJ3x3uY,12916
8
- ballchasing/typed/deep_replay.py,sha256=hiIHgrEdBhTuADslscLQU1RPNd8YQ9sZJVflY1Y6TSw,7856
9
- ballchasing/typed/shallow_group.py,sha256=i-WvkqkBV4WBy_UbcWoZcas0yryggzCQpU-8Qm2FL7A,453
10
- ballchasing/typed/shallow_replay.py,sha256=r4zfCbHTJ4lf6VNcr6FSkXY_YD9p7Z3U6e0xWlzZZ9I,1877
11
- ballchasing/typed/shared.py,sha256=c9kgY1ecdVQDFTjWQVA_EmJ1ABBsf8jTZZ0ohIl8bnw,7977
12
- ballchasing/util/__init__.py,sha256=ISyxzGEJy2_wzJnikHK5Qo0N4zU0U0YsVP9sOa9v5NI,90
13
- ballchasing/util/dates.py,sha256=gUSldK6-jMNbGLaBiYwmiKUR0h0ulzPiiDCZdFbBq2s,883
14
- ballchasing/util/iterators.py,sha256=1An0MiQ6QZHLpa-38eDYek-OrOGLI5pI9m0h1YDKUdc,4196
15
- ballchasing/util/replays.py,sha256=4OmDqrNrjHKz6G9iVVz01UWq3KGJGEYbWJ-nNaDqK0E,8380
16
- ballchasing/util/stats.py,sha256=8Bi3TvbUmV97eVXY1moc8hjTUetKXZ8XAhSJFW_DC8s,2461
17
- python_ballchasing-0.5.3.dist-info/licenses/LICENSE,sha256=ua0R_J89EfdcyYXy_6TMz6BoSxABvyBYCfgfOKu12FE,1075
18
- scripts/get_maps.py,sha256=y3X28uqoi4kRo8OMZH0c2JS0AGlNCl4ZLO4d7_ZVteA,6065
19
- scripts/make_types.py,sha256=6EBF5V0Lh7bt7LTKKBWJI8jywVObpDC20-GYOOdFqFU,6588
20
- scripts/test.py,sha256=j_qRBqFeymHtzh75z9JQxpwJSnAwsmljSsS8b2yyu9I,2748
21
- scripts/test_typed.py,sha256=3XYwQWVLqH2L_gr6FOfZ_elXYvSipzAhnmVUXYH1te4,3116
22
- tests/test_fixes.py,sha256=swVEcvuXM6Kba3ce90ZduCMBOl36NBT2TRKKYBY-Bqw,20593
23
- python_ballchasing-0.5.3.dist-info/METADATA,sha256=WZ1Y9vdpVrxUG8VdfoMISeatQUwh9cX57kPddVKe8oI,3687
24
- python_ballchasing-0.5.3.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
25
- python_ballchasing-0.5.3.dist-info/top_level.txt,sha256=XsIp-HGAPOjN3ZpjMRRGvJcbra_qptToUFUjAOk5VZA,26
26
- python_ballchasing-0.5.3.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- ballchasing
2
- scripts
3
- tests
scripts/get_maps.py DELETED
@@ -1,147 +0,0 @@
1
- import json
2
- import os
3
- import re
4
- from collections import Counter
5
- from itertools import chain
6
-
7
- import requests
8
- from tqdm import tqdm
9
-
10
- import ballchasing as bc
11
-
12
- key = os.environ.get("BALLCHASING_API_KEY")
13
-
14
- api = bc.Api(key)
15
-
16
- all_maps = api.get_maps()
17
-
18
- if "uf_day_p" not in all_maps:
19
- print("Adding Futura Garden map to the list")
20
- all_maps["uf_day_p"] = "Futura Garden"
21
- if "stadium_10a_p" not in all_maps:
22
- print("Adding 10th Anniversary Stadium map to the list")
23
- all_maps["stadium_10a_p"] = "DFH Stadium (10th Anniversary)"
24
- for map_code, map_name in all_maps.items():
25
- if "(" in map_name and ")" not in map_name:
26
- # Fix maps with missing closing parenthesis
27
- print(f"Adding missing parenthesis for map {map_code}: {map_name}")
28
- all_maps[map_code] = map_name + ")"
29
-
30
- rlbot_map_list = requests.get(
31
- "https://raw.githubusercontent.com/RLBot/gui/refs/heads/master/frontend/src/arena-names.ts"
32
- ).text
33
- standard_maps_rlbot = re.search(r"MAPS_STANDARD\s*=\s*(\{[^}]+\})", rlbot_map_list)
34
- if standard_maps_rlbot:
35
- standard_maps_rlbot = eval(standard_maps_rlbot.group(1))
36
- standard_maps_rlbot = {v.lower(): k for k, v in standard_maps_rlbot.items()}
37
- else:
38
- standard_maps_rlbot = {}
39
-
40
- nonstandard_maps_rlbot = re.search(r"MAPS_NON_STANDARD\s*=\s*(\{[^}]+\})", rlbot_map_list)
41
- if nonstandard_maps_rlbot:
42
- nonstandard_maps_rlbot = eval(nonstandard_maps_rlbot.group(1))
43
- nonstandard_maps_rlbot = {v.lower(): k for k, v in nonstandard_maps_rlbot.items()}
44
- else:
45
- nonstandard_maps_rlbot = {}
46
-
47
- # Some corrections:
48
- # if "farm_hw_p" in standard_maps_rlbot:
49
- # standard_maps_rlbot["farm_hw_p"] = nonstandard_maps_rlbot["farm_hw_p"]
50
- # del nonstandard_maps_rlbot["farm_hw_p"]
51
- standard_maps_rlbot["woods_night_p"] = all_maps["woods_night_p"]
52
- standard_maps_rlbot["farm_upsidedown_p"] = all_maps["farm_upsidedown_p"]
53
-
54
- # Update all_maps with any missing maps that are in the RLBot list
55
- for map_code, map_name in chain(standard_maps_rlbot.items(), nonstandard_maps_rlbot.items()):
56
- if map_code not in all_maps:
57
- all_maps[map_code] = map_name
58
-
59
-
60
- # for seasons in bc.Season.ALL[::-1]:
61
- # # Check start and end of season in case of removals
62
- # for sort_dir in (bc.SortDir.ASCENDING, bc.SortDir.DESCENDING):
63
- # for replay in api.get_replays(season=seasons, sort_dir=sort_dir, count=200):
64
- # map_code = replay.get("map_code")
65
- # if map_code is None:
66
- # print(f"Replay {replay['id']} has no map code!")
67
- # continue
68
- # map_name = replay.get("map_name") # Likely missing
69
- # if map_code not in all_maps:
70
- # print(f"Map {map_code} ({map_name}) not in the list of maps!")
71
- # print()
72
-
73
-
74
- def print_maps(maps: dict):
75
- print(", ".join(f'"{m}"' for m in sorted(maps.keys())))
76
- print(", ".join(f'{m.upper()}' for m in sorted(maps.keys())))
77
- print(", ".join(f'"{maps[m]}"' for m in sorted(maps.keys())))
78
- print()
79
-
80
-
81
- print_maps(all_maps)
82
-
83
- standard_playlists = bc.Playlist.RANKED + bc.Playlist.UNRANKED
84
- non_standard_playlists = [bc.Playlist.RANKED_HOOPS, bc.Playlist.RANKED_DROPSHOT,
85
- bc.Playlist.HOOPS, bc.Playlist.DROPSHOT,
86
- bc.Playlist.GRIDIRON, bc.Playlist.ROCKETLABS]
87
-
88
-
89
- def check_map(code):
90
- map_name = all_maps.get(code, None)
91
- if map_code in standard_maps_rlbot or map_name in standard_maps_rlbot.values():
92
- return True
93
- if map_code in nonstandard_maps_rlbot or map_name in nonstandard_maps_rlbot.values():
94
- return False
95
- # return None
96
- # First, check playlists with only non-standard maps
97
- for replay in api.get_replays(map_id=code, playlist=non_standard_playlists, count=100):
98
- if replay["playlist_id"] in non_standard_playlists:
99
- return False
100
-
101
- # Check both casual and ranked
102
- for playlists in (bc.Playlist.RANKED + (bc.Playlist.RANKED_SNOWDAY,),
103
- bc.Playlist.UNRANKED):
104
- # Start with later seasons since it can include more maps, but do them individually in case of changing maps
105
- # Do only f2p since a few early seasons had non-standard maps
106
- for seasons in bc.Season.FREE_TO_PLAY[::-1]:
107
- # Check start and end of season in case of removals
108
- for sort_dir in (bc.SortDir.ASCENDING, bc.SortDir.DESCENDING):
109
- for replay in api.get_replays(season=seasons, map_id=code, playlist=playlists, sort_dir=sort_dir,
110
- count=200):
111
- if replay["playlist_id"] in bc.Playlist.RANKED:
112
- return True
113
- elif replay["playlist_id"] in bc.Playlist.UNRANKED:
114
- return None
115
- return False
116
-
117
-
118
- standard_maps = {}
119
- uncertain_maps = {}
120
- non_standard_maps = {}
121
- for map_code, map_name in tqdm(all_maps.items()):
122
- res = check_map(map_code)
123
- if res:
124
- standard_maps[map_code] = map_name
125
- elif res is None:
126
- uncertain_maps[map_code] = map_name
127
- else:
128
- non_standard_maps[map_code] = map_name
129
-
130
- print_maps(standard_maps)
131
- print_maps(uncertain_maps)
132
- print_maps(non_standard_maps)
133
- print_maps({**non_standard_maps, **uncertain_maps})
134
- print("Done!")
135
-
136
- # Check if current constants agree
137
- from ballchasing.constants import Map
138
-
139
- if set(m.lower() for m in Map.ALL) != set(all_maps.keys()):
140
- print("Current Map constants do not match the discovered maps!")
141
- print("Missing from Map.ALL:", set(all_maps.keys()) - set(m.lower() for m in Map.ALL))
142
- if set(m.lower() for m in Map.STANDARD_MAPS) != set(standard_maps.keys()):
143
- print("Current Map.STANDARD constants do not match the discovered standard maps!")
144
- print("Missing from Map.STANDARD:", set(standard_maps.keys()) - set(m.lower() for m in Map.STANDARD_MAPS))
145
- if set(m.lower() for m in Map.NON_STANDARD_MAPS) != set(non_standard_maps.keys()):
146
- print("Current Map.NON_STANDARD constants do not match the discovered non-standard maps!")
147
- print("Missing from Map.NON_STANDARD:", set(non_standard_maps.keys()) - set(m.lower() for m in Map.NON_STANDARD_MAPS))