From 9f798559cfd0d031560793d0317898695f5a1e84 Mon Sep 17 00:00:00 2001 From: Wyatt Verchere Date: Fri, 15 Dec 2023 12:49:55 -0700 Subject: [PATCH] country testing (#801) Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com> --- src/routes/v3/analytics_get.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/routes/v3/analytics_get.rs b/src/routes/v3/analytics_get.rs index dc754279..6b81f1a2 100644 --- a/src/routes/v3/analytics_get.rs +++ b/src/routes/v3/analytics_get.rs @@ -413,6 +413,11 @@ pub async fn countries_downloads_get( } } + let hm: HashMap> = hm + .into_iter() + .map(|(key, value)| (key, condense_countries(value))) + .collect(); + Ok(HttpResponse::Ok().json(hm)) } @@ -480,9 +485,31 @@ pub async fn countries_views_get( } } + let hm: HashMap> = hm + .into_iter() + .map(|(key, value)| (key, condense_countries(value))) + .collect(); + Ok(HttpResponse::Ok().json(hm)) } +fn condense_countries(countries: HashMap) -> HashMap { + // Every country under '15' (view or downloads) should be condensed into 'XX' + let mut hm = HashMap::new(); + for (mut country, count) in countries { + if count < 15 { + country = "XX".to_string(); + } + if !hm.contains_key(&country) { + hm.insert(country.to_string(), 0); + } + if let Some(hm) = hm.get_mut(&country) { + *hm += count; + } + } + hm +} + async fn filter_allowed_ids( mut project_ids: Option>, user: crate::models::users::User,