Elo-MMR-Py 1.0.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,13 @@
1
+ [package]
2
+ name = "elo-mmr-python-bindings"
3
+ version = "1.0.0"
4
+ edition = "2021"
5
+
6
+ [lib]
7
+ name = "elo_mmr_python_bindings"
8
+ path = "src/rust/lib.rs"
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ pyo3 = { version = "0.16.2", features = ["extension-module"] }
13
+ multi-skill = { git = "https://github.com/EbTech/Elo-MMR", rev="82c2a1ccd310ae041c32df1007e98cde07d52979" }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Aleksey Ropan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include Cargo.toml
2
+ recursive-include src/rust *
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.1
2
+ Name: Elo-MMR-Py
3
+ Version: 1.0.2
4
+ Summary: Python bindings for Elo-MRR
5
+ Author: Aleksey Ropan
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Aleksey Ropan
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Discussion, https://github.com/aropan/Elo-MMR-Py/discussions
29
+ Project-URL: Issues, https://github.com/aropan/Elo-MMR-Py/issues
30
+ Project-URL: Repository, https://github.com/aropan/Elo-MMR-Py
31
+ Keywords: rating,competition,skill,mmr,elo,trueskill,endure,glicko,python,rust
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Programming Language :: Python
37
+ Classifier: Programming Language :: Rust
38
+ Classifier: Topic :: Games/Entertainment
39
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
40
+ Classifier: Topic :: Utilities
41
+ Description-Content-Type: text/markdown
42
+ License-File: LICENSE
43
+
44
+ # Elo-MMR-Py
45
+
46
+ Python bindings for [Elo-MRR](https://github.com/EbTech/Elo-MMR).
47
+
48
+ ## Installation
49
+
50
+ You can install using pip. This is the easiest way to install the package and its dependencies.
51
+
52
+ ### Install from PyPI
53
+
54
+ To install the latest released version from PyPI, run the following command:
55
+
56
+ ```python
57
+ pip install Elo-MMR-Py
58
+ ```
59
+
60
+ This will download and install the latest version of Elo-MMR-Py from PyPI.
61
+
62
+ ### Install from Source
63
+
64
+ To install Elo-MMR-Py directly from the source code using Git, run:
65
+
66
+
67
+ ```python
68
+ pip install git+https://github.com/aropan/Elo-MMR-Py.git
69
+ ```
70
+
71
+ #### Usage
72
+
73
+ After installation, you can import and use Elo-MMR-Py in your Python projects:
74
+
75
+ ```python
76
+ from elo_mmr_py import Contest, rate
77
+
78
+ contests = [
79
+ Contest(standings=[('player_1', 0, 0), ('player_2', 1, 1), ('player_3', 2, 2)]),
80
+ Contest(standings=[('player_1', 0, 1), ('player_2', 0, 1), ('player_3', 2, 2)]),
81
+ Contest(standings=[('player_1', 0, 0), ('player_2', 1, 2), ('player_3', 1, 2)]),
82
+ Contest(standings=[('player_4', 0, 0), ('player_1', 1, 1), ('player_2', 2, 2), ('player_3', 3, 3)]),
83
+ Contest(standings=[('player_4', 0, 0), ('player_1', 1, 1), ('player_2', 2, 2), ('player_3', 3, 3)]),
84
+ ]
85
+ players = rate(contests)
86
+
87
+ from pprint import pprint
88
+ pprint(players)
89
+ ```
90
+
91
+ Output for example above:
92
+
93
+ ```python
94
+ {'player_1': Player(name='player_1',
95
+ rating=1675,
96
+ events=[PyPlayerEvent(contest_index=0, rating_mu=1705, rating_sig=171, perf_score=1744, place=0),
97
+ PyPlayerEvent(contest_index=1, rating_mu=1663, rating_sig=130, perf_score=1618, place=0),
98
+ PyPlayerEvent(contest_index=2, rating_mu=1686, rating_sig=111, perf_score=1728, place=0),
99
+ PyPlayerEvent(contest_index=3, rating_mu=1678, rating_sig=100, perf_score=1660, place=1),
100
+ PyPlayerEvent(contest_index=4, rating_mu=1675, rating_sig=94, perf_score=1666, place=1)]),
101
+ 'player_2': Player(name='player_2',
102
+ rating=1483,
103
+ events=[PyPlayerEvent(contest_index=0, rating_mu=1500, rating_sig=171, perf_score=1500, place=1),
104
+ PyPlayerEvent(contest_index=1, rating_mu=1555, rating_sig=130, perf_score=1618, place=0),
105
+ PyPlayerEvent(contest_index=2, rating_mu=1500, rating_sig=111, perf_score=1393, place=1),
106
+ PyPlayerEvent(contest_index=3, rating_mu=1487, rating_sig=100, perf_score=1459, place=2),
107
+ PyPlayerEvent(contest_index=4, rating_mu=1483, rating_sig=94, perf_score=1471, place=2)]),
108
+ 'player_3': Player(name='player_3',
109
+ rating=1279,
110
+ events=[PyPlayerEvent(contest_index=0, rating_mu=1295, rating_sig=171, perf_score=1256, place=2),
111
+ PyPlayerEvent(contest_index=1, rating_mu=1270, rating_sig=130, perf_score=1242, place=2),
112
+ PyPlayerEvent(contest_index=2, rating_mu=1312, rating_sig=111, perf_score=1393, place=1),
113
+ PyPlayerEvent(contest_index=3, rating_mu=1291, rating_sig=100, perf_score=1240, place=3),
114
+ PyPlayerEvent(contest_index=4, rating_mu=1279, rating_sig=94, perf_score=1247, place=3)]),
115
+ 'player_4': Player(name='player_4',
116
+ rating=1809,
117
+ events=[PyPlayerEvent(contest_index=3, rating_mu=1767, rating_sig=171, perf_score=1819, place=0),
118
+ PyPlayerEvent(contest_index=4, rating_mu=1809, rating_sig=130, perf_score=1855, place=0)])}
119
+ ```
120
+
121
+ ### Contributing
122
+
123
+ Welcome contributions! If you would like to contribute to the project, please fork the repository and submit a pull request.
@@ -0,0 +1,80 @@
1
+ # Elo-MMR-Py
2
+
3
+ Python bindings for [Elo-MRR](https://github.com/EbTech/Elo-MMR).
4
+
5
+ ## Installation
6
+
7
+ You can install using pip. This is the easiest way to install the package and its dependencies.
8
+
9
+ ### Install from PyPI
10
+
11
+ To install the latest released version from PyPI, run the following command:
12
+
13
+ ```python
14
+ pip install Elo-MMR-Py
15
+ ```
16
+
17
+ This will download and install the latest version of Elo-MMR-Py from PyPI.
18
+
19
+ ### Install from Source
20
+
21
+ To install Elo-MMR-Py directly from the source code using Git, run:
22
+
23
+
24
+ ```python
25
+ pip install git+https://github.com/aropan/Elo-MMR-Py.git
26
+ ```
27
+
28
+ #### Usage
29
+
30
+ After installation, you can import and use Elo-MMR-Py in your Python projects:
31
+
32
+ ```python
33
+ from elo_mmr_py import Contest, rate
34
+
35
+ contests = [
36
+ Contest(standings=[('player_1', 0, 0), ('player_2', 1, 1), ('player_3', 2, 2)]),
37
+ Contest(standings=[('player_1', 0, 1), ('player_2', 0, 1), ('player_3', 2, 2)]),
38
+ Contest(standings=[('player_1', 0, 0), ('player_2', 1, 2), ('player_3', 1, 2)]),
39
+ Contest(standings=[('player_4', 0, 0), ('player_1', 1, 1), ('player_2', 2, 2), ('player_3', 3, 3)]),
40
+ Contest(standings=[('player_4', 0, 0), ('player_1', 1, 1), ('player_2', 2, 2), ('player_3', 3, 3)]),
41
+ ]
42
+ players = rate(contests)
43
+
44
+ from pprint import pprint
45
+ pprint(players)
46
+ ```
47
+
48
+ Output for example above:
49
+
50
+ ```python
51
+ {'player_1': Player(name='player_1',
52
+ rating=1675,
53
+ events=[PyPlayerEvent(contest_index=0, rating_mu=1705, rating_sig=171, perf_score=1744, place=0),
54
+ PyPlayerEvent(contest_index=1, rating_mu=1663, rating_sig=130, perf_score=1618, place=0),
55
+ PyPlayerEvent(contest_index=2, rating_mu=1686, rating_sig=111, perf_score=1728, place=0),
56
+ PyPlayerEvent(contest_index=3, rating_mu=1678, rating_sig=100, perf_score=1660, place=1),
57
+ PyPlayerEvent(contest_index=4, rating_mu=1675, rating_sig=94, perf_score=1666, place=1)]),
58
+ 'player_2': Player(name='player_2',
59
+ rating=1483,
60
+ events=[PyPlayerEvent(contest_index=0, rating_mu=1500, rating_sig=171, perf_score=1500, place=1),
61
+ PyPlayerEvent(contest_index=1, rating_mu=1555, rating_sig=130, perf_score=1618, place=0),
62
+ PyPlayerEvent(contest_index=2, rating_mu=1500, rating_sig=111, perf_score=1393, place=1),
63
+ PyPlayerEvent(contest_index=3, rating_mu=1487, rating_sig=100, perf_score=1459, place=2),
64
+ PyPlayerEvent(contest_index=4, rating_mu=1483, rating_sig=94, perf_score=1471, place=2)]),
65
+ 'player_3': Player(name='player_3',
66
+ rating=1279,
67
+ events=[PyPlayerEvent(contest_index=0, rating_mu=1295, rating_sig=171, perf_score=1256, place=2),
68
+ PyPlayerEvent(contest_index=1, rating_mu=1270, rating_sig=130, perf_score=1242, place=2),
69
+ PyPlayerEvent(contest_index=2, rating_mu=1312, rating_sig=111, perf_score=1393, place=1),
70
+ PyPlayerEvent(contest_index=3, rating_mu=1291, rating_sig=100, perf_score=1240, place=3),
71
+ PyPlayerEvent(contest_index=4, rating_mu=1279, rating_sig=94, perf_score=1247, place=3)]),
72
+ 'player_4': Player(name='player_4',
73
+ rating=1809,
74
+ events=[PyPlayerEvent(contest_index=3, rating_mu=1767, rating_sig=171, perf_score=1819, place=0),
75
+ PyPlayerEvent(contest_index=4, rating_mu=1809, rating_sig=130, perf_score=1855, place=0)])}
76
+ ```
77
+
78
+ ### Contributing
79
+
80
+ Welcome contributions! If you would like to contribute to the project, please fork the repository and submit a pull request.
@@ -0,0 +1,66 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel", "setuptools-rust"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "Elo-MMR-Py"
7
+ version = "1.0.2"
8
+ readme = "README.md"
9
+ description = "Python bindings for Elo-MRR"
10
+ authors = [{name = "Aleksey Ropan"}]
11
+ license = {file = "LICENSE"}
12
+ keywords = ['rating', 'competition', 'skill', 'mmr', 'elo', 'trueskill', 'endure', 'glicko', 'python', 'rust']
13
+ classifiers = [
14
+ "Intended Audience :: Developers",
15
+ "Intended Audience :: Science/Research",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python",
19
+ "Programming Language :: Rust",
20
+ "Topic :: Games/Entertainment",
21
+ "Topic :: Software Development :: Libraries :: Python Modules",
22
+ "Topic :: Utilities"
23
+ ]
24
+
25
+ [project.urls]
26
+ Discussion = "https://github.com/aropan/Elo-MMR-Py/discussions"
27
+ Issues = "https://github.com/aropan/Elo-MMR-Py/issues"
28
+ Repository = "https://github.com/aropan/Elo-MMR-Py"
29
+
30
+ [[tool.setuptools-rust.ext-modules]]
31
+ target = "elo_mmr_py.elo_mmr_python_bindings"
32
+
33
+ [tool.cibuildwheel]
34
+ skip = "*musllinux* pp* cp27-* cp35-* cp36-* cp37-* cp38-*"
35
+ build-verbosity = 1
36
+ environment = { VERBOSE = "1" }
37
+ test-requires = "pytest"
38
+ test-command = "pytest {project}/tests -s -v"
39
+
40
+ [tool.cibuildwheel.linux]
41
+ environment = 'PATH="$HOME/.cargo/bin:$PATH"'
42
+ before-build = "yum install -y openssl-devel && curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y && rustup show"
43
+
44
+ [tool.cibuildwheel.macos]
45
+ archs = 'x86_64 arm64'
46
+ environment = 'PATH="$HOME/.cargo/bin:$PATH"'
47
+ before-build = "rustup default stable && rustup show"
48
+
49
+ [[tool.cibuildwheel.overrides]]
50
+ select = "*macos*x86_64*"
51
+ before-build = "rustup target add --toolchain stable x86_64-apple-darwin && rustup default stable-x86_64-apple-darwin && rustup show"
52
+
53
+ [[tool.cibuildwheel.overrides]]
54
+ select = "*macos*arm64*"
55
+ before-build = "rustup target add --toolchain stable aarch64-apple-darwin && rustup default stable-aarch64-apple-darwin && rustup show"
56
+
57
+ [tool.cibuildwheel.windows]
58
+ environment = 'PATH="$UserProfile\.cargo\bin;$PATH"'
59
+
60
+ [[tool.cibuildwheel.overrides]]
61
+ select = "*win32*"
62
+ before-build = "rustup toolchain install stable-i686-pc-windows-msvc && rustup default stable-i686-pc-windows-msvc && rustup override set stable-i686-pc-windows-msvc && rustup show"
63
+
64
+ [[tool.cibuildwheel.overrides]]
65
+ select = "*win_amd64*"
66
+ before-build = "rustup toolchain install stable-x86_64-pc-windows-msvc && rustup default stable-x86_64-pc-windows-msvc && rustup override set stable-x86_64-pc-windows-msvc && rustup show"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.1
2
+ Name: Elo-MMR-Py
3
+ Version: 1.0.2
4
+ Summary: Python bindings for Elo-MRR
5
+ Author: Aleksey Ropan
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Aleksey Ropan
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Discussion, https://github.com/aropan/Elo-MMR-Py/discussions
29
+ Project-URL: Issues, https://github.com/aropan/Elo-MMR-Py/issues
30
+ Project-URL: Repository, https://github.com/aropan/Elo-MMR-Py
31
+ Keywords: rating,competition,skill,mmr,elo,trueskill,endure,glicko,python,rust
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Programming Language :: Python
37
+ Classifier: Programming Language :: Rust
38
+ Classifier: Topic :: Games/Entertainment
39
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
40
+ Classifier: Topic :: Utilities
41
+ Description-Content-Type: text/markdown
42
+ License-File: LICENSE
43
+
44
+ # Elo-MMR-Py
45
+
46
+ Python bindings for [Elo-MRR](https://github.com/EbTech/Elo-MMR).
47
+
48
+ ## Installation
49
+
50
+ You can install using pip. This is the easiest way to install the package and its dependencies.
51
+
52
+ ### Install from PyPI
53
+
54
+ To install the latest released version from PyPI, run the following command:
55
+
56
+ ```python
57
+ pip install Elo-MMR-Py
58
+ ```
59
+
60
+ This will download and install the latest version of Elo-MMR-Py from PyPI.
61
+
62
+ ### Install from Source
63
+
64
+ To install Elo-MMR-Py directly from the source code using Git, run:
65
+
66
+
67
+ ```python
68
+ pip install git+https://github.com/aropan/Elo-MMR-Py.git
69
+ ```
70
+
71
+ #### Usage
72
+
73
+ After installation, you can import and use Elo-MMR-Py in your Python projects:
74
+
75
+ ```python
76
+ from elo_mmr_py import Contest, rate
77
+
78
+ contests = [
79
+ Contest(standings=[('player_1', 0, 0), ('player_2', 1, 1), ('player_3', 2, 2)]),
80
+ Contest(standings=[('player_1', 0, 1), ('player_2', 0, 1), ('player_3', 2, 2)]),
81
+ Contest(standings=[('player_1', 0, 0), ('player_2', 1, 2), ('player_3', 1, 2)]),
82
+ Contest(standings=[('player_4', 0, 0), ('player_1', 1, 1), ('player_2', 2, 2), ('player_3', 3, 3)]),
83
+ Contest(standings=[('player_4', 0, 0), ('player_1', 1, 1), ('player_2', 2, 2), ('player_3', 3, 3)]),
84
+ ]
85
+ players = rate(contests)
86
+
87
+ from pprint import pprint
88
+ pprint(players)
89
+ ```
90
+
91
+ Output for example above:
92
+
93
+ ```python
94
+ {'player_1': Player(name='player_1',
95
+ rating=1675,
96
+ events=[PyPlayerEvent(contest_index=0, rating_mu=1705, rating_sig=171, perf_score=1744, place=0),
97
+ PyPlayerEvent(contest_index=1, rating_mu=1663, rating_sig=130, perf_score=1618, place=0),
98
+ PyPlayerEvent(contest_index=2, rating_mu=1686, rating_sig=111, perf_score=1728, place=0),
99
+ PyPlayerEvent(contest_index=3, rating_mu=1678, rating_sig=100, perf_score=1660, place=1),
100
+ PyPlayerEvent(contest_index=4, rating_mu=1675, rating_sig=94, perf_score=1666, place=1)]),
101
+ 'player_2': Player(name='player_2',
102
+ rating=1483,
103
+ events=[PyPlayerEvent(contest_index=0, rating_mu=1500, rating_sig=171, perf_score=1500, place=1),
104
+ PyPlayerEvent(contest_index=1, rating_mu=1555, rating_sig=130, perf_score=1618, place=0),
105
+ PyPlayerEvent(contest_index=2, rating_mu=1500, rating_sig=111, perf_score=1393, place=1),
106
+ PyPlayerEvent(contest_index=3, rating_mu=1487, rating_sig=100, perf_score=1459, place=2),
107
+ PyPlayerEvent(contest_index=4, rating_mu=1483, rating_sig=94, perf_score=1471, place=2)]),
108
+ 'player_3': Player(name='player_3',
109
+ rating=1279,
110
+ events=[PyPlayerEvent(contest_index=0, rating_mu=1295, rating_sig=171, perf_score=1256, place=2),
111
+ PyPlayerEvent(contest_index=1, rating_mu=1270, rating_sig=130, perf_score=1242, place=2),
112
+ PyPlayerEvent(contest_index=2, rating_mu=1312, rating_sig=111, perf_score=1393, place=1),
113
+ PyPlayerEvent(contest_index=3, rating_mu=1291, rating_sig=100, perf_score=1240, place=3),
114
+ PyPlayerEvent(contest_index=4, rating_mu=1279, rating_sig=94, perf_score=1247, place=3)]),
115
+ 'player_4': Player(name='player_4',
116
+ rating=1809,
117
+ events=[PyPlayerEvent(contest_index=3, rating_mu=1767, rating_sig=171, perf_score=1819, place=0),
118
+ PyPlayerEvent(contest_index=4, rating_mu=1809, rating_sig=130, perf_score=1855, place=0)])}
119
+ ```
120
+
121
+ ### Contributing
122
+
123
+ Welcome contributions! If you would like to contribute to the project, please fork the repository and submit a pull request.
@@ -0,0 +1,12 @@
1
+ Cargo.toml
2
+ LICENSE
3
+ MANIFEST.in
4
+ README.md
5
+ pyproject.toml
6
+ src/Elo_MMR_Py.egg-info/PKG-INFO
7
+ src/Elo_MMR_Py.egg-info/SOURCES.txt
8
+ src/Elo_MMR_Py.egg-info/dependency_links.txt
9
+ src/Elo_MMR_Py.egg-info/top_level.txt
10
+ src/elo_mmr_py/__init__.py
11
+ src/rust/lib.rs
12
+ tests/test_elo_mmr_py.py
@@ -0,0 +1,2 @@
1
+ elo_mmr_py
2
+ rust
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Dict, List, Optional
5
+
6
+ from elo_mmr_py.elo_mmr_python_bindings import Contest, PlayerEvent
7
+ from elo_mmr_py.elo_mmr_python_bindings import rate as rust_rate
8
+
9
+
10
+ @dataclass
11
+ class Player:
12
+ name: str
13
+ rating: int
14
+ events: List[PlayerEvent]
15
+
16
+
17
+ def rate(
18
+ contests: List[Contest],
19
+ system: str = 'mmr',
20
+ mu_noob: float = 1500.,
21
+ sig_noob: float = 350.,
22
+ load_checkpoint: Optional[str] = None,
23
+ save_checkpoint: Optional[str] = None,
24
+ ) -> Dict[str, Player]:
25
+ """
26
+ Rates players based on their performance in contests.
27
+
28
+ Args:
29
+ system (str): The name of the rating system to use (e.g., "mmr", "glicko").
30
+ contests (List[PyContest]): A list of contest objects, each representing a single contest.
31
+ mu_noob (float): The initial mean rating for new players.
32
+ sig_noob (float): The initial rating deviation for new players.
33
+ load_checkpoint (Optional[str]): The path to a file from which to load the rating system state.
34
+ If None, the rating system starts without prior state.
35
+ save_checkpoint (Optional[str]): The path to a file where the rating system state will be saved
36
+ after processing all contests. If None, the state is not saved.
37
+
38
+ Returns:
39
+ PyRateResult: An object containing the results of the rating process, including
40
+ the final ratings of players and the time elapsed during the rating calculation.
41
+ """
42
+
43
+ rate_result = rust_rate(
44
+ system,
45
+ contests,
46
+ mu_noob=mu_noob,
47
+ sig_noob=sig_noob,
48
+ load_checkpoint=load_checkpoint,
49
+ save_checkpoint=save_checkpoint,
50
+ )
51
+ ret = {
52
+ name: Player(name, events[-1].rating_mu, events)
53
+ for name, events in rate_result.players_events.items()
54
+ }
55
+ return ret
@@ -0,0 +1,219 @@
1
+ use std::collections::HashMap;
2
+ use pyo3::prelude::*;
3
+ use pyo3::wrap_pyfunction;
4
+ use multi_skill::systems::{PlayerEvent, get_rating_system_by_name};
5
+ use multi_skill::experiment_config::{Experiment, ExperimentResults};
6
+ use multi_skill::data_processing::{Dataset, Contest, ContestDataset, BoxedDataset, read_json, ContestRatingParams};
7
+
8
+ /// A Contest object represents a competition.
9
+ ///
10
+ /// Args:
11
+ /// standings (List[Tuple[str, int, int]]): A list of tuples, each representing
12
+ /// a participant's standing with their name, low rank, and high rank.
13
+ /// name (Optional[str]): The name of the contest. Defaults to "".
14
+ /// time_seconds (Optional[int]): The duration of the contest in seconds. Defaults to 0.
15
+ /// url (Optional[str]): The URL of the contest. Defaults to None.
16
+ #[pyclass(name="Contest")]
17
+ #[derive(Clone)]
18
+ struct PyContest {
19
+ inner: Contest,
20
+ }
21
+
22
+ #[pymethods]
23
+ impl PyContest {
24
+ #[new]
25
+ #[args(standings, name = "None", time_seconds = "None", url = "None")]
26
+ fn new(
27
+ standings: Vec<(String, usize, usize)>,
28
+ name: Option<String>,
29
+ time_seconds: Option<u64>,
30
+ url: Option<String>,
31
+ ) -> PyResult<Self> {
32
+ let rating_params = ContestRatingParams::default();
33
+ let name = name.unwrap_or("".to_string());
34
+ let time_seconds = time_seconds.unwrap_or(0);
35
+ Ok(PyContest {
36
+ inner: Contest {
37
+ name,
38
+ url,
39
+ rating_params,
40
+ time_seconds,
41
+ standings,
42
+ },
43
+ })
44
+ }
45
+
46
+ #[getter]
47
+ fn name(&self) -> PyResult<&str> {
48
+ Ok(&self.inner.name)
49
+ }
50
+
51
+ #[getter]
52
+ fn time_seconds(&self) -> PyResult<u64> {
53
+ Ok(self.inner.time_seconds)
54
+ }
55
+
56
+ #[getter]
57
+ fn standings(&self) -> PyResult<Vec<(String, usize, usize)>> {
58
+ Ok(self.inner.standings.clone())
59
+ }
60
+
61
+ #[getter]
62
+ fn url(&self) -> PyResult<Option<&str>> {
63
+ Ok(self.inner.url.as_deref())
64
+ }
65
+ }
66
+
67
+ struct ContestVec(Vec<Contest>);
68
+
69
+ impl Dataset for ContestVec {
70
+ type Item = Contest;
71
+ fn len(&self) -> usize { self.0.len() }
72
+ fn get(&self, index: usize) -> Contest { self.0.get(index).unwrap().clone() }
73
+ }
74
+
75
+ /// Represents an event for a player in a contest.
76
+ ///
77
+ /// Args:
78
+ /// contest_index (int): The index of the contest.
79
+ /// rating_mu (int): The player's rating mean after the contest.
80
+ /// rating_sig (int): The player's rating deviation after the contest.
81
+ /// perf_score (int): The performance score of the player in the contest.
82
+ /// place (int): The place of the player in the contest.
83
+ #[pyclass(name="PlayerEvent")]
84
+ #[derive(Clone)]
85
+ struct PyPlayerEvent {
86
+ #[pyo3(get)]
87
+ contest_index: usize,
88
+ #[pyo3(get)]
89
+ rating_mu: i32,
90
+ #[pyo3(get)]
91
+ rating_sig: i32,
92
+ #[pyo3(get)]
93
+ perf_score: i32,
94
+ #[pyo3(get)]
95
+ place: usize,
96
+ }
97
+
98
+ #[pymethods]
99
+ impl PyPlayerEvent {
100
+ fn __repr__(&self) -> PyResult<String> {
101
+ Ok(format!(
102
+ "PyPlayerEvent(contest_index={}, rating_mu={}, rating_sig={}, perf_score={}, place={})",
103
+ self.contest_index, self.rating_mu, self.rating_sig, self.perf_score, self.place
104
+ ))
105
+ }
106
+
107
+ fn __str__(&self) -> PyResult<String> {
108
+ self.__repr__()
109
+ }
110
+ }
111
+
112
+ impl From<PlayerEvent> for PyPlayerEvent {
113
+ fn from(event: PlayerEvent) -> Self {
114
+ PyPlayerEvent {
115
+ contest_index: event.contest_index,
116
+ rating_mu: event.rating_mu,
117
+ rating_sig: event.rating_sig,
118
+ perf_score: event.perf_score,
119
+ place: event.place,
120
+ }
121
+ }
122
+ }
123
+
124
+ /// Represents the result of a rating calculation.
125
+ ///
126
+ /// Attributes:
127
+ /// players_events (Dict[str, List[PyPlayerEvent]]): A dictionary mapping player IDs
128
+ /// to a list of player events. Each event is an instance of `PyPlayerEvent`,
129
+ /// which contains information about the player's performance in a particular contest.
130
+ /// secs_elapsed (float): The number of seconds elapsed during the rating calculation process.
131
+ #[pyclass(name="RateResult")]
132
+ struct PyRateResult {
133
+ #[pyo3(get)]
134
+ players_events: HashMap<String, Vec<PyPlayerEvent>>,
135
+ #[pyo3(get)]
136
+ secs_elapsed: f64,
137
+ }
138
+
139
+ #[pymethods]
140
+ impl PyRateResult {
141
+ fn __repr__(&self) -> PyResult<String> {
142
+ let n_total_events: usize = self.players_events.values().map(|events| events.len()).sum();
143
+ Ok(format!(
144
+ "PyRateResult(n_players={}, n_total_events={}, secs_elapsed={})",
145
+ self.players_events.len(), n_total_events, self.secs_elapsed
146
+ ))
147
+ }
148
+
149
+ fn __str__(&self) -> PyResult<String> {
150
+ self.__repr__()
151
+ }
152
+ }
153
+
154
+ fn from_experiment_results(experiment_results: ExperimentResults) -> PyResult<PyRateResult> {
155
+ let players_py: HashMap<String, Vec<PyPlayerEvent>> = experiment_results.players
156
+ .into_iter()
157
+ .map(|(name, player_cell)| {
158
+ let player = player_cell.into_inner();
159
+ let events_py: Vec<PyPlayerEvent> = player.event_history.into_iter().map(PyPlayerEvent::from).collect();
160
+ (name, events_py)
161
+ })
162
+ .collect();
163
+
164
+ Ok(PyRateResult {
165
+ players_events: players_py,
166
+ secs_elapsed: experiment_results.secs_elapsed,
167
+ })
168
+ }
169
+
170
+ /// Rates players based on their performance in contests.
171
+ ///
172
+ /// Args:
173
+ /// system (str): The name of the rating system to use (e.g., "mmr", "glicko").
174
+ /// contests (List[PyContest]): A list of contest objects, each representing a single contest.
175
+ /// mu_noob (float): The initial mean rating for new players.
176
+ /// sig_noob (float): The initial rating deviation for new players.
177
+ /// load_checkpoint (Optional[str]): The path to a file from which to load the rating system state.
178
+ /// If None, the rating system starts without prior state.
179
+ /// save_checkpoint (Optional[str]): The path to a file where the rating system state will be saved
180
+ /// after processing all contests. If None, the state is not saved.
181
+ ///
182
+ /// Returns:
183
+ /// PyRateResult: An object containing the results of the rating process, including
184
+ /// the final ratings of players and the time elapsed during the rating calculation.
185
+ #[pyfunction]
186
+ #[pyo3(text_signature = "(system, contests, mu_noob, sig_noob, load_checkpoint=None, save_checkpoint=None)")]
187
+ fn rate(
188
+ system: String,
189
+ contests: Vec<PyContest>,
190
+ mu_noob: f64,
191
+ sig_noob: f64,
192
+ load_checkpoint: Option<String>,
193
+ save_checkpoint: Option<String>,
194
+ ) -> PyRateResult {
195
+ let contest_vec: Vec<Contest> = contests.into_iter().map(|contest| contest.inner).collect();
196
+ let boxed_dataset: BoxedDataset<Contest> = Box::new(ContestVec(contest_vec));
197
+ let dataset: ContestDataset = boxed_dataset.wrap();
198
+
199
+ let system = get_rating_system_by_name(&*system).unwrap();
200
+
201
+ let loaded_state = match load_checkpoint {
202
+ Some(filename) => read_json(filename).expect("Failed to read checkpoint"),
203
+ None => HashMap::new(),
204
+ };
205
+
206
+ let experiment = Experiment {mu_noob, sig_noob, system, dataset, loaded_state, save_checkpoint};
207
+ let results: ExperimentResults = experiment.eval(experiment.dataset.len());
208
+ let rate_results = from_experiment_results(results).unwrap();
209
+ return rate_results;
210
+ }
211
+
212
+ #[pymodule]
213
+ fn elo_mmr_python_bindings(_py: Python, m: &PyModule) -> PyResult<()> {
214
+ m.add_class::<PyContest>()?;
215
+ m.add_class::<PyPlayerEvent>()?;
216
+ m.add_class::<PyRateResult>()?;
217
+ m.add_wrapped(wrap_pyfunction!(rate))?;
218
+ Ok(())
219
+ }
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from elo_mmr_py import Contest, rate
4
+
5
+
6
+ def test_create_contest_with_standings():
7
+ standings = [('player_1', 0, 0), ('player_2', 1, 1), ('player_3', 2, 2)]
8
+ contest = Contest(standings=standings)
9
+ assert isinstance(contest, Contest)
10
+ assert contest.standings == standings
11
+
12
+
13
+ def test_create_contest_with_name():
14
+ name = 'contest_1'
15
+ contest = Contest(name=name, standings=[])
16
+ assert isinstance(contest, Contest)
17
+ assert contest.name == name
18
+
19
+
20
+ def test_create_contest_with_time_seconds():
21
+ time_seconds = 100500
22
+ contest = Contest(time_seconds=time_seconds, standings=[])
23
+ assert isinstance(contest, Contest)
24
+ assert contest.time_seconds == time_seconds
25
+
26
+
27
+ def test_create_contest_with_url():
28
+ url = 'https://example.com/'
29
+ contest = Contest(url=url, standings=[])
30
+ assert isinstance(contest, Contest)
31
+ assert contest.url == url
32
+
33
+
34
+ def test_rate_contests():
35
+ contests = [
36
+ Contest(standings=[('player_1', 0, 0), ('player_2', 1, 1), ('player_3', 2, 2)]),
37
+ Contest(standings=[('player_1', 0, 1), ('player_2', 0, 1), ('player_3', 2, 2)]),
38
+ Contest(standings=[('player_1', 0, 0), ('player_2', 1, 2), ('player_3', 1, 2)]),
39
+ Contest(standings=[('player_4', 0, 0), ('player_1', 1, 1), ('player_2', 2, 2), ('player_3', 3, 3)]),
40
+ Contest(standings=[('player_4', 0, 0), ('player_1', 1, 1), ('player_2', 2, 2), ('player_3', 3, 3)]),
41
+ ]
42
+ players = rate(contests)
43
+
44
+ assert isinstance(players, dict)
45
+ assert len(players) == 4
46
+ assert sum(len(player.events) for player in players.values()) == 17
47
+ ratings = sorted(players.values(), key=lambda player: player.rating, reverse=True)
48
+ ranking = [player.name for player in ratings]
49
+ assert ranking == ['player_4', 'player_1', 'player_2', 'player_3']