Fall back to event time if set time isn't recorded
This commit is contained in:
parent
1aa1b87211
commit
1aa85bd989
|
@ -86,7 +86,7 @@ pub struct EventSetsResponse {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SetData {
|
pub struct SetData {
|
||||||
pub id: SetId,
|
pub id: SetId,
|
||||||
pub time: Timestamp,
|
pub time: Option<Timestamp>,
|
||||||
pub teams: Teams<PlayerData>,
|
pub teams: Teams<PlayerData>,
|
||||||
pub winner: usize,
|
pub winner: usize,
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ impl QueryUnwrap<EventSetsVars> for EventSets {
|
||||||
.try_collect()?;
|
.try_collect()?;
|
||||||
Some(SetData {
|
Some(SetData {
|
||||||
id: set.id?,
|
id: set.id?,
|
||||||
time: set.start_at.or(set.started_at)?,
|
time: set.start_at.or(set.started_at),
|
||||||
teams,
|
teams,
|
||||||
winner,
|
winner,
|
||||||
})
|
})
|
||||||
|
|
|
@ -53,7 +53,6 @@ struct PageInfo {
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
#[cynic(variables = "TournamentEventsVars")]
|
#[cynic(variables = "TournamentEventsVars")]
|
||||||
struct Tournament {
|
struct Tournament {
|
||||||
name: Option<String>,
|
|
||||||
#[arguments(limit: 99999, filter: { videogameId: [$game_id] })]
|
#[arguments(limit: 99999, filter: { videogameId: [$game_id] })]
|
||||||
#[cynic(flatten)]
|
#[cynic(flatten)]
|
||||||
events: Vec<Event>,
|
events: Vec<Event>,
|
||||||
|
@ -63,6 +62,7 @@ struct Tournament {
|
||||||
#[cynic(variables = "TournamentEventsVars")]
|
#[cynic(variables = "TournamentEventsVars")]
|
||||||
struct Event {
|
struct Event {
|
||||||
id: Option<EventId>,
|
id: Option<EventId>,
|
||||||
|
start_at: Option<Timestamp>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unwrap
|
// Unwrap
|
||||||
|
@ -75,8 +75,13 @@ pub struct TournamentEventResponse {
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TournamentData {
|
pub struct TournamentData {
|
||||||
pub name: String,
|
pub events: Vec<EventData>,
|
||||||
pub events: Vec<EventId>,
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct EventData {
|
||||||
|
pub id: EventId,
|
||||||
|
pub time: Timestamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> QueryUnwrap<TournamentEventsVars<'a>> for TournamentEvents {
|
impl<'a> QueryUnwrap<TournamentEventsVars<'a>> for TournamentEvents {
|
||||||
|
@ -92,11 +97,15 @@ impl<'a> QueryUnwrap<TournamentEventsVars<'a>> for TournamentEvents {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|tour| {
|
.filter_map(|tour| {
|
||||||
Some(TournamentData {
|
Some(TournamentData {
|
||||||
name: tour.name?,
|
|
||||||
events: tour
|
events: tour
|
||||||
.events
|
.events
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|event| event.id)
|
.filter_map(|event| {
|
||||||
|
Some(EventData {
|
||||||
|
id: event.id?,
|
||||||
|
time: event.start_at?,
|
||||||
|
})
|
||||||
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
27
src/sync.rs
27
src/sync.rs
|
@ -118,7 +118,7 @@ fn get_event_sets(event: EventId, auth: &str) -> Option<Vec<SetData>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tournament_events(metadata: &DatasetMetadata, auth: &str) -> Option<Vec<EventId>> {
|
fn get_tournament_events(metadata: &DatasetMetadata, auth: &str) -> Option<Vec<EventData>> {
|
||||||
println!("Accessing tournaments...");
|
println!("Accessing tournaments...");
|
||||||
|
|
||||||
let tour_response = run_query::<TournamentEvents, _>(
|
let tour_response = run_query::<TournamentEvents, _>(
|
||||||
|
@ -182,10 +182,13 @@ fn update_from_set(
|
||||||
connection: &Connection,
|
connection: &Connection,
|
||||||
dataset: &str,
|
dataset: &str,
|
||||||
metadata: &DatasetMetadata,
|
metadata: &DatasetMetadata,
|
||||||
|
event_time: Timestamp,
|
||||||
results: SetData,
|
results: SetData,
|
||||||
) -> sqlite::Result<()> {
|
) -> sqlite::Result<()> {
|
||||||
let players_data = results.teams;
|
let players_data = results.teams;
|
||||||
add_players(connection, dataset, &players_data, results.time)?;
|
// Fall back to event time if set time is not recorded
|
||||||
|
let time = results.time.unwrap_or(event_time);
|
||||||
|
add_players(connection, dataset, &players_data, time)?;
|
||||||
|
|
||||||
// Non-singles matches are currently not supported
|
// Non-singles matches are currently not supported
|
||||||
if players_data.len() != 2 || players_data[0].len() != 1 || players_data[1].len() != 1 {
|
if players_data.len() != 2 || players_data[0].len() != 1 || players_data[1].len() != 1 {
|
||||||
|
@ -198,10 +201,10 @@ fn update_from_set(
|
||||||
drop(it);
|
drop(it);
|
||||||
|
|
||||||
let (deviation1, volatility1, last_played1) = get_player_data(connection, dataset, player1)?;
|
let (deviation1, volatility1, last_played1) = get_player_data(connection, dataset, player1)?;
|
||||||
let time1 = results.time.0.checked_sub(last_played1.0).unwrap_or(0);
|
let time1 = time.0.checked_sub(last_played1.0).unwrap_or(0);
|
||||||
|
|
||||||
let (deviation2, volatility2, last_played2) = get_player_data(connection, dataset, player1)?;
|
let (deviation2, volatility2, last_played2) = get_player_data(connection, dataset, player1)?;
|
||||||
let time2 = results.time.0.checked_sub(last_played2.0).unwrap_or(0);
|
let time2 = 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)?,
|
||||||
|
@ -243,7 +246,7 @@ fn update_from_set(
|
||||||
connection,
|
connection,
|
||||||
dataset,
|
dataset,
|
||||||
player1,
|
player1,
|
||||||
results.time,
|
time,
|
||||||
dev_new1,
|
dev_new1,
|
||||||
vol_new1,
|
vol_new1,
|
||||||
results.winner == 0,
|
results.winner == 0,
|
||||||
|
@ -253,7 +256,7 @@ fn update_from_set(
|
||||||
connection,
|
connection,
|
||||||
dataset,
|
dataset,
|
||||||
player2,
|
player2,
|
||||||
results.time,
|
time,
|
||||||
dev_new2,
|
dev_new2,
|
||||||
vol_new2,
|
vol_new2,
|
||||||
results.winner == 1,
|
results.winner == 1,
|
||||||
|
@ -290,13 +293,13 @@ pub fn sync_dataset(
|
||||||
for (i, event) in events.into_iter().enumerate() {
|
for (i, event) in events.into_iter().enumerate() {
|
||||||
println!(
|
println!(
|
||||||
"Accessing sets from event ID {}... ({}/{})",
|
"Accessing sets from event ID {}... ({}/{})",
|
||||||
event.0,
|
event.id.0,
|
||||||
i + 1,
|
i + 1,
|
||||||
num_events
|
num_events
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut sets =
|
let mut sets =
|
||||||
get_event_sets(event, auth).unwrap_or_else(|| error("Could not access start.gg", 1));
|
get_event_sets(event.id, auth).unwrap_or_else(|| error("Could not access start.gg", 1));
|
||||||
|
|
||||||
if sets.is_empty() {
|
if sets.is_empty() {
|
||||||
println!(" No valid sets");
|
println!(" No valid sets");
|
||||||
|
@ -304,8 +307,9 @@ pub fn sync_dataset(
|
||||||
println!(" Updating ratings from event...");
|
println!(" Updating ratings from event...");
|
||||||
|
|
||||||
sets.sort_by_key(|set| set.time);
|
sets.sort_by_key(|set| set.time);
|
||||||
sets.into_iter()
|
sets.into_iter().try_for_each(|set| {
|
||||||
.try_for_each(|set| update_from_set(connection, dataset, &metadata, set))?;
|
update_from_set(connection, dataset, &metadata, event.time, set)
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connection.execute("COMMIT;")
|
connection.execute("COMMIT;")
|
||||||
|
@ -327,9 +331,10 @@ mod tests {
|
||||||
&connection,
|
&connection,
|
||||||
"test",
|
"test",
|
||||||
&metadata(),
|
&metadata(),
|
||||||
|
Timestamp(0),
|
||||||
SetData {
|
SetData {
|
||||||
id: SetId(StringOrInt::Int(0)),
|
id: SetId(StringOrInt::Int(0)),
|
||||||
time: Timestamp(0),
|
time: None,
|
||||||
teams: players,
|
teams: players,
|
||||||
winner: 0,
|
winner: 0,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue