Work around a terrible, terrible start.gg bug
I honestly don't even know what to say about this one.
This commit is contained in:
parent
361efe60a3
commit
847d879287
|
@ -1,10 +1,29 @@
|
|||
use schema::schema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Display, Error, Formatter};
|
||||
|
||||
// Types
|
||||
// HACK: Unfortunately, start.gg seems to use integers and strings
|
||||
// interchangeably for its ID types (... for some reason), whereas cynic always
|
||||
// assumes that IDs are strings. To get around that, we define new scalar types
|
||||
// that deserialize properly.
|
||||
|
||||
// HACK: Unfortunately, start.gg seems to use integers for its ID type, whereas
|
||||
// cynic always assumes that IDs are strings. To get around that, we define new
|
||||
// scalar types that deserialize to u64.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum StringOrInt {
|
||||
String(String),
|
||||
Int(u64),
|
||||
}
|
||||
|
||||
impl Display for StringOrInt {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
||||
match self {
|
||||
StringOrInt::String(x) => x.fmt(fmt),
|
||||
StringOrInt::Int(x) => x.fmt(fmt),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scalar Types
|
||||
|
||||
#[derive(cynic::Scalar, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cynic(graphql_type = "ID")]
|
||||
|
@ -26,10 +45,10 @@ pub struct EntrantId(pub u64);
|
|||
#[repr(transparent)]
|
||||
pub struct PlayerId(pub u64);
|
||||
|
||||
#[derive(cynic::Scalar, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cynic(graphql_type = "ID")]
|
||||
#[repr(transparent)]
|
||||
pub struct SetId(pub u64);
|
||||
pub struct SetId(pub StringOrInt);
|
||||
|
||||
#[derive(cynic::Scalar, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[repr(transparent)]
|
||||
|
|
25
src/sync.rs
25
src/sync.rs
|
@ -205,7 +205,15 @@ fn update_from_set(
|
|||
|
||||
let advantage = match get_advantage(connection, dataset, player1, player2) {
|
||||
Err(e) => Err(e)?,
|
||||
Ok(None) => initialize_edge(connection, dataset, metadata.decay_rate, player1, player2)?,
|
||||
Ok(None) => initialize_edge(
|
||||
connection,
|
||||
dataset,
|
||||
player1,
|
||||
player2,
|
||||
metadata.set_limit,
|
||||
metadata.decay_rate,
|
||||
metadata.adj_decay_rate,
|
||||
)?,
|
||||
Ok(Some(adv)) => adv,
|
||||
};
|
||||
let (adjust1, dev_new1, vol_new1) = glicko_adjust(
|
||||
|
@ -239,7 +247,7 @@ fn update_from_set(
|
|||
dev_new1,
|
||||
vol_new1,
|
||||
results.winner == 0,
|
||||
results.id,
|
||||
results.id.clone(),
|
||||
)?;
|
||||
set_player_data(
|
||||
connection,
|
||||
|
@ -249,7 +257,7 @@ fn update_from_set(
|
|||
dev_new2,
|
||||
vol_new2,
|
||||
results.winner == 1,
|
||||
results.id,
|
||||
results.id.clone(),
|
||||
)?;
|
||||
|
||||
adjust_advantages(
|
||||
|
@ -267,11 +275,6 @@ fn update_from_set(
|
|||
)
|
||||
}
|
||||
|
||||
// HACK: Blacklist of events not to access
|
||||
// due to the worst bug I have ever encountered in my entire life
|
||||
// Why is start.gg like this
|
||||
const EVENT_BLACKLIST: &[EventId] = &[EventId(273741)];
|
||||
|
||||
pub fn sync_dataset(
|
||||
connection: &Connection,
|
||||
dataset: &str,
|
||||
|
@ -285,10 +288,6 @@ pub fn sync_dataset(
|
|||
|
||||
let num_events = events.len();
|
||||
for (i, event) in events.into_iter().enumerate() {
|
||||
if EVENT_BLACKLIST.contains(&event) {
|
||||
continue;
|
||||
}
|
||||
|
||||
println!(
|
||||
"Accessing sets from event ID {}... ({}/{})",
|
||||
event.0,
|
||||
|
@ -329,7 +328,7 @@ mod tests {
|
|||
"test",
|
||||
&metadata(),
|
||||
SetData {
|
||||
id: SetId(0),
|
||||
id: SetId(StringOrInt::Int(0)),
|
||||
time: Timestamp(0),
|
||||
teams: players,
|
||||
winner: 0,
|
||||
|
|
Loading…
Reference in a new issue