Modify how set limit affects ratings
This commit is contained in:
parent
d7b5394be3
commit
00d0195595
|
@ -402,6 +402,32 @@ pub fn get_player_set_counts(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_matchup_set_counts(
|
||||||
|
connection: &Connection,
|
||||||
|
dataset: &str,
|
||||||
|
player1: PlayerId,
|
||||||
|
player2: PlayerId,
|
||||||
|
) -> sqlite::Result<(u64, u64)> {
|
||||||
|
if player1 == player2 {
|
||||||
|
return Ok((0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
let query = format!(
|
||||||
|
r#"SELECT iif(:a > :b, sets_count_B, sets_count_A) sets_count_A, iif(:a > :b, sets_count_A, sets_count_B) sets_count_B
|
||||||
|
FROM "{}_network" WHERE player_A = min(:a, :b) AND player_B = max(:a, :b)"#,
|
||||||
|
dataset
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut statement = connection.prepare(&query)?;
|
||||||
|
statement.bind((":a", player1.0 as i64))?;
|
||||||
|
statement.bind((":b", player2.0 as i64))?;
|
||||||
|
statement.next()?;
|
||||||
|
Ok((
|
||||||
|
statement.read::<i64, _>("sets_count_A")? as u64,
|
||||||
|
statement.read::<i64, _>("sets_count_B")? as u64,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_player_data(
|
pub fn set_player_data(
|
||||||
connection: &Connection,
|
connection: &Connection,
|
||||||
dataset: &str,
|
dataset: &str,
|
||||||
|
@ -484,13 +510,10 @@ pub fn adjust_advantages(
|
||||||
adjust1: f64,
|
adjust1: f64,
|
||||||
adjust2: f64,
|
adjust2: f64,
|
||||||
decay_rate: f64,
|
decay_rate: f64,
|
||||||
adj_decay_rate: f64,
|
|
||||||
set_limit: u64,
|
|
||||||
) -> sqlite::Result<()> {
|
) -> sqlite::Result<()> {
|
||||||
let query1 = format!(
|
let query1 = format!(
|
||||||
r#"UPDATE "{}_network"
|
r#"UPDATE "{}_network"
|
||||||
SET advantage = advantage + iif(:pl = player_A, -:v, :v)
|
SET advantage = advantage + iif(:pl = player_A, -:v, :v) * :d
|
||||||
* iif(sets_count >= :sl, :d, :da)
|
|
||||||
WHERE (player_A = :pl AND player_B != :plo)
|
WHERE (player_A = :pl AND player_B != :plo)
|
||||||
OR (player_B = :pl AND player_A != :plo)"#,
|
OR (player_B = :pl AND player_A != :plo)"#,
|
||||||
dataset
|
dataset
|
||||||
|
@ -508,18 +531,14 @@ WHERE player_A = min(:a, :b) AND player_B = max(:a, :b)"#,
|
||||||
statement.bind((":pl", player1.0 as i64))?;
|
statement.bind((":pl", player1.0 as i64))?;
|
||||||
statement.bind((":plo", player2.0 as i64))?;
|
statement.bind((":plo", player2.0 as i64))?;
|
||||||
statement.bind((":v", adjust1))?;
|
statement.bind((":v", adjust1))?;
|
||||||
statement.bind((":sl", set_limit as i64))?;
|
|
||||||
statement.bind((":d", decay_rate))?;
|
statement.bind((":d", decay_rate))?;
|
||||||
statement.bind((":da", adj_decay_rate))?;
|
|
||||||
statement.into_iter().try_for_each(|x| x.map(|_| ()))?;
|
statement.into_iter().try_for_each(|x| x.map(|_| ()))?;
|
||||||
|
|
||||||
statement = connection.prepare(&query1)?;
|
statement = connection.prepare(&query1)?;
|
||||||
statement.bind((":pl", player2.0 as i64))?;
|
statement.bind((":pl", player2.0 as i64))?;
|
||||||
statement.bind((":plo", player1.0 as i64))?;
|
statement.bind((":plo", player1.0 as i64))?;
|
||||||
statement.bind((":v", adjust2))?;
|
statement.bind((":v", adjust2))?;
|
||||||
statement.bind((":sl", set_limit as i64))?;
|
|
||||||
statement.bind((":d", decay_rate))?;
|
statement.bind((":d", decay_rate))?;
|
||||||
statement.bind((":da", adj_decay_rate))?;
|
|
||||||
statement.into_iter().try_for_each(|x| x.map(|_| ()))?;
|
statement.into_iter().try_for_each(|x| x.map(|_| ()))?;
|
||||||
|
|
||||||
statement = connection.prepare(&query2)?;
|
statement = connection.prepare(&query2)?;
|
||||||
|
|
13
src/sync.rs
13
src/sync.rs
|
@ -265,6 +265,13 @@ fn update_from_set(
|
||||||
&results.id,
|
&results.id,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
let (sets1, sets2) = get_matchup_set_counts(connection, dataset, player1, player2)?;
|
||||||
|
let decay_rate = if sets1 + sets2 >= metadata.set_limit {
|
||||||
|
metadata.decay_rate
|
||||||
|
} else {
|
||||||
|
metadata.adj_decay_rate
|
||||||
|
};
|
||||||
|
|
||||||
adjust_advantages(
|
adjust_advantages(
|
||||||
connection,
|
connection,
|
||||||
dataset,
|
dataset,
|
||||||
|
@ -274,9 +281,7 @@ fn update_from_set(
|
||||||
results.winner,
|
results.winner,
|
||||||
adjust1,
|
adjust1,
|
||||||
adjust2,
|
adjust2,
|
||||||
metadata.decay_rate,
|
decay_rate,
|
||||||
metadata.adj_decay_rate,
|
|
||||||
metadata.set_limit,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +328,7 @@ pub fn sync_dataset(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::datasets::tests::*;
|
use crate::database::tests::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn glicko_single() -> sqlite::Result<()> {
|
fn glicko_single() -> sqlite::Result<()> {
|
||||||
|
|
Loading…
Reference in a new issue