Bearloga has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/345611 )
Change subject: Add relative option to External By Search Engine ...................................................................... Add relative option to External By Search Engine - Adds the option to view search enginer referred pageviews in terms of percentages (shares) - Improves date range selector for both dygraphs - Fixes smoothing on search engine referred pageviews tab Bug: T161771 Change-Id: I833b6477e6375d2ee16da38dac5096e37eb6afb4 --- M server.R M ui.R M utils.R 3 files changed, 25 insertions(+), 8 deletions(-) Approvals: Bearloga: Verified; Looks good to me, approved diff --git a/server.R b/server.R index b0863cf..1c892de 100644 --- a/server.R +++ b/server.R @@ -19,20 +19,24 @@ polloi::make_dygraph(xlab = "Date", ylab = "Pageviews", title = "Sources of page views (e.g. search engines and internal referers)") %>% dyLegend(labelsDiv = "traffic_summary_legend", show = "always", showZeroValues = FALSE) %>% - dyRangeSelector %>% + dyRangeSelector(retainDateWindow = TRUE) %>% dyEvent(as.Date("2016-03-07"), "A (new UDF)", labelLoc = "bottom") %>% dyEvent(as.Date("2016-06-26"), "B (DuckDuckGo)", labelLoc = "bottom") %>% dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = "bottom") }) output$traffic_bysearch_dygraph <- renderDygraph({ - bysearch_traffic_data[[input$platform_traffic_bysearch]] %>% + input$platform_traffic_bysearch_prop %>% + polloi::data_select(bysearch_traffic_data_prop[[input$platform_traffic_bysearch]], + bysearch_traffic_data[[input$platform_traffic_bysearch]]) %>% polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_traffic_bysearch)) %>% - polloi::make_dygraph(xlab = "Date", ylab = "Pageviews", + polloi::make_dygraph(xlab = "Date", ylab = ifelse(input$platform_traffic_bysearch_prop, "Pageview Share (%)", "Pageviews"), title = "Pageviews from external search engines, broken down by engine") %>% dyLegend(labelsDiv = "traffic_bysearch_legend", show = "always", showZeroValues = FALSE) %>% dyAxis("y", logscale = input$platform_traffic_bysearch_log) %>% - dyRangeSelector(fillColor = "", strokeColor = "") %>% + dyRangeSelector(fillColor = ifelse(input$platform_traffic_bysearch_prop, "", "#A7B1C4"), + strokeColor = ifelse(input$platform_traffic_bysearch_prop, "", "#808FAB"), + retainDateWindow = TRUE) %>% dyEvent(as.Date("2016-06-26"), "A (DuckDuckGo)", labelLoc = "bottom") %>% dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = "bottom") }) diff --git a/ui.R b/ui.R index 358e8a9..1ac0e5a 100644 --- a/ui.R +++ b/ui.R @@ -38,7 +38,10 @@ tabItem(tabName = "traffic_by_engine", fluidRow( column(selectizeInput(inputId = "platform_traffic_bysearch", label = "Platform", choices = c("All", "Desktop", "Mobile Web")), width = 2), - column(HTML("<label class = \"control-label\" style = \"margin-bottom:-30px;\">Scale</label>"), checkboxInput("platform_traffic_bysearch_log", label = "Use Log scale", value = FALSE), width = 2), + column(HTML("<label class = \"control-label\" style = \"margin-bottom:-30px;\">Scale</label>"), + conditionalPanel("!input.platform_traffic_bysearch_prop", checkboxInput("platform_traffic_bysearch_log", label = "Use Log scale", value = FALSE)), + conditionalPanel("!input.platform_traffic_bysearch_log", checkboxInput("platform_traffic_bysearch_prop", label = "Use Proportion", value = FALSE)), + width = 2), column(polloi::smooth_select("smoothing_traffic_bysearch"), width = 3), column(div(id = "traffic_bysearch_legend", style = "text-align: right;"), width = 5)), dygraphOutput("traffic_bysearch_dygraph"), diff --git a/utils.R b/utils.R index e2d7a1b..b3f338b 100644 --- a/utils.R +++ b/utils.R @@ -22,8 +22,9 @@ # Write out the overall values for traffic interim <- data[, j = list(pageviews = sum(pageviews)), by = c("date", "referer_class", "access_method")] - interim <- split(interim, f = interim$access_method) - interim$total <- data[,j = list(pageviews = sum(pageviews)), + interim <- split(interim, f = interim$access_method) %>% + lapply(dplyr::select_, .dots = list(quote(-access_method))) # fixes smoothing + interim$total <- data[, j = list(pageviews = sum(pageviews)), by = c("date", "referer_class")] names(interim) <- c("Desktop", "Mobile Web", "All") summary_traffic_data <<- lapply(interim, tidyr::spread, key = "referer_class", value = "pageviews", fill = NA) @@ -32,7 +33,8 @@ interim <- data[is_search == TRUE, j = list(pageviews = sum(pageviews)), by = c("date", "search_engine", "access_method")] - interim <- split(interim, f = interim$access_method) + interim <- split(interim, f = interim$access_method) %>% + lapply(dplyr::select_, .dots = list(quote(-access_method))) # fixes smoothing interim$total <- data[is_search == TRUE, j = list(pageviews = sum(pageviews)), by = c("date", "search_engine")] @@ -41,5 +43,13 @@ lapply(dplyr::filter_, .dots = list(quote(search_engine != "Not referred by search"))) %>% lapply(tidyr::spread, key = "search_engine", value = "pageviews", fill = NA) + # Proportion + interim <- interim %>% + lapply(dplyr::group_by, date) %>% + lapply(dplyr::mutate, pageviews = 100*pageviews/sum(pageviews)) + bysearch_traffic_data_prop <<- interim %>% + lapply(dplyr::filter_, .dots = list(quote(search_engine != "Not referred by search"))) %>% + lapply(tidyr::spread, key = "search_engine", value = "pageviews", fill = NA) + return(invisible()) } -- To view, visit https://gerrit.wikimedia.org/r/345611 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I833b6477e6375d2ee16da38dac5096e37eb6afb4 Gerrit-PatchSet: 3 Gerrit-Project: wikimedia/discovery/wonderbolt Gerrit-Branch: master Gerrit-Owner: Chelsyx <c...@wikimedia.org> Gerrit-Reviewer: Bearloga <mpo...@wikimedia.org> Gerrit-Reviewer: Chelsyx <c...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits