rustat-python-api 0.1.0__tar.gz → 0.1.2__tar.gz

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.
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.1
2
+ Name: rustat-python-api
3
+ Version: 0.1.2
4
+ Summary: A Python wrapper for RuStat API
5
+ Home-page: https://github.com/dailydaniel/rustat-python-api
6
+ Author: Daniel Zholkovsky
7
+ Author-email: daniel@zholkovsky.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+
16
+ # rustat-python-api
17
+
18
+ ### Python wrapper for the Rustat API
19
+ ### Example of usage:
20
+ 0. Install the package:
21
+ ```bash
22
+ pip install rustat-python-api
23
+ ```
24
+ 1. Usage:
25
+ ```python
26
+ from rustat_python_api import RuStatParser
27
+
28
+ user = "your_login"
29
+ password = "your_password"
30
+
31
+ parser = RuStatParser(user, password)
32
+
33
+ info = parser.get_rpl_info()
34
+ keys = list(info.keys())
35
+ season_id, team_id = keys[-1], info[keys[-1]]["season_teams"][0]["id"]
36
+
37
+ schedule = parser.get_schedule(team_id, season_id)
38
+ keys = list(schedule.keys())
39
+ match_id = keys[-1]
40
+
41
+ events = parser.get_events(match_id)
42
+
43
+ stats = parser.get_match_stats(match_id)
44
+
45
+ tracking = parser.get_tracking(match_id)
46
+ ```
@@ -0,0 +1,31 @@
1
+ # rustat-python-api
2
+
3
+ ### Python wrapper for the Rustat API
4
+ ### Example of usage:
5
+ 0. Install the package:
6
+ ```bash
7
+ pip install rustat-python-api
8
+ ```
9
+ 1. Usage:
10
+ ```python
11
+ from rustat_python_api import RuStatParser
12
+
13
+ user = "your_login"
14
+ password = "your_password"
15
+
16
+ parser = RuStatParser(user, password)
17
+
18
+ info = parser.get_rpl_info()
19
+ keys = list(info.keys())
20
+ season_id, team_id = keys[-1], info[keys[-1]]["season_teams"][0]["id"]
21
+
22
+ schedule = parser.get_schedule(team_id, season_id)
23
+ keys = list(schedule.keys())
24
+ match_id = keys[-1]
25
+
26
+ events = parser.get_events(match_id)
27
+
28
+ stats = parser.get_match_stats(match_id)
29
+
30
+ tracking = parser.get_tracking(match_id)
31
+ ```
@@ -3,11 +3,11 @@ import pandas as pd
3
3
  from collections import defaultdict
4
4
  from tqdm import tqdm
5
5
 
6
- from urls import URLs
6
+ from .urls import URLs
7
7
 
8
8
 
9
9
  class RuStatParser:
10
- def __init__(self, user: str, password: str):
10
+ def __init__(self, user: str, password: str, urls: dict = URLs):
11
11
  self.numeric_columns = [
12
12
  'id', 'number', 'player_id', 'team_id', 'half', 'second',
13
13
  'pos_x', 'pos_y', 'pos_dest_x', 'pos_dest_y', 'len', 'possession_id', 'possession_team_id',
@@ -17,6 +17,7 @@ class RuStatParser:
17
17
 
18
18
  self.user = user
19
19
  self.password = password
20
+ self.urls = urls
20
21
 
21
22
  self.cached_info = {}
22
23
 
@@ -28,7 +29,7 @@ class RuStatParser:
28
29
  def get_rpl_info(self):
29
30
  for season_id in tqdm(range(1, 36)):
30
31
  data = self.resp2data(
31
- URLs["tournament_teams"].format(
32
+ self.urls["tournament_teams"].format(
32
33
  user=self.user,
33
34
  password=self.password,
34
35
  season_id=season_id
@@ -38,7 +39,7 @@ class RuStatParser:
38
39
  if data:
39
40
  first_team_id = data["data"]["row"][0]["id"]
40
41
  first_team_schedule = self.resp2data(
41
- URLs["schedule"].format(
42
+ self.urls["schedule"].format(
42
43
  user=self.user,
43
44
  password=self.password,
44
45
  team_id=first_team_id,
@@ -61,7 +62,7 @@ class RuStatParser:
61
62
 
62
63
  def get_schedule(self, team_id: str, season_id: str) -> dict:
63
64
  data = self.resp2data(
64
- URLs["schedule"].format(
65
+ self.urls["schedule"].format(
65
66
  user=self.user,
66
67
  password=self.password,
67
68
  team_id=team_id,
@@ -85,7 +86,7 @@ class RuStatParser:
85
86
 
86
87
  def get_events(self, match_id: int) -> pd.DataFrame | None:
87
88
  data = self.resp2data(
88
- URLs["events"].format(
89
+ self.urls["events"].format(
89
90
  user=self.user,
90
91
  password=self.password,
91
92
  match_id=match_id
@@ -102,9 +103,43 @@ class RuStatParser:
102
103
 
103
104
  return df
104
105
 
106
+ def get_tracking(self, match_id: int) -> pd.DataFrame | None:
107
+ data = self.resp2data(
108
+ self.urls["tracking"].format(
109
+ user=self.user,
110
+ password=self.password,
111
+ match_id=match_id
112
+ )
113
+ )
114
+
115
+ if not data:
116
+ return None
117
+
118
+ data = data["data"]["team"]
119
+ df = pd.DataFrame(columns=["half", "second", "pos_x", "pos_y", "team_id", "player_id", "player_name", "side_1h"])
120
+
121
+ for team_data in tqdm(data):
122
+ team_id = team_data["id"]
123
+ side_1h = team_data["gate_position_half_1"]
124
+
125
+ for player_data in team_data["player"]:
126
+ player_id = player_data["id"]
127
+ player_name = player_data["name"]
128
+
129
+ cur_df = pd.json_normalize(player_data["row"])
130
+ cur_df = cur_df.apply(pd.to_numeric, errors='coerce')
131
+ cur_df["team_id"] = team_id
132
+ cur_df["player_id"] = player_id
133
+ cur_df["player_name"] = player_name
134
+ cur_df["side_1h"] = side_1h
135
+
136
+ df = pd.concat([df, cur_df], ignore_index=True)
137
+
138
+ return df.sort_values(by=["second", "team_id", "player_id"])
139
+
105
140
  def get_match_stats(self, match_id: int) -> dict:
106
141
  data = self.resp2data(
107
- URLs["match_stats"].format(
142
+ self.urls["match_stats"].format(
108
143
  user=self.user,
109
144
  password=self.password,
110
145
  match_id=match_id
@@ -2,5 +2,6 @@ URLs = {
2
2
  "schedule": "http://feeds.rustatsport.ru/?tpl=35&user={user}&key={password}&team_id={team_id}&season_id={season_id}&date_start=&date_end=&format=json",
3
3
  "events": "http://feeds.rustatsport.ru/?tpl=36&user={user}&key={password}&match_id={match_id}&start_ms=0&dl=0&lang_id=1&format=json",
4
4
  "match_stats": "http://feeds.rustatsport.ru/?tpl=207&user={user}&key={password}&match_id={match_id}&lang_id=1&format=json",
5
- "tournament_teams": "http://feeds.rustatsport.ru/?tpl=32&user={user}&key={password}&tournament_id=2&season_id={season_id}&date_start=&date_end=&lang_id=1&format=json"
5
+ "tournament_teams": "http://feeds.rustatsport.ru/?tpl=32&user={user}&key={password}&tournament_id=2&season_id={season_id}&date_start=&date_end=&lang_id=1&format=json",
6
+ "tracking": "https://feeds.rustatsport.ru/?tpl=274&user={user}&key={password}&match_id={match_id}&lang_id=0&format=json"
6
7
  }
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.1
2
+ Name: rustat-python-api
3
+ Version: 0.1.2
4
+ Summary: A Python wrapper for RuStat API
5
+ Home-page: https://github.com/dailydaniel/rustat-python-api
6
+ Author: Daniel Zholkovsky
7
+ Author-email: daniel@zholkovsky.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+
16
+ # rustat-python-api
17
+
18
+ ### Python wrapper for the Rustat API
19
+ ### Example of usage:
20
+ 0. Install the package:
21
+ ```bash
22
+ pip install rustat-python-api
23
+ ```
24
+ 1. Usage:
25
+ ```python
26
+ from rustat_python_api import RuStatParser
27
+
28
+ user = "your_login"
29
+ password = "your_password"
30
+
31
+ parser = RuStatParser(user, password)
32
+
33
+ info = parser.get_rpl_info()
34
+ keys = list(info.keys())
35
+ season_id, team_id = keys[-1], info[keys[-1]]["season_teams"][0]["id"]
36
+
37
+ schedule = parser.get_schedule(team_id, season_id)
38
+ keys = list(schedule.keys())
39
+ match_id = keys[-1]
40
+
41
+ events = parser.get_events(match_id)
42
+
43
+ stats = parser.get_match_stats(match_id)
44
+
45
+ tracking = parser.get_tracking(match_id)
46
+ ```
@@ -1,2 +1,3 @@
1
1
  requests==2.32.3
2
2
  pandas==2.2.3
3
+ tqdm==4.66.5
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='rustat-python-api',
5
- version='0.1.0',
5
+ version='0.1.2',
6
6
  description='A Python wrapper for RuStat API',
7
7
  long_description=open('README.md').read(),
8
8
  long_description_content_type='text/markdown',
@@ -14,6 +14,7 @@ setup(
14
14
  install_requires=[
15
15
  'requests==2.32.3',
16
16
  'pandas==2.2.3',
17
+ 'tqdm==4.66.5'
17
18
  ],
18
19
  classifiers=[
19
20
  'Programming Language :: Python :: 3',
@@ -1,16 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: rustat-python-api
3
- Version: 0.1.0
4
- Summary: A Python wrapper for RuStat API
5
- Home-page: https://github.com/dailydaniel/rustat-python-api
6
- Author: Daniel Zholkovsky
7
- Author-email: daniel@zholkovsky.com
8
- License: MIT
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.10
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
-
16
- # rustat-python-api
@@ -1 +0,0 @@
1
- # rustat-python-api
@@ -1,16 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: rustat-python-api
3
- Version: 0.1.0
4
- Summary: A Python wrapper for RuStat API
5
- Home-page: https://github.com/dailydaniel/rustat-python-api
6
- Author: Daniel Zholkovsky
7
- Author-email: daniel@zholkovsky.com
8
- License: MIT
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.10
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
-
16
- # rustat-python-api