From 30ebd611af312b802d0e87d2c24e841a181f2c3c Mon Sep 17 00:00:00 2001 From: mrferris Date: Wed, 21 Feb 2024 10:56:01 -0500 Subject: [PATCH] feat: adds 4444s stats and graphing --- entity/src/audit_stats.rs | 12 ++++ glados-audit/src/stats.rs | 48 +++++++++++++++ glados-core/src/stats.rs | 4 ++ glados-web/assets/js/stats_history.js | 12 +++- glados-web/templates/audit_dashboard.html | 4 +- migration/src/lib.rs | 2 + .../m20240213_190221_add_fourfours_stats.rs | 60 +++++++++++++++++++ 7 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 migration/src/m20240213_190221_add_fourfours_stats.rs 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..e9401ad7 100644 --- a/glados-audit/src/stats.rs +++ b/glados-audit/src/stats.rs @@ -31,6 +31,7 @@ async fn record_current_stats(conn: &DatabaseConnection) -> Result<(), DbErr> { latest, random, oldest, + fourfours, all_headers, all_bodies, all_receipts, @@ -40,6 +41,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 +81,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 +170,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 +205,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 +215,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 +227,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 +237,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..e720976c 100644 --- a/glados-web/assets/js/stats_history.js +++ b/glados-web/assets/js/stats_history.js @@ -99,7 +99,7 @@ function createMultiLineChart(height, width, dataSets) { // Select all '.legend' group elements and click on all but the first three svg.selectAll(".legend") - .each(function(d, i) { + .each(function (d, i) { if (i >= 3) { // Skip the first three dispatchClick(this); } @@ -113,7 +113,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 +135,7 @@ function convertDataForChart(data) { 'success_rate_latest', 'success_rate_random', 'success_rate_oldest', + 'success_rate_4444s', 'success_rate_all_headers', 'success_rate_all_bodies', 'success_rate_all_receipts', @@ -140,6 +145,9 @@ function convertDataForChart(data) { 'success_rate_random_headers', 'success_rate_random_bodies', 'success_rate_random_receipts', + 'success_rate_4444s_headers', + 'success_rate_4444s_bodies', + 'success_rate_4444s_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 +
-
+