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,