Skip to content

Commit

Permalink
Integrated with soccer scaper data
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Dec 4, 2023
1 parent 30b0379 commit 9685a91
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 155 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exclude = ["/images", "/bin", "/.idea", "/.github", "/coverage", "/doc", "/examp
anyhow = "1.0.75"
chrono = "0.4.31"
clap = { version = "4.4.6", features = ["derive"] }
racing_scraper = "0.0.8"
racing_scraper = "0.0.10"
serde_json = "1.0.107"
stanza = "0.3.0"
tinyrand = "0.5.0"
Expand Down
32 changes: 17 additions & 15 deletions src/bin/datadump.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
use anyhow::anyhow;
use brumby::csv::{CsvWriter, Record};
use brumby::{data, model};
use brumby::data::{EventDetailExt, PredicateClosures};
use brumby::market::{Market, OverroundMethod};
use brumby::model::cf::Factor;
use brumby::model::fit;
use brumby::model::fit::FitOptions;
use brumby::probs::SliceExt;
use clap::Parser;
use racing_scraper::models::EventType;
use std::collections::HashSet;
use std::env;
use std::error::Error;
use std::path::PathBuf;
use std::time::Instant;

use anyhow::anyhow;
use clap::Parser;
use racing_scraper::models::EventType;
use strum::{EnumCount, IntoEnumIterator};
use tracing::{debug, info};

use brumby::{model, racing_data};
use brumby::csv::{CsvWriter, Record};
use brumby::market::{Market, OverroundMethod};
use brumby::model::cf::Factor;
use brumby::model::fit;
use brumby::model::fit::FitOptions;
use brumby::probs::SliceExt;
use brumby::racing_data::{PredicateClosures, RaceSummary};

const OVERROUND_METHOD: OverroundMethod = OverroundMethod::Multiplicative;

#[derive(Debug, clap::Parser, Clone)]
Expand Down Expand Up @@ -73,12 +75,12 @@ fn main() -> Result<(), Box<dyn Error>> {

let mut predicates = vec![];
if let Some(race_type) = args.race_type {
predicates.push(data::Predicate::Type { race_type });
predicates.push(racing_data::Predicate::Type { race_type });
}
if let Some(cutoff_worst) = args.departure {
predicates.push(data::Predicate::Departure { cutoff_worst })
predicates.push(racing_data::Predicate::Departure { cutoff_worst })
}
let race_files = data::read_from_dir(args.dir.unwrap(), PredicateClosures::from(predicates))?;
let race_files = racing_data::read_from_dir(args.dir.unwrap(), PredicateClosures::from(predicates))?;
let total_num_races = race_files.len();
let mut unique_races = HashSet::new();
let mut duplicate_races = 0;
Expand All @@ -94,7 +96,7 @@ fn main() -> Result<(), Box<dyn Error>> {
race_file.file.to_str().unwrap(),
index + 1,
);
let race = race_file.race.summarise();
let race = RaceSummary::from(race_file.race);
let markets: Vec<_> = (0..race.prices.rows())
.map(|rank| {
let prices = race.prices.row_slice(rank).to_vec();
Expand Down
8 changes: 4 additions & 4 deletions src/bin/departure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use stanza::style::{HAlign, Header, MinWidth, Styles};
use stanza::table::{Cell, Col, Row, Table};
use tracing::{debug, info};

use brumby::data;
use brumby::data::{EventDetailExt, PlacePriceDeparture, PredicateClosures};
use brumby::racing_data;
use brumby::racing_data::{EventDetailExt, PlacePriceDeparture, PredicateClosures};

const TOP_SUBSET: usize = 25;

Expand Down Expand Up @@ -58,9 +58,9 @@ fn main() -> Result<(), Box<dyn Error>> {
let start_time = Instant::now();
let mut predicates = vec![];
if let Some(race_type) = args.race_type {
predicates.push(data::Predicate::Type { race_type });
predicates.push(racing_data::Predicate::Type { race_type });
}
let races = data::read_from_dir(args.dir.unwrap(), PredicateClosures::from(predicates))?;
let races = racing_data::read_from_dir(args.dir.unwrap(), PredicateClosures::from(predicates))?;

let mut assessments = Vec::with_capacity(races.len());
let num_races = races.len();
Expand Down
12 changes: 6 additions & 6 deletions src/bin/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use stanza::style::{HAlign, Header, MinWidth, Styles};
use stanza::table::{Cell, Col, Row, Table};
use tracing::{debug, info};

use brumby::data;
use brumby::data::{EventDetailExt, PlacePriceDeparture, PredicateClosures, RaceSummary};
use brumby::racing_data;
use brumby::racing_data::{EventDetailExt, PlacePriceDeparture, PredicateClosures, RaceSummary};
use brumby::file::ReadJsonFile;
use brumby::market::{Market, OverroundMethod};
use brumby::model::cf::Coefficients;
Expand Down Expand Up @@ -68,12 +68,12 @@ fn main() -> Result<(), Box<dyn Error>> {
let start_time = Instant::now();
let mut predicates = vec![];
if let Some(race_type) = args.race_type {
predicates.push(data::Predicate::Type { race_type });
predicates.push(racing_data::Predicate::Type { race_type });
}
if let Some(cutoff_worst) = args.departure {
predicates.push(data::Predicate::Departure { cutoff_worst })
predicates.push(racing_data::Predicate::Departure { cutoff_worst })
}
let races = data::read_from_dir(args.dir.unwrap(), PredicateClosures::from(predicates))?;
let races = racing_data::read_from_dir(args.dir.unwrap(), PredicateClosures::from(predicates))?;

let mut configs = HashMap::new();
for race_type in [EventType::Thoroughbred, EventType::Greyhound] {
Expand Down Expand Up @@ -107,7 +107,7 @@ fn main() -> Result<(), Box<dyn Error>> {
index + 1
);
let departure = race_file.race.place_price_departure();
let race = race_file.race.summarise();
let race = RaceSummary::from(race_file.race);
let calibrator = Fitter::try_from(configs[&race.race_type].clone())?;
let sample_top_n = TopN {
markets: (0..race.prices.rows())
Expand Down
6 changes: 3 additions & 3 deletions src/bin/fractional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use stanza::style::{HAlign, MinWidth, Separator, Styles};
use stanza::table::{Col, Row, Table};
use tracing::{debug, info};

use brumby::data::{download_by_id, EventDetailExt, RaceSummary};
use brumby::racing_data::{download_by_id, RaceSummary};
use brumby::file::ReadJsonFile;
use brumby::market::{Market, Overround, OverroundMethod};
use brumby::model;
Expand Down Expand Up @@ -177,11 +177,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
async fn read_race_data(args: &Args) -> anyhow::Result<RaceSummary> {
if let Some(path) = args.file.as_ref() {
let event_detail = EventDetail::read_json_file(path)?;
return Ok(event_detail.summarise());
return Ok(event_detail.into());
}
if let Some(&id) = args.download.as_ref() {
let event_detail = download_by_id(id).await?;
return Ok(event_detail.summarise());
return Ok(event_detail.into());
}
unreachable!()
}
4 changes: 2 additions & 2 deletions src/bin/prices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use stanza::style::{HAlign, MinWidth, Separator, Styles};
use stanza::table::{Col, Row, Table};
use tracing::{debug, info};

use brumby::data::{download_by_id, EventDetailExt, RaceSummary};
use brumby::racing_data::{download_by_id, RaceSummary};
use brumby::display::DisplaySlice;
use brumby::file::ReadJsonFile;
use brumby::market::{Market, Overround, OverroundMethod};
Expand Down Expand Up @@ -243,5 +243,5 @@ async fn read_race_data(args: &Args) -> anyhow::Result<RaceSummary> {
unreachable!()
}
};
Ok(event_detail.summarise())
Ok(event_detail.into())
}
Loading

0 comments on commit 9685a91

Please sign in to comment.