From a0da010dabcf70eae8841e13af258351cd580771 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 26 Jan 2023 01:09:30 -0500 Subject: [PATCH] Add model ratings to TTS list and get endpoints --- .../queries/tts/tts_models/get_tts_model.rs | 19 +++++++++++++++ .../queries/tts/tts_models/list_tts_models.rs | 23 +++++++++++++++++++ .../endpoints/tts/get_tts_model.rs | 15 ++++++++++++ .../endpoints/tts/list_tts_models.rs | 15 ++++++++++++ 4 files changed, 72 insertions(+) diff --git a/crates/lib/database_queries/src/queries/tts/tts_models/get_tts_model.rs b/crates/lib/database_queries/src/queries/tts/tts_models/get_tts_model.rs index 5d2558a5cf..a5cd2bdcc3 100644 --- a/crates/lib/database_queries/src/queries/tts/tts_models/get_tts_model.rs +++ b/crates/lib/database_queries/src/queries/tts/tts_models/get_tts_model.rs @@ -44,6 +44,10 @@ pub struct TtsModelRecord { pub maybe_suggested_unique_bot_command: Option, + pub user_ratings_positive_count: u32, + pub user_ratings_negative_count: u32, + pub user_ratings_total_count: u32, // NB: Does not include "neutral" ratings. + pub creator_set_visibility: Visibility, pub is_locked_from_use: bool, @@ -152,6 +156,9 @@ pub async fn get_tts_model_by_token_using_connection( is_front_page_featured: i8_to_bool(model.is_front_page_featured), is_twitch_featured: i8_to_bool(model.is_twitch_featured), maybe_suggested_unique_bot_command: model.maybe_suggested_unique_bot_command, + user_ratings_positive_count: model.user_ratings_positive_count, + user_ratings_negative_count: model.user_ratings_negative_count, + user_ratings_total_count: model.user_ratings_total_count, creator_set_visibility: Visibility::from_str(&model.creator_set_visibility) .unwrap_or(Visibility::Public), is_locked_from_use: i8_to_bool(model.is_locked_from_use), @@ -202,6 +209,10 @@ SELECT tts.maybe_suggested_unique_bot_command, + tts.user_ratings_positive_count, + tts.user_ratings_negative_count, + tts.user_ratings_total_count, + tts.creator_set_visibility, tts.is_locked_from_use, @@ -271,6 +282,10 @@ SELECT tts.maybe_suggested_unique_bot_command, + tts.user_ratings_positive_count, + tts.user_ratings_negative_count, + tts.user_ratings_total_count, + tts.creator_set_visibility, tts.is_locked_from_use, @@ -337,6 +352,10 @@ struct InternalTtsModelRecordRaw { pub maybe_suggested_unique_bot_command: Option, + pub user_ratings_positive_count: u32, + pub user_ratings_negative_count: u32, + pub user_ratings_total_count: u32, // NB: Does not include "neutral" ratings. + pub creator_set_visibility: String, pub is_locked_from_use: i8, diff --git a/crates/lib/database_queries/src/queries/tts/tts_models/list_tts_models.rs b/crates/lib/database_queries/src/queries/tts/tts_models/list_tts_models.rs index 4f390741f6..b67377d247 100644 --- a/crates/lib/database_queries/src/queries/tts/tts_models/list_tts_models.rs +++ b/crates/lib/database_queries/src/queries/tts/tts_models/list_tts_models.rs @@ -31,6 +31,10 @@ pub struct TtsModelRecordForList { pub maybe_suggested_unique_bot_command: Option, + pub user_ratings_positive_count: u32, + pub user_ratings_negative_count: u32, + pub user_ratings_total_count: u32, // NB: Does not include "neutral" ratings. + pub created_at: DateTime, pub updated_at: DateTime, } @@ -94,6 +98,9 @@ pub async fn list_tts_models_with_connection( is_front_page_featured: i8_to_bool(model.is_front_page_featured), is_twitch_featured: i8_to_bool(model.is_twitch_featured), maybe_suggested_unique_bot_command: model.maybe_suggested_unique_bot_command, + user_ratings_positive_count: model.user_ratings_positive_count, + user_ratings_negative_count: model.user_ratings_negative_count, + user_ratings_total_count: model.user_ratings_total_count, created_at: model.created_at, updated_at: model.updated_at, } @@ -126,6 +133,9 @@ SELECT tts.is_front_page_featured, tts.is_twitch_featured, tts.maybe_suggested_unique_bot_command, + tts.user_ratings_positive_count, + tts.user_ratings_negative_count, + tts.user_ratings_total_count, tts.created_at, tts.updated_at FROM tts_models as tts @@ -157,6 +167,9 @@ SELECT tts.is_front_page_featured, tts.is_twitch_featured, tts.maybe_suggested_unique_bot_command, + tts.user_ratings_positive_count, + tts.user_ratings_negative_count, + tts.user_ratings_total_count, tts.created_at, tts.updated_at FROM tts_models as tts @@ -199,6 +212,9 @@ SELECT tts.is_front_page_featured, tts.is_twitch_featured, tts.maybe_suggested_unique_bot_command, + tts.user_ratings_positive_count, + tts.user_ratings_negative_count, + tts.user_ratings_total_count, tts.created_at, tts.updated_at FROM tts_models as tts @@ -233,6 +249,9 @@ SELECT tts.is_front_page_featured, tts.is_twitch_featured, tts.maybe_suggested_unique_bot_command, + tts.user_ratings_positive_count, + tts.user_ratings_negative_count, + tts.user_ratings_total_count, tts.created_at, tts.updated_at FROM tts_models as tts @@ -273,6 +292,10 @@ struct InternalRawTtsModelRecordForList { pub maybe_suggested_unique_bot_command: Option, + pub user_ratings_positive_count: u32, + pub user_ratings_negative_count: u32, + pub user_ratings_total_count: u32, // NB: Does not include "neutral" ratings. + pub created_at: DateTime, pub updated_at: DateTime, } diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/tts/get_tts_model.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/tts/get_tts_model.rs index 4ae6141577..23002b8432 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/tts/get_tts_model.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/tts/get_tts_model.rs @@ -80,6 +80,8 @@ pub struct TtsModelInfo { pub maybe_suggested_unique_bot_command: Option, + pub user_ratings: UserRatingsStats, + pub creator_set_visibility: Visibility, pub is_locked_from_use: bool, @@ -103,6 +105,14 @@ pub struct CustomVocoderInfo { pub creator_gravatar_hash: String, } +#[derive(Serialize)] +pub struct UserRatingsStats { + pub positive_count: u32, + pub negative_count: u32, + /// Total count does not take into account "neutral" ratings. + pub total_count: u32, +} + /// "Moderator-only fields" that we wouldn't want to expose to ordinary users. /// It's the web endpoint controller's responsibility to clear these for non-mods. #[derive(Serialize)] @@ -264,6 +274,11 @@ pub async fn get_tts_model_handler( is_front_page_featured: model.is_front_page_featured, is_twitch_featured: model.is_twitch_featured, maybe_suggested_unique_bot_command: model.maybe_suggested_unique_bot_command, + user_ratings: UserRatingsStats { + positive_count: model.user_ratings_positive_count, + negative_count: model.user_ratings_negative_count, + total_count: model.user_ratings_total_count, + }, creator_set_visibility: model.creator_set_visibility, is_locked_from_use: model.is_locked_from_use, is_locked_from_user_modification: model.is_locked_from_user_modification, diff --git a/crates/service/web/storyteller_web/src/http_server/endpoints/tts/list_tts_models.rs b/crates/service/web/storyteller_web/src/http_server/endpoints/tts/list_tts_models.rs index 2ec956cd38..2f1fd0786f 100644 --- a/crates/service/web/storyteller_web/src/http_server/endpoints/tts/list_tts_models.rs +++ b/crates/service/web/storyteller_web/src/http_server/endpoints/tts/list_tts_models.rs @@ -35,6 +35,8 @@ pub struct TtsModelRecordForResponse { pub is_twitch_featured: bool, pub maybe_suggested_unique_bot_command: Option, + pub user_ratings: UserRatingsStats, + /// Category assignments /// From non-deleted, mod-approved categories only pub category_tokens: HashSet, @@ -43,6 +45,14 @@ pub struct TtsModelRecordForResponse { pub updated_at: DateTime, } +#[derive(Serialize, Clone)] +pub struct UserRatingsStats { + pub positive_count: u32, + pub negative_count: u32, + /// Total count does not take into account "neutral" ratings. + pub total_count: u32, +} + #[derive(Serialize)] pub struct ListTtsModelsSuccessResponse { pub success: bool, @@ -161,6 +171,11 @@ async fn get_all_models(mysql_connection: &mut PoolConnection) -> AnyhowR is_front_page_featured: model.is_front_page_featured, is_twitch_featured: model.is_twitch_featured, maybe_suggested_unique_bot_command: model.maybe_suggested_unique_bot_command, + user_ratings: UserRatingsStats { + positive_count: model.user_ratings_positive_count, + negative_count: model.user_ratings_negative_count, + total_count: model.user_ratings_total_count, + }, category_tokens: model_categories_map.model_to_category_tokens.get(&model_token) .map(|hash| hash.clone()) .unwrap_or(HashSet::new()),