Initial commit.
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
||||||
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "elo"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Anders Olsson <anders.e.olsson@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
27
src/lib.rs
Normal file
27
src/lib.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
pub fn rating(a: f32, b: f32, score: f32, n: f32, k: f32) -> f32 {
|
||||||
|
a + delta(score, expected(a, b, n), k)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delta(score: f32, rating: f32, k: f32) -> f32 {
|
||||||
|
k * (score - rating)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn expected(a: f32, b: f32, n: f32) -> f32 {
|
||||||
|
1.0 / (1.0 + 10.0_f32.powf((b - a) / n))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rating() {
|
||||||
|
let r = rating(1600.0, 1600.0, 1.0, 400.0, 32.0);
|
||||||
|
|
||||||
|
assert_eq!(r, 1616.0);
|
||||||
|
|
||||||
|
let r = rating(1600.0, 1600.0, 0.5, 400.0, 32.0);
|
||||||
|
|
||||||
|
assert_eq!(r, 1600.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user