Chelsyx has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/345611 )

Change subject: Add relative option to External By Search Engine
......................................................................

Add relative option to External By Search Engine

Bug: T161771
Change-Id: I833b6477e6375d2ee16da38dac5096e37eb6afb4
---
M server.R
M ui.R
M utils.R
3 files changed, 34 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/discovery/wonderbolt 
refs/changes/11/345611/1

diff --git a/server.R b/server.R
index b0863cf..f835b6e 100644
--- a/server.R
+++ b/server.R
@@ -26,15 +26,28 @@
   })
 
   output$traffic_bysearch_dygraph <- renderDygraph({
-    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",
-                           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 = "") %>%
-      dyEvent(as.Date("2016-06-26"), "A (DuckDuckGo)", labelLoc = "bottom") %>%
-      dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = "bottom")
+    if (input$platform_traffic_bysearch_prop == FALSE){
+      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",
+                             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 = "") %>%
+        dyEvent(as.Date("2016-06-26"), "A (DuckDuckGo)", labelLoc = "bottom") 
%>%
+        dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = 
"bottom")
+    } else{
+      bysearch_traffic_data_prop[[input$platform_traffic_bysearch]] %>%
+        polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, 
input$smoothing_traffic_bysearch)) %>%
+        polloi::make_dygraph(xlab = "Date", ylab = "Pageview Share (%)",
+                             title = "Pageview shares 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 = "") %>%
+        dyEvent(as.Date("2016-06-26"), "A (DuckDuckGo)", labelLoc = "bottom") 
%>%
+        dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = 
"bottom")
+    }
+
   })
 
   # Check datasets for missing data and notify user which datasets are missing 
data (if any)
diff --git a/ui.R b/ui.R
index 358e8a9..c0928f4 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>"),
+                         checkboxInput("platform_traffic_bysearch_log", label 
= "Use Log scale", value = FALSE),
+                         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..4a12d66 100644
--- a/utils.R
+++ b/utils.R
@@ -41,5 +41,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: newchange
Gerrit-Change-Id: I833b6477e6375d2ee16da38dac5096e37eb6afb4
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/wonderbolt
Gerrit-Branch: master
Gerrit-Owner: Chelsyx <c...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to