Skip to content

Commit

Permalink
add CONFIG_PATH (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingDepot authored Feb 12, 2024
1 parent d6e24cc commit 6dc71a7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
13 changes: 1 addition & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "boot_bot"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -12,7 +12,6 @@ linfa = "0.7.0"
linfa-trees = { version = "0.7.0", features = ["serde"] }
ndarray = "0.15.6"
reqwest = { version="0.11.24", features = ["blocking"] }
openssl = { version = "0.10", features = ["vendored"] }
serde_json = "1.0.113"
serde = "1.0.196"
bincode = "1.3.3"
bincode = "1.3.3"
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
requires environment variables:
# requires environment variables:

RIOT_TOKEN The token for the Riot API

DISCORD_TOKEN The token for the Discord API

VIP_USER Snowflake of the user that may execute configuration commands

VIP_GUILD Snowflake of the guild that has configuration commands

GAME_VERSION The LoL version used for the embed downloads

needs the following files:
CONFIG_PATH The base path for the files listed below


# needs the following files:

snowflake_puuid.txt Maps Discord Snowflakes to Riot PUUIDs, each on a new line, separated by pipe symbols

snowflake_puuid.txt Maps Discord Snowflakes to Riot PUUIDs, each on a new line, separated by pipe symbols
model.bin The DecisionTree. Can be recreated by the bot
12 changes: 8 additions & 4 deletions src/prediction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ fn train_decision_tree(data: &Array2<f32>, sq: SplitQuality) -> DecisionTree<f32
}

fn save_model(model: &DecisionTree<f32, String>, file_name: &str) {
let model_file = File::create(file_name).unwrap();
let base_path = env::var("CONFIG_PATH").unwrap_or(String::new());
let model_file = File::create(format!("{}{}", base_path, file_name)).unwrap();
bincode::serialize_into(&model_file, &model).unwrap();
}

fn load_model(file_name: &str) -> Option<DecisionTree<f32, String>> {
if let Ok(mut model_file) = File::open(file_name) {
let base_path = env::var("CONFIG_PATH").unwrap_or(String::new());
if let Ok(mut model_file) = File::open(format!("{}{}", base_path, file_name)) {
let mut buffer = Vec::new();
model_file.read_to_end(&mut buffer).unwrap();
let deserialized_model: DecisionTree<f32, String> = bincode::deserialize(&buffer).unwrap();
Expand All @@ -86,7 +88,8 @@ fn load_model(file_name: &str) -> Option<DecisionTree<f32, String>> {
pub fn recreate_model(game_count: usize) {
let token: &str = &env::var("RIOT_TOKEN")
.expect("Could not fetch the Riot token");
let snowflake_map = create_snowflake_puuid_map(crate::constants::MAPPING_FILE);
let base_path = env::var("CONFIG_PATH").unwrap_or(String::new());
let snowflake_map = create_snowflake_puuid_map(&format!("{}{}", base_path, crate::constants::MAPPING_FILE));
let test_puuid = snowflake_map.values().filter(|id| id.starts_with("f7Xz")).nth(0).unwrap().clone();

// Train a new model
Expand All @@ -107,7 +110,8 @@ pub fn recreate_model(game_count: usize) {
pub fn predict(snowflake: &str) -> Option<String> {
let token: &str = &env::var("RIOT_TOKEN")
.expect("Could not fetch the Riot token");
let snowflake_map = create_snowflake_puuid_map(crate::constants::MAPPING_FILE);
let base_path = env::var("CONFIG_PATH").unwrap_or(String::new());
let snowflake_map = create_snowflake_puuid_map(&format!("{}{}", base_path, crate::constants::MAPPING_FILE));

if let Some(puuid) = snowflake_map.get(snowflake) {
if let Some(model) = load_model(MODEL_FILE_NAME) {
Expand Down

0 comments on commit 6dc71a7

Please sign in to comment.