Add model ratings to TTS list and get endpoints

This commit is contained in:
Brandon Thomas committed 2023-01-26 01:12:20 -05:00
1 parent 74ff632f4d
commit a0da010dab
4 files changed
+72

No files matched your search

@@ -44,6 +44,10 @@ pub struct TtsModelRecord {
pub maybe_suggested_unique_bot_command: Option<String>,
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<String>,
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,
@@ -31,6 +31,10 @@ pub struct TtsModelRecordForList {
pub maybe_suggested_unique_bot_command: Option<String>,
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<Utc>,
pub updated_at: DateTime<Utc>,
}
@@ -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<String>,
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<Utc>,
pub updated_at: DateTime<Utc>,
}
@@ -80,6 +80,8 @@ pub struct TtsModelInfo {
pub maybe_suggested_unique_bot_command: Option<String>,
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,
@@ -35,6 +35,8 @@ pub struct TtsModelRecordForResponse {
pub is_twitch_featured: bool,
pub maybe_suggested_unique_bot_command: Option<String>,
pub user_ratings: UserRatingsStats,
/// Category assignments
/// From non-deleted, mod-approved categories only
pub category_tokens: HashSet<String>,
@@ -43,6 +45,14 @@ pub struct TtsModelRecordForResponse {
pub updated_at: DateTime<Utc>,
}
#[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<MySql>) -> 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()),