diff --git a/entity/src/audit_stats.rs b/entity/src/audit_stats.rs index dc0bd0f7..627ea69c 100644 --- a/entity/src/audit_stats.rs +++ b/entity/src/audit_stats.rs @@ -16,6 +16,7 @@ pub struct Model { pub success_rate_latest: f32, pub success_rate_random: f32, pub success_rate_oldest: f32, + pub success_rate_four_fours: f32, pub success_rate_all_headers: f32, pub success_rate_all_bodies: f32, pub success_rate_all_receipts: f32, @@ -25,6 +26,9 @@ pub struct Model { pub success_rate_random_headers: f32, pub success_rate_random_bodies: f32, pub success_rate_random_receipts: f32, + pub success_rate_four_fours_headers: f32, + pub success_rate_four_fours_bodies: f32, + pub success_rate_four_fours_receipts: f32, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -40,6 +44,7 @@ pub async fn create( success_rate_latest: f32, success_rate_random: f32, success_rate_oldest: f32, + success_rate_four_fours: f32, success_rate_all_headers: f32, success_rate_all_bodies: f32, success_rate_all_receipts: f32, @@ -49,6 +54,9 @@ pub async fn create( success_rate_random_headers: f32, success_rate_random_bodies: f32, success_rate_random_receipts: f32, + success_rate_four_fours_headers: f32, + success_rate_four_fours_bodies: f32, + success_rate_four_fours_receipts: f32, conn: &DatabaseConnection, ) -> Result { let audit_stats = ActiveModel { @@ -59,6 +67,7 @@ pub async fn create( success_rate_latest: Set(success_rate_latest), success_rate_random: Set(success_rate_random), success_rate_oldest: Set(success_rate_oldest), + success_rate_four_fours: Set(success_rate_four_fours), success_rate_all_headers: Set(success_rate_all_headers), success_rate_all_bodies: Set(success_rate_all_bodies), success_rate_all_receipts: Set(success_rate_all_receipts), @@ -68,6 +77,9 @@ pub async fn create( success_rate_random_headers: Set(success_rate_random_headers), success_rate_random_bodies: Set(success_rate_random_bodies), success_rate_random_receipts: Set(success_rate_random_receipts), + success_rate_four_fours_headers: Set(success_rate_four_fours_headers), + success_rate_four_fours_bodies: Set(success_rate_four_fours_bodies), + success_rate_four_fours_receipts: Set(success_rate_four_fours_receipts), }; Ok(audit_stats.insert(conn).await?) } diff --git a/glados-audit/src/stats.rs b/glados-audit/src/stats.rs index 740e50e6..d3cc3b19 100644 --- a/glados-audit/src/stats.rs +++ b/glados-audit/src/stats.rs @@ -6,7 +6,7 @@ use glados_core::stats::{ }; use sea_orm::{DatabaseConnection, DbErr}; use tokio::time::{interval, Duration}; -use tracing::{debug, error, info}; +use tracing::{debug, error}; /// Loops indefinitely, periodically recording audit stats to the database. pub async fn periodically_record_stats(period: Duration, conn: DatabaseConnection) -> ! { @@ -17,7 +17,6 @@ pub async fn periodically_record_stats(period: Duration, conn: DatabaseConnectio record_current_stats(&conn).await.unwrap_or_else(|e| { error!("failed to record audit stats: {e}"); }); - info!("Successfully recorded audit stats"); interval.tick().await; } } @@ -31,6 +30,7 @@ async fn record_current_stats(conn: &DatabaseConnection) -> Result<(), DbErr> { latest, random, oldest, + fourfours, all_headers, all_bodies, all_receipts, @@ -40,6 +40,9 @@ async fn record_current_stats(conn: &DatabaseConnection) -> Result<(), DbErr> { random_headers, random_bodies, random_receipts, + fourfours_headers, + fourfours_bodies, + fourfours_receipts, ) = tokio::join!( get_audit_stats( filter_audits(AuditFilters { @@ -77,6 +80,15 @@ async fn record_current_stats(conn: &DatabaseConnection) -> Result<(), DbErr> { Period::Hour, conn ), + get_audit_stats( + filter_audits(AuditFilters { + strategy: StrategyFilter::FourFours, + content_type: ContentTypeFilter::All, + success: SuccessFilter::All + }), + Period::Hour, + conn + ), get_audit_stats( filter_audits(AuditFilters { strategy: StrategyFilter::All, @@ -157,6 +169,33 @@ async fn record_current_stats(conn: &DatabaseConnection) -> Result<(), DbErr> { }), Period::Hour, conn + ), + get_audit_stats( + filter_audits(AuditFilters { + strategy: StrategyFilter::FourFours, + content_type: ContentTypeFilter::Headers, + success: SuccessFilter::All + }), + Period::Hour, + conn + ), + get_audit_stats( + filter_audits(AuditFilters { + strategy: StrategyFilter::FourFours, + content_type: ContentTypeFilter::Bodies, + success: SuccessFilter::All + }), + Period::Hour, + conn + ), + get_audit_stats( + filter_audits(AuditFilters { + strategy: StrategyFilter::FourFours, + content_type: ContentTypeFilter::Receipts, + success: SuccessFilter::All + }), + Period::Hour, + conn ) ); @@ -165,6 +204,7 @@ async fn record_current_stats(conn: &DatabaseConnection) -> Result<(), DbErr> { let success_rate_latest = latest?.pass_percent; let success_rate_random = random?.pass_percent; let success_rate_oldest = oldest?.pass_percent; + let success_rate_fourfours = fourfours?.pass_percent; let success_rate_all_headers = all_headers?.pass_percent; let success_rate_all_bodies = all_bodies?.pass_percent; let success_rate_all_receipts = all_receipts?.pass_percent; @@ -174,6 +214,9 @@ async fn record_current_stats(conn: &DatabaseConnection) -> Result<(), DbErr> { let success_rate_random_headers = random_headers?.pass_percent; let success_rate_random_bodies = random_bodies?.pass_percent; let success_rate_random_receipts = random_receipts?.pass_percent; + let success_rate_fourfours_headers = fourfours_headers?.pass_percent; + let success_rate_fourfours_bodies = fourfours_bodies?.pass_percent; + let success_rate_fourfours_receipts = fourfours_receipts?.pass_percent; // Record the values. match audit_stats::create( @@ -183,6 +226,7 @@ async fn record_current_stats(conn: &DatabaseConnection) -> Result<(), DbErr> { success_rate_latest, success_rate_random, success_rate_oldest, + success_rate_fourfours, success_rate_all_headers, success_rate_all_bodies, success_rate_all_receipts, @@ -192,6 +236,9 @@ async fn record_current_stats(conn: &DatabaseConnection) -> Result<(), DbErr> { success_rate_random_headers, success_rate_random_bodies, success_rate_random_receipts, + success_rate_fourfours_headers, + success_rate_fourfours_bodies, + success_rate_fourfours_receipts, conn, ) .await diff --git a/glados-core/src/stats.rs b/glados-core/src/stats.rs index 0d3021fa..db92dc81 100644 --- a/glados-core/src/stats.rs +++ b/glados-core/src/stats.rs @@ -31,6 +31,9 @@ pub fn filter_audits(filters: AuditFilters) -> Select { StrategyFilter::Oldest => audits.filter( content_audit::Column::StrategyUsed.eq(SelectionStrategy::SelectOldestUnaudited), ), + StrategyFilter::FourFours => { + audits.filter(content_audit::Column::StrategyUsed.eq(SelectionStrategy::FourFours)) + } }; // Success filters let audits = match filters.success { @@ -200,6 +203,7 @@ pub enum StrategyFilter { Random, Latest, Oldest, + FourFours, } #[derive(Deserialize)] diff --git a/glados-web/assets/js/stats_history.js b/glados-web/assets/js/stats_history.js index 8dbc503e..551d402e 100644 --- a/glados-web/assets/js/stats_history.js +++ b/glados-web/assets/js/stats_history.js @@ -98,9 +98,10 @@ function createMultiLineChart(height, width, dataSets) { } // Select all '.legend' group elements and click on all but the first three + let selectedIndexes = [0, 4, 14, 15, 16] svg.selectAll(".legend") - .each(function(d, i) { - if (i >= 3) { // Skip the first three + .each(function (d, i) { + if (!selectedIndexes.includes(i)) { // Skip the first three dispatchClick(this); } }); @@ -113,7 +114,11 @@ function createMultiLineChart(height, width, dataSets) { .attr("fill", (d, i) => colors[i % colors.length]); // Add text to the legend. - const labels = ["All", "Latest", "Random", "Oldest", "All Headers", "All Bodies", "All Receipts", "Latest Headers", "Latest Bodies", "Latest Receipts", "Random Headers", "Random Bodies", "Random Receipts"]; + const labels = ["All", "Latest", "Random", "Oldest", "4444s", + "All Headers", "All Bodies", "All Receipts", + "Latest Headers", "Latest Bodies", "Latest Receipts", + "Random Headers", "Random Bodies", "Random Receipts", + "4444s Headers", "4444s Bodies", "4444s Receipts"]; legend.append("text") .attr("x", -24) .attr("y", 9) @@ -131,6 +136,7 @@ function convertDataForChart(data) { 'success_rate_latest', 'success_rate_random', 'success_rate_oldest', + 'success_rate_four_fourss', 'success_rate_all_headers', 'success_rate_all_bodies', 'success_rate_all_receipts', @@ -140,6 +146,9 @@ function convertDataForChart(data) { 'success_rate_random_headers', 'success_rate_random_bodies', 'success_rate_random_receipts', + 'success_rate_four_fours_headers', + 'success_rate_four_fours_bodies', + 'success_rate_four_fours_receipts' ]; return successRateKeys.map(key => diff --git a/glados-web/templates/audit_dashboard.html b/glados-web/templates/audit_dashboard.html index 97a86f5a..843013bb 100644 --- a/glados-web/templates/audit_dashboard.html +++ b/glados-web/templates/audit_dashboard.html @@ -29,6 +29,8 @@

Audit Dashboard

type="button">Random +
-
+