Allow configuration of country and state when creating dataset

This commit is contained in:
Kiana Sheibani 2023-10-13 19:13:17 -04:00
parent 3d97028b92
commit de9e668a72
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -148,11 +148,15 @@ fn dataset_new(name: Option<String>, auth_token: Option<String>) {
.or_else(|| get_auth_token(&config_dir)) .or_else(|| get_auth_token(&config_dir))
.unwrap_or_else(|| error("Access token not provided", 1)); .unwrap_or_else(|| error("Access token not provided", 1));
// Name
let name = name.unwrap_or_else(|| { let name = name.unwrap_or_else(|| {
print!("Name of new dataset: "); print!("Name of new dataset: ");
read_string() read_string()
}); });
// Game
print!("Search games: "); print!("Search games: ");
let games = run_query::<VideogameSearch, _>( let games = run_query::<VideogameSearch, _>(
VideogameSearchVars { VideogameSearchVars {
@ -184,6 +188,32 @@ fn dataset_new(name: Option<String>, auth_token: Option<String>) {
name: game_name, name: game_name,
} = games[index].clone(); } = games[index].clone();
// Location
print!("\nCountry to track ratings for (two-letter code, leave empty for none): ");
let country = {
let string = read_string();
if string.is_empty() {
None
} else {
Some(string)
}
};
let state = if country.as_ref().is_some_and(|s| s == "US" || s == "CA") {
print!("\nState/province to track ratings for (two-letter code, leave empty for none): ");
let string = read_string();
if string.is_empty() {
None
} else {
Some(string)
}
} else {
None
};
// Done configuring
let connection = let connection =
open_datasets(&config_dir).unwrap_or_else(|_| error("Could not open datasets file", 1)); open_datasets(&config_dir).unwrap_or_else(|_| error("Could not open datasets file", 1));
new_dataset( new_dataset(
@ -193,8 +223,8 @@ fn dataset_new(name: Option<String>, auth_token: Option<String>) {
last_sync: Timestamp(1), last_sync: Timestamp(1),
game_id, game_id,
game_name, game_name,
country: None, country,
state: None, state,
decay_rate: 0.5, decay_rate: 0.5,
period: (3600 * 24 * 30) as f64, period: (3600 * 24 * 30) as f64,
tau: 0.2, tau: 0.2,