Fix underflow bug when computing time decay
This commit is contained in:
parent
e51f4e2962
commit
6f969cd231
|
@ -24,7 +24,7 @@ pub struct EventSets {
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
#[cynic(variables = "EventSetsVars")]
|
#[cynic(variables = "EventSetsVars")]
|
||||||
struct Event {
|
struct Event {
|
||||||
#[arguments(page: $page, perPage: 50)]
|
#[arguments(page: $page, perPage: 40, sortType: RECENT)]
|
||||||
sets: Option<SetConnection>,
|
sets: Option<SetConnection>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ struct PageInfo {
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
struct Set {
|
struct Set {
|
||||||
start_at: Option<Timestamp>,
|
start_at: Option<Timestamp>,
|
||||||
|
started_at: Option<Timestamp>,
|
||||||
#[arguments(includeByes: true)]
|
#[arguments(includeByes: true)]
|
||||||
#[cynic(flatten)]
|
#[cynic(flatten)]
|
||||||
slots: Vec<SetSlot>,
|
slots: Vec<SetSlot>,
|
||||||
|
@ -125,7 +126,7 @@ impl QueryUnwrap<EventSetsVars> for EventSets {
|
||||||
})
|
})
|
||||||
.try_collect()?;
|
.try_collect()?;
|
||||||
Some(SetData {
|
Some(SetData {
|
||||||
time: set.start_at?,
|
time: set.start_at.or(set.started_at)?,
|
||||||
teams,
|
teams,
|
||||||
winner,
|
winner,
|
||||||
})
|
})
|
||||||
|
|
19
src/sync.rs
19
src/sync.rs
|
@ -199,6 +199,10 @@ fn update_from_set(
|
||||||
|
|
||||||
let (deviation1, volatility1, last_played1) = get_player_data(connection, dataset, player1)?;
|
let (deviation1, volatility1, last_played1) = get_player_data(connection, dataset, player1)?;
|
||||||
let (deviation2, volatility2, last_played2) = 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) {
|
let advantage = match get_advantage(connection, dataset, player1, player2) {
|
||||||
Err(e) => Err(e)?,
|
Err(e) => Err(e)?,
|
||||||
Ok(None) => initialize_edge(connection, dataset, metadata.decay_rate, player1, player2)?,
|
Ok(None) => initialize_edge(connection, dataset, metadata.decay_rate, player1, player2)?,
|
||||||
|
@ -210,7 +214,7 @@ fn update_from_set(
|
||||||
volatility1,
|
volatility1,
|
||||||
deviation2,
|
deviation2,
|
||||||
results.winner == 0,
|
results.winner == 0,
|
||||||
results.time.0 - last_played1.0,
|
time1,
|
||||||
metadata,
|
metadata,
|
||||||
);
|
);
|
||||||
let (adjust2, dev_new2, vol_new2) = glicko_adjust(
|
let (adjust2, dev_new2, vol_new2) = glicko_adjust(
|
||||||
|
@ -219,7 +223,7 @@ fn update_from_set(
|
||||||
volatility2,
|
volatility2,
|
||||||
deviation1,
|
deviation1,
|
||||||
results.winner == 1,
|
results.winner == 1,
|
||||||
results.time.0 - last_played2.0,
|
time2,
|
||||||
metadata,
|
metadata,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -270,13 +274,16 @@ pub fn sync_dataset(
|
||||||
event.0, i, num_events
|
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));
|
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()
|
sets.sort_by_key(|set| set.time);
|
||||||
.try_for_each(|set| update_from_set(connection, dataset, &metadata, set))?;
|
sets.into_iter()
|
||||||
}
|
}
|
||||||
connection.execute("COMMIT;")
|
connection.execute("COMMIT;")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue