OliverKeyes has submitted this change and it was merged.
Change subject: Adds browser breakdown
......................................................................
Adds browser breakdown
- Lets users see share % of each browser over time
- Includes filtering for easier selection
- Includes a variety of sorting options
Bug: T124827
Change-Id: Id905906a04e00c4c78b190e44ec30c1dc87687f4
---
M functions.R
M server.R
A tab_documentation/browsers.md
M ui.R
4 files changed, 123 insertions(+), 5 deletions(-)
Approvals:
OliverKeyes: Verified; Looks good to me, approved
diff --git a/functions.R b/functions.R
index af5932d..f7d3ac5 100644
--- a/functions.R
+++ b/functions.R
@@ -29,3 +29,32 @@
by = "date"],
formula = date ~ country, fun.aggregate =
sum)
}
+
+# Fits an exponential model to the data and returns the rate of growth (or
decay!)
+get_exp_rate <- function(dates, y) {
+ time_frame <- range(dates)
+ days <- as.character(seq(time_frame[1], time_frame[2], "day"))
+ if (length(days) < 3) {
+ return(as.double(NA))
+ } else {
+ x <- as.numeric(as.character(factor(as.character(dates), days,
1:length(days))))
+ return(tryCatch({
+ fit <- nls(y ~ exp(a + b * x), start = list(a = 0, b = 0))
+ round(as.double(fit$m$getPars()['b']), 4)
+ }, error = function(e) {}, finally = as.double(NA)))
+ }
+ # plot(x, y, type = "l")
+ # lines(x, predict(fit, list(x = x)), lty = "dashed", col = "blue")
+}
+
+read_useragents <- function(){
+ data <- as.data.table(polloi::read_dataset(path =
"portal/user_agent_data.tsv"))
+ data$browser <- paste(data$browser, data$version)
+ data$version <- NULL
+ data <- data[order(data$date, data$browser),,]
+ ua_data <<- data
+ browser_rates <<- data[, list(rate = get_exp_rate(date, percent),
+ last = tail(percent, 1),
+ times = length(percent)),
+ by = "browser"]
+}
diff --git a/server.R b/server.R
index b03e03f..7f081b3 100644
--- a/server.R
+++ b/server.R
@@ -52,4 +52,49 @@
dyAxis("x", axisLabelFormatter = polloi::custom_axis_formatter,
axisLabelWidth = 70) %>%
dyLegend(labelsDiv = "country_breakdown_legend", show = "always", width
= 400)
})
+
+ output$browser_selector_container <- renderUI({
+ browsers <- switch(input$browser_order,
+ "alphabet" = {
+ sort(browser_rates$browser)
+ },
+ "growth" = {
+ browser_rates$browser[order(browser_rates$rate,
decreasing = TRUE)]
+ },
+ "decay" = {
+ browser_rates$browser[order(browser_rates$rate,
decreasing = FALSE)]
+ },
+ "last" = {
+ browser_rates$browser[order(browser_rates$last,
decreasing = TRUE)]
+ },
+ "times" = {
+ browser_rates$browser[order(browser_rates$times,
decreasing = TRUE)]
+ })
+ if (input$browser_filter != "") {
+ if (grepl(",\\s?", input$browser_filter, fixed = FALSE)) {
+ browser_filter <- gsub(", ", ",", input$browser_filter, fixed = TRUE)
+ browser_filter <- strsplit(browser_filter, ",")[[1]]
+ browsers <- browsers[browsers %in% unlist(lapply(browser_filter,
function(browser) {
+ browsers[grepl(browser, browsers, ignore.case = TRUE)]
+ }))]
+ } else {
+ browsers <- browsers[grepl(input$browser_filter, browsers, ignore.case
= TRUE)]
+ }
+ }
+ if (!is.null(input$browser_selector)) {
+ selected <- input$browser_selector
+ } else {
+ selected <- browsers[1]
+ }
+ return(selectInput("browser_selector", "Browser", selected = selected,
choices = browsers,
+ multiple = TRUE, selectize = FALSE, size = 15))
+ })
+
+ output$browser_breakdown_dygraph <- renderDygraph({
+ ua_data[ua_data$browser %in% input$browser_selector, , ] %>%
+ reshape2::dcast(date ~ browser, fun.aggregate = sum) %>%
+ polloi::make_dygraph(xlab = "Date", ylab = "Share (%)", title = "Browser
breakdown of portal visitors") %>%
+ dyCSS(css = "www/inverse.css") %>%
+ dyLegend(labelsDiv = "browser_breakdown_legend", show = "always", width
= 400)
+ })
})
diff --git a/tab_documentation/browsers.md b/tab_documentation/browsers.md
new file mode 100644
index 0000000..14aa0a9
--- /dev/null
+++ b/tab_documentation/browsers.md
@@ -0,0 +1,26 @@
+What users use to view the Wikipedia portal
+=======
+
+This measures which Internet browsers portal users use from each day,
displaying the proportion of traffic accounted for by the browser. For any
given day, we only record browsers with at least 0.5% share of users.
+
+Sorting options
+------
+* __Alphabetical sorting__ and __sorting by last recorded percentage__ do what
they say on the tin.
+* __Sorting by popularity growth/decay__ uses an estimated rate (computed by
fitting an exponential model).
+* __Sorting by number of times__ can be useful because a browser is only
included if it has at least 0.5% share, so the number of times can be regarded
as a rough estimate of longevity.
+
+Outages and inaccuracies
+------
+None so far!
+
+Questions, bug reports, and feature suggestions
+------
+For technical, non-bug questions, [email
Mikhail](mailto:[email protected]?subject=Dashboard%20Question). If you
experience a bug or notice something wrong or have a suggestion, [open a ticket
in
Phabricator](https://phabricator.wikimedia.org/maniphest/task/create/?projects=Discovery)
in the Discovery board or [email
Dan](mailto:[email protected]?subject=Dashboard%20Question).
+
+<hr style="border-color: gray;">
+<p style="font-size: small; color: gray;">
+ <strong>Link to this dashboard:</strong>
+ <a href="http://discovery.wmflabs.org/portal/#geographic">
+ http://discovery.wmflabs.org/portal/#geographic
+ </a>
+</p>
diff --git a/ui.R b/ui.R
index fa50e58..ac96dc9 100644
--- a/ui.R
+++ b/ui.R
@@ -12,11 +12,11 @@
tags$link(rel = "stylesheet", type = "text/css", href = "stylesheet.css"),
tags$script(src = "custom.js")
),
- sidebarMenu(menuItem(text = "Traffic"),
- menuSubItem(text = "Clickthrough rate", tabName =
"clickthrough_rate"),
- menuSubItem(text = "Breakdown", tabName = "action_breakdown"),
- menuSubItem(text = "Dwell time", tabName = "dwell_data"),
- menuSubItem(text = "Geographic breakdown", tabName =
"country_breakdown")
+ sidebarMenu(menuItem(text = "Clickthrough rate", tabName =
"clickthrough_rate"),
+ menuItem(text = "Breakdown", tabName = "action_breakdown"),
+ menuItem(text = "Dwell time", tabName = "dwell_data"),
+ menuItem(text = "Geographic breakdown", tabName =
"country_breakdown"),
+ menuItem(text = "Browser breakdown", tabName =
"browser_breakdown", badgeColor = "light-blue", badgeLabel = "New!")
)
)
@@ -42,6 +42,24 @@
style = "height: 60px; padding-top: 30px; padding-left:
20px;"),
style = "width: 100%; background-color: #222D32; color:
#ECF0F5; padding-top: 10px;"),
includeMarkdown("./tab_documentation/geography.md")
+ ),
+ tabItem(tabName = "browser_breakdown",
+ fluidRow(column(selectInput("browser_order", "Sort", selected =
"growth",
+ choices = list("Alphabetically" =
"alphabet",
+ "By popularity growth
rate" = "growth",
+ "By popularity decay
rate" = "decay",
+ "Last recorded
percentage" = "last",
+ "Number of times it
appears in data" = "times")),
+ textInput("browser_filter", "Filter", placeholder
= "IE, firefox"),
+ helpText("Case insensitive & accepts
comma-separated input."),
+ uiOutput("browser_selector_container"),
+ width = 3),
+ column(div(dygraphOutput("browser_breakdown_dygraph"),
+ div(id = "browser_breakdown_legend",
+ style = "height: 60px; padding-top: 30px;
padding-left: 20px;"),
+ style = "width: 100%; background-color:
#222D32; color: #ECF0F5; padding-top: 10px;"),
+ width = 9)),
+ includeMarkdown("./tab_documentation/browsers.md")
)
)
)
--
To view, visit https://gerrit.wikimedia.org/r/271441
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id905906a04e00c4c78b190e44ec30c1dc87687f4
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/prince
Gerrit-Branch: master
Gerrit-Owner: Bearloga <[email protected]>
Gerrit-Reviewer: OliverKeyes <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits