Change time to use i64 instead of u64

This commit is contained in:
2022-06-28 23:18:55 +02:00
parent 6125a81696
commit 22c61d47b1
8 changed files with 117 additions and 22 deletions

View File

@@ -1,3 +1,4 @@
use plotters::prelude::*;
use time::Date;
use trueskill_tt::{History, IndexMap};
@@ -37,13 +38,104 @@ fn main() {
.assume_utc()
.unix_timestamp();
times.push(time as u64 / (60 * 60 * 24));
times.push(time / (60 * 60 * 24));
}
let mut hist = History::builder().sigma(1.6).gamma(0.036).build();
hist.add_events(composition, results, times, vec![]);
hist.convergence(10, 0.01, true);
let players = [
("djokovic", "d643"),
("federer", "f324"),
("sampras", "s402"),
("lendl", "l018"),
("connors", "c044"),
("nadal", "n409"),
("john_mcenroe", "m047"),
("bjorn_borg", "b058"),
("aggasi", "a092"),
("hewitt", "h432"),
("edberg", "e004"),
("vilas", "v028"),
("nastase", "n008"),
("courier", "c243"),
("kuerten", "k293"),
("murray", "mc10"),
("wilander", "w023"),
("roddick", "r485"),
];
let curves = hist.learning_curves();
let mut x_spec = (f64::MAX, f64::MIN);
let mut y_spec = (f64::MAX, f64::MIN);
for id in players.iter().map(|&(_, id)| index_map.get_or_create(id)) {
for (ts, gs) in &curves[&id] {
let ts = *ts as f64;
if ts < x_spec.0 {
x_spec.0 = ts;
}
if ts > x_spec.1 {
x_spec.1 = ts;
}
let mu = gs.mu as f64;
if mu < y_spec.0 {
y_spec.0 = mu;
}
if mu > y_spec.1 {
y_spec.1 = mu;
}
}
}
let root = SVGBackend::new("plot.svg", (1024, 1024)).into_drawing_area();
root.fill(&WHITE).unwrap();
let mut chart = ChartBuilder::on(&root)
.caption("Hello world", ("sans-serif", 50).into_font())
.margin(5)
.x_label_area_size(30)
.y_label_area_size(30)
.build_cartesian_2d(x_spec.0..x_spec.1, y_spec.0..y_spec.1)
.unwrap();
chart.configure_mesh().draw().unwrap();
for (idx, (player, id)) in players
.iter()
.map(|&(player, id)| (player, index_map.get_or_create(id)))
.enumerate()
{
let mut data = Vec::new();
for (ts, gs) in &curves[&id] {
data.push((*ts as f64, gs.mu));
}
let color = Palette99::pick(idx);
chart
.draw_series(LineSeries::new(data, &color))
.unwrap()
.label(format!("{}", player))
.legend(move |(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &color));
}
chart
.configure_series_labels()
.background_style(&WHITE.mix(0.8))
.border_style(&BLACK)
.draw()
.unwrap();
}
mod csv {