diff --git a/examples/atp.rs b/examples/atp.rs index 9389a95..bfc77d8 100644 --- a/examples/atp.rs +++ b/examples/atp.rs @@ -1,29 +1,5 @@ -/* -use std::collections::HashMap; - use time::Date; - -use trueskill_tt::{History, PlayerIndex, BETA, MU, P_DRAW}; - -struct Players(HashMap); - -impl Players { - fn new() -> Self { - Self(HashMap::new()) - } - - fn get(&mut self, name: &str) -> PlayerIndex { - if let Some(idx) = self.0.get(name) { - *idx - } else { - let idx = PlayerIndex::new(self.0.len()); - - self.0.insert(name.to_string(), idx); - - idx - } - } -} +use trueskill_tt::{History, IndexMap}; fn main() { let mut csv = csv::Reader::open("examples/atp.csv").unwrap(); @@ -34,26 +10,26 @@ fn main() { let time_format = time::format_description::parse("[year]-[month]-[day]").unwrap(); - let mut players = Players::new(); + let mut index_map = IndexMap::new(); for row in csv.records() { if &row["double"] == "t" { - let w1_id = players.get(&row["w1_id"]); - let w2_id = players.get(&row["w2_id"]); + let w1_id = index_map.get_or_create(&row["w1_id"]); + let w2_id = index_map.get_or_create(&row["w2_id"]); - let l1_id = players.get(&row["l1_id"]); - let l2_id = players.get(&row["l2_id"]); + let l1_id = index_map.get_or_create(&row["l1_id"]); + let l2_id = index_map.get_or_create(&row["l2_id"]); composition.push(vec![vec![w1_id, w2_id], vec![l1_id, l2_id]]); } else { - let w1_id = players.get(&row["w1_id"]); + let w1_id = index_map.get_or_create(&row["w1_id"]); - let l1_id = players.get(&row["l1_id"]); + let l1_id = index_map.get_or_create(&row["l1_id"]); composition.push(vec![vec![w1_id], vec![l1_id]]); } - results.push(vec![1, 0]); + results.push(vec![1.0, 0.0]); let time = Date::parse(&row["time_start"], &time_format) .unwrap() @@ -61,68 +37,13 @@ fn main() { .assume_utc() .unix_timestamp(); - times.push(time as f64 / (60 * 60 * 24) as f64); + times.push(time as u64 / (60 * 60 * 24)); } - /* - let mut history = History::builder() - .sigma(1.6) - .gamma(0.036) - .priors(priors) - .build::