diff --git a/glados-web/src/lib.rs b/glados-web/src/lib.rs index cbe37550..cb21a491 100644 --- a/glados-web/src/lib.rs +++ b/glados-web/src/lib.rs @@ -90,6 +90,14 @@ pub async fn run_glados_web(config: Arc) -> Result<()> { "/api/hourly-success-rate/", get(routes::hourly_success_rate), ) + .route( + "/api/latest-census-node-diversiity-data", + get(routes::get_radius_diversity_data), + ) + .route( + "/api/latest-census-node-radius-data", + get(routes::generate_radius_graph_data), + ) .route( "/api/is-content-in-deadzone/:content_key", get(routes::is_content_in_deadzone), diff --git a/glados-web/src/routes.rs b/glados-web/src/routes.rs index e03e9e49..a35159d7 100644 --- a/glados-web/src/routes.rs +++ b/glados-web/src/routes.rs @@ -107,7 +107,9 @@ impl Display for ClientDiversityResult { } } -async fn generate_radius_graph_data(state: &Arc) -> Vec { +pub async fn generate_radius_graph_data( + Extension(state): Extension>, +) -> Result>, StatusCode> { let builder = state.database_connection.get_database_backend(); let mut radius_density = Query::select(); radius_density @@ -206,7 +208,20 @@ async fn generate_radius_graph_data(state: &Arc) -> Vec>, +) -> Result>, StatusCode> { + let client_diversity_data = match get_max_census_id(&state).await { + None => vec![], + Some(max_census_id) => generate_client_diversity_data(&state, None, max_census_id) + .await + .unwrap(), + }; + + Ok(Json(client_diversity_data)) } fn xor_distance_to_fraction(radius_high_bytes: [u8; 4]) -> f64 { @@ -384,14 +399,6 @@ async fn generate_enr_list_from_census_id( } pub async fn root(Extension(state): Extension>) -> impl IntoResponse { - let client_diversity_data = match get_max_census_id(&state).await { - None => vec![], - Some(max_census_id) => generate_client_diversity_data(&state, None, max_census_id) - .await - .unwrap(), - }; - - let radius_percentages = generate_radius_graph_data(&state).await; // Run queries for content dashboard data concurrently let (hour_stats, day_stats, week_stats) = tokio::join!( get_audit_stats( @@ -429,8 +436,6 @@ pub async fn root(Extension(state): Extension>) -> impl IntoResponse let week_stats = week_stats.unwrap(); let template = IndexTemplate { - client_diversity_data, - average_radius_chart: radius_percentages, stats: [hour_stats, day_stats, week_stats], }; HtmlTemplate(template) diff --git a/glados-web/src/templates.rs b/glados-web/src/templates.rs index b86aff44..064880a2 100644 --- a/glados-web/src/templates.rs +++ b/glados-web/src/templates.rs @@ -5,16 +5,12 @@ use axum::{ }; use entity::{client_info, content, content_audit, execution_metadata, key_value, node, record}; -use crate::routes::{ - CalculatedRadiusChartData, ClientDiversityResult, PaginatedCensusListResult, RawEnr, -}; +use crate::routes::{ClientDiversityResult, PaginatedCensusListResult, RawEnr}; use glados_core::stats::AuditStats; #[derive(Template)] #[template(path = "index.html")] pub struct IndexTemplate { - pub client_diversity_data: Vec, - pub average_radius_chart: Vec, pub stats: [AuditStats; 3], } diff --git a/glados-web/templates/index.html b/glados-web/templates/index.html index cd753a66..1cf689ed 100644 --- a/glados-web/templates/index.html +++ b/glados-web/templates/index.html @@ -92,10 +92,17 @@

Client Count