Skip to content

Commit 6dc71a7

Browse files
authored
add CONFIG_PATH (#11)
1 parent d6e24cc commit 6dc71a7

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

Cargo.lock

+1-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "boot_bot"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -12,7 +12,6 @@ linfa = "0.7.0"
1212
linfa-trees = { version = "0.7.0", features = ["serde"] }
1313
ndarray = "0.15.6"
1414
reqwest = { version="0.11.24", features = ["blocking"] }
15-
openssl = { version = "0.10", features = ["vendored"] }
1615
serde_json = "1.0.113"
1716
serde = "1.0.196"
18-
bincode = "1.3.3"
17+
bincode = "1.3.3"

README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
requires environment variables:
1+
# requires environment variables:
22

33
RIOT_TOKEN The token for the Riot API
4+
45
DISCORD_TOKEN The token for the Discord API
6+
57
VIP_USER Snowflake of the user that may execute configuration commands
8+
69
VIP_GUILD Snowflake of the guild that has configuration commands
10+
711
GAME_VERSION The LoL version used for the embed downloads
812

9-
needs the following files:
13+
CONFIG_PATH The base path for the files listed below
14+
15+
16+
# needs the following files:
17+
18+
snowflake_puuid.txt Maps Discord Snowflakes to Riot PUUIDs, each on a new line, separated by pipe symbols
1019

11-
snowflake_puuid.txt Maps Discord Snowflakes to Riot PUUIDs, each on a new line, separated by pipe symbols
20+
model.bin The DecisionTree. Can be recreated by the bot

src/prediction.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ fn train_decision_tree(data: &Array2<f32>, sq: SplitQuality) -> DecisionTree<f32
5858
}
5959

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

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

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

112116
if let Some(puuid) = snowflake_map.get(snowflake) {
113117
if let Some(model) = load_model(MODEL_FILE_NAME) {

0 commit comments

Comments
 (0)