From 02099ac1f6ac779d2bbdc94a86541c2c1892b693 Mon Sep 17 00:00:00 2001 From: Sik Yoon Date: Sun, 15 Oct 2023 15:16:32 +0900 Subject: [PATCH] Add kelly_criterion table --- src/initialization.rs | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/initialization.rs b/src/initialization.rs index 0aadc29..5831528 100644 --- a/src/initialization.rs +++ b/src/initialization.rs @@ -998,6 +998,63 @@ async fn initialize_database() { println!("Ok"); } + { + // kelly_criterion + print!("table 'kelly_criterion'..."); + io::stdout().flush(); + + let table_name = String::from("kelly_criterion"); + let exists_result = exists_table(&table_name).await; + let initial_table = vec![ + ("id", "integer", Some("PK, UN, AI")), + ("betting_rate", "double", None), + ("win_rate", "double", None), + ("lose_rate", "double", None), + ("profit_rate", "double", None), + ("loss_rate", "double", None), + ]; + let table_condition = None; + + let insert_initial_columns = vec![ + "betting_rate", + "win_rate", + "lose_rate", + "profit_rate", + "loss_rate", + ]; + let insert_initial_value = vec![ + String::from("50.0"), // initialize betting size: 50% + String::from("0.0"), + String::from("0.0"), + String::from("0.0"), + String::from("0.0"), + ]; + if exists_result == false { + let mut result = new_table(&table_name, &initial_table, &table_condition).await; + if result.is_err() { + loop { + result = new_table(&table_name, &initial_table, &table_condition).await; + if result.is_ok() { + break; + } + sleep(Duration::from_millis(10)).await; + } + } + insert_one_record(&table_name, &insert_initial_columns, &insert_initial_value) + .await + .expect("Failed to insert initial row!"); + } else { + delete_all_rows(&table_name) + .await + .expect("Failed to delete rows!"); + insert_one_record(&table_name, &insert_initial_columns, &insert_initial_value) + .await + .expect("Failed to insert initial row!"); + } + + println!("Ok"); + } + { // filtered_indices print!("table 'filtered_indices'..."); @@ -1074,6 +1131,7 @@ async fn initialize_database() { ("minimum_profit_percent", "double", None), ("maximum_profit_percent", "double", None), ("registerer", "smallint", Some("UN")), + ("is_long", "tinyint", Some("UN")), ]; // let table_condition = Some("ENGINE = MEMORY"); let table_condition = None;