Bearloga has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/367456 )
Change subject: Use new functions in polloi to get geo data
......................................................................
Use new functions in polloi to get geo data
Bug: T167913
Change-Id: I00cad391fa22399f583eb7791256c1eb25ba611b
---
M modules/metrics/portal/geographic_breakdown.R
1 file changed, 2 insertions(+), 14 deletions(-)
Approvals:
Bearloga: Verified; Looks good to me, approved
diff --git a/modules/metrics/portal/geographic_breakdown.R
b/modules/metrics/portal/geographic_breakdown.R
index 606e6a0..3456a45 100644
--- a/modules/metrics/portal/geographic_breakdown.R
+++ b/modules/metrics/portal/geographic_breakdown.R
@@ -66,23 +66,11 @@
} else {
results$ts <- as.POSIXct(results$ts, format = "%Y%m%d%H%M%S")
# Geography data that is common to both outputs:
- data("ISO_3166_1", package = "ISOcodes")
- # Remove accents because Reportupdater requires ASCII:
- ISO_3166_1$Name <- stringi::stri_trans_general(ISO_3166_1$Name,
"Latin-ASCII")
- us_other_abb <- c("AS", "GU", "MP", "PR", "VI")
- us_other_mask <- match(us_other_abb, ISO_3166_1$Alpha_2)
- regions <- data.frame(abb = c(paste0("US:", c(as.character(state.abb),
"DC")), us_other_abb),
- region = paste0("U.S. (",
c(as.character(state.region), "South", rep("Other",5)), ")"),
- state = c(state.name, "District of Columbia",
ISO_3166_1$Name[us_other_mask]),
- stringsAsFactors = FALSE)
- regions$region[regions$region == "U.S. (North Central)"] <- "U.S. (Midwest)"
- regions$region[c(state.division == "Pacific", rep(FALSE, 5))] <- "U.S.
(Pacific)" # see https://phabricator.wikimedia.org/T136257#2399411
+ regions <- polloi::get_us_state()
library(magrittr) # Required for piping
if (opt$include_all) {
# Generate all countries breakdown
- all_countries <- data.frame(abb = c(regions$abb,
ISO_3166_1$Alpha_2[-us_other_mask]),
- name = c(regions$region,
ISO_3166_1$Name[-us_other_mask]),
- stringsAsFactors = FALSE)
+ all_countries <- polloi::get_country_state()
data_w_countryname <- results %>%
dplyr::mutate(country = ifelse(country %in% all_countries$abb, country,
"Other")) %>%
dplyr::left_join(all_countries, by = c("country" = "abb")) %>%
--
To view, visit https://gerrit.wikimedia.org/r/367456
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I00cad391fa22399f583eb7791256c1eb25ba611b
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/golden
Gerrit-Branch: master
Gerrit-Owner: Chelsyx <[email protected]>
Gerrit-Reviewer: Bearloga <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits