Fix underflow bug when computing time decay

This commit is contained in:
Kiana Sheibani 2023-11-02 14:03:01 -04:00
parent e51f4e2962
commit 6f969cd231
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 16 additions and 8 deletions

View file

@ -24,7 +24,7 @@ pub struct EventSets {
#[derive(cynic::QueryFragment, Debug)]
#[cynic(variables = "EventSetsVars")]
struct Event {
#[arguments(page: $page, perPage: 50)]
#[arguments(page: $page, perPage: 40, sortType: RECENT)]
sets: Option<SetConnection>,
}
@ -43,6 +43,7 @@ struct PageInfo {
#[derive(cynic::QueryFragment, Debug)]
struct Set {
start_at: Option<Timestamp>,
started_at: Option<Timestamp>,
#[arguments(includeByes: true)]
#[cynic(flatten)]
slots: Vec<SetSlot>,
@ -125,7 +126,7 @@ impl QueryUnwrap<EventSetsVars> for EventSets {
})
.try_collect()?;
Some(SetData {
time: set.start_at?,
time: set.start_at.or(set.started_at)?,
teams,
winner,
})

View file

@ -199,6 +199,10 @@ fn update_from_set(
let (deviation1, volatility1, last_played1) = get_player_data(connection, dataset, player1)?;
let (deviation2, volatility2, last_played2) = get_player_data(connection, dataset, player1)?;
let time1 = results.time.0.checked_sub(last_played1.0).unwrap_or(0);
let time2 = results.time.0.checked_sub(last_played2.0).unwrap_or(0);
let advantage = match get_advantage(connection, dataset, player1, player2) {
Err(e) => Err(e)?,
Ok(None) => initialize_edge(connection, dataset, metadata.decay_rate, player1, player2)?,
@ -210,7 +214,7 @@ fn update_from_set(
volatility1,
deviation2,
results.winner == 0,
results.time.0 - last_played1.0,
time1,
metadata,
);
let (adjust2, dev_new2, vol_new2) = glicko_adjust(
@ -219,7 +223,7 @@ fn update_from_set(
volatility2,
deviation1,
results.winner == 1,
results.time.0 - last_played2.0,
time2,
metadata,
);
@ -270,13 +274,16 @@ pub fn sync_dataset(
event.0, i, num_events
);
let sets =
let mut sets =
get_event_sets(event, auth).unwrap_or_else(|| error("Could not access start.gg", 1));
println!(" Updating ratings from event...");
if sets.is_empty() {
println!(" No valid sets");
} else {
println!(" Updating ratings from event...");
sets.into_iter()
.try_for_each(|set| update_from_set(connection, dataset, &metadata, set))?;
sets.sort_by_key(|set| set.time);
sets.into_iter()
}
connection.execute("COMMIT;")
}