OliverKeyes has submitted this change and it was merged.
Change subject: Added smoothing and time frame selection
......................................................................
Added smoothing and time frame selection
Bug: T118214
Change-Id: I741b28775e7369bb3e536989daf4b074316b53a8
---
M CHANGELOG.md
M server.R
M ui.R
M utils.R
4 files changed, 132 insertions(+), 84 deletions(-)
Approvals:
OliverKeyes: Verified; Looks good to me, approved
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d8a54e0..93133e1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,11 @@
# Change Log (Patch Notes)
All notable changes to this project will be documented in this file.
+## 2015/11/10
+- Fixed smoothing
+- Refactored large sections of code
+- Added time frame selection
+
## 2015/09/30
- Added a change log
- Added a contributor code of conduct
diff --git a/server.R b/server.R
index d2c064d..195f000 100644
--- a/server.R
+++ b/server.R
@@ -1,7 +1,6 @@
-# Version 0.0.1
source("utils.R")
-existing_date <- (Sys.Date()-1)
+existing_date <- Sys.Date() - 1
# Actual server code.
shinyServer(function(input, output) {
@@ -13,40 +12,10 @@
existing_date <<- Sys.Date()
}
- output$users_per_platform <- renderDygraph(polloi::make_dygraph(
- polloi::smoother(user_data,
- smooth_level =
polloi::smooth_switch(input$smoothing_global,
- input$smoothing_users_per_platform)),
- "Date", "Events", "Unique users by platform, by day"
- ))
-
- output$geohack_feature_usage <- renderDygraph(polloi::make_dygraph(
- polloi::smoother(usage_data$GeoHack,
- smooth_level =
polloi::smooth_switch(input$smoothing_global,
- input$smoothing_geohack_feature_usage)),
- "Date", "Events", "Feature usage for GeoHack"
- ))
-
- output$wikiminiatlas_feature_usage <- renderDygraph(polloi::make_dygraph(
- polloi::smoother(usage_data$WikiMiniAtlas,
- smooth_level =
polloi::smooth_switch(input$smoothing_global,
- input$smoothing_wikiminiatlas_feature_usage)),
- "Date", "Events", "Feature usage for WikiMiniAtlas"
- ))
-
- output$wikivoyage_feature_usage <- renderDygraph(polloi::make_dygraph(
- polloi::smoother(usage_data$Wikivoyage,
- smooth_level =
polloi::smooth_switch(input$smoothing_global,
- input$smoothing_wikivoyage_feature_usage)),
- "Date", "Events", "Feature usage for Wikivoyage"
- ))
-
- output$wiwosm_feature_usage <- renderDygraph(polloi::make_dygraph(
- polloi::smoother(usage_data$WIWOSM,
- smooth_level =
polloi::smooth_switch(input$smoothing_global,
- input$smoothing_tiles_summary_series)),
- "Date", "Events", "Feature usage for WIWOSM"
- ))
+ # Wrap time_frame_range to provide global settings
+ time_frame_range <- function(input_local_timeframe, input_local_daterange) {
+ return(polloi::time_frame_range(input_local_timeframe,
input_local_daterange, input$timeframe_global, input$daterange_global))
+ }
output$tiles_summary_series <- renderDygraph({
temp <- ddply(tiles_data, .(date), summarize,
@@ -56,12 +25,13 @@
switch(input$tiles_summary_variable,
Users = { temp %<>% dplyr::select(-`total tiles`) },
Tiles = { temp %<>% dplyr::select(-`total users`) })
- temp %<>% polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
- input$smoothing_tiles_summary_series))
+ temp %<>% polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
input$smoothing_tiles_summary_series)) %>%
+
polloi::subset_by_date_range(time_frame_range(input$tiles_summary_series_timeframe,
input$tiles_summary_series_timeframe_daterange))
polloi::make_dygraph(temp, "Date", input$tiles_summary_variable, "Tile
usage") %>%
dySeries(name = grep('average tiles per user', names(temp), value =
TRUE), axis = 'y2') %>%
dyAxis(name = 'y', drawGrid = FALSE) %>%
dyAxis(name = 'y2', independentTicks = TRUE, drawGrid = FALSE) %>%
+ dyLegend(labelsDiv = "tiles_summary_series_legend", show = "always") %>%
dyAnnotation(as.Date("2015-09-17"), text = "Announcement",
tooltip = "Maps launch announcement",
width = 100, height = 25, attachAtBottom = TRUE)
@@ -69,9 +39,10 @@
output$tiles_style_series <- renderDygraph({
ddply(tiles_data, .(date, style), summarize, `total tiles` = sum(total))
%>%
tidyr::spread(style, `total tiles`) %>%
- polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
- input$smoothing_tiles_style_series)) %>%
+ polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
input$smoothing_tiles_style_series)) %>%
+
polloi::subset_by_date_range(time_frame_range(input$tiles_style_series_timeframe,
input$tiles_style_series_timeframe_daterange)) %>%
polloi::make_dygraph("Date", "Tiles", "Total tiles by style",
legend_name = "Style") %>%
+ dyLegend(labelsDiv = "tiles_style_series_legend", show = "always") %>%
dyAnnotation(as.Date("2015-09-17"), text = "Announcement",
tooltip = "Maps launch announcement",
width = 100, height = 25, attachAtBottom = TRUE)
@@ -79,9 +50,10 @@
output$tiles_users_series <- renderDygraph({
ddply(tiles_data, .(date, style), summarize, `total users` = sum(users))
%>%
tidyr::spread(style, `total users`) %>%
- polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
- input$smoothing_tiles_users_series)) %>%
+ polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
input$smoothing_tiles_users_series)) %>%
+
polloi::subset_by_date_range(time_frame_range(input$tiles_users_series_timeframe,
input$tiles_users_series_timeframe_daterange)) %>%
polloi::make_dygraph("Date", "Users", "Total users by style") %>%
+ dyLegend(labelsDiv = "tiles_users_series_legend", show = "always") %>%
dyAnnotation(as.Date("2015-09-17"), text = "Announcement",
tooltip = "Maps launch announcement",
width = 100, height = 25, attachAtBottom = TRUE)
@@ -96,9 +68,46 @@
subset(zoom %in% as.numeric(input$zoom_level_selector)) %>%
ddply(.(date, zoom), summarize, `total tiles` = sum(total)) %>%
tidyr::spread(zoom, `total tiles`) %>%
- polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
- input$smoothing_tiles_zoom_series)) %>%
- polloi::make_dygraph("Date", "Tiles", "Total tiles by zoom level")
+ polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
input$smoothing_tiles_zoom_series)) %>%
+
polloi::subset_by_date_range(time_frame_range(input$tiles_zoom_series_timeframe,
input$tiles_zoom_series_timeframe_daterange)) %>%
+ polloi::make_dygraph("Date", "Tiles", "Total tiles by zoom level") %>%
+ dyLegend(labelsDiv = "tiles_zoom_series_legend", show = "always")
+ })
+
+ output$users_per_platform <- renderDygraph({
+ user_data %>%
+ polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
input$smoothing_users_per_platform)) %>%
+
polloi::subset_by_date_range(time_frame_range(input$users_per_platform_timeframe,
input$users_per_platform_timeframe_daterange)) %>%
+ polloi::make_dygraph("Date", "Events", "Unique users by platform, by
day") %>%
+ dyLegend(labelsDiv = "users_per_platform_legend", show = "always")
+ })
+
+ output$geohack_feature_usage <- renderDygraph({
+ usage_data$GeoHack %>%
+ polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
input$smoothing_geohack_feature_usage)) %>%
+
polloi::subset_by_date_range(time_frame_range(input$geohack_feature_usage_timeframe,
input$geohack_feature_usage_timeframe_daterange)) %>%
+ polloi::make_dygraph("Date", "Events", "Feature usage for GeoHack")
+ })
+
+ output$wikiminiatlas_feature_usage <- renderDygraph({
+ usage_data$WikiMiniAtlas %>%
+ polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
input$smoothing_wikiminiatlas_feature_usage)) %>%
+
polloi::subset_by_date_range(time_frame_range(input$wikiminiatlas_feature_usage_timeframe,
input$wikiminiatlas_feature_usage_timeframe_daterange)) %>%
+ polloi::make_dygraph("Date", "Events", "Feature usage for WikiMiniAtlas")
+ })
+
+ output$wikivoyage_feature_usage <- renderDygraph({
+ usage_data$Wikivoyage %>%
+ polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
input$smoothing_wikivoyage_feature_usage)) %>%
+
polloi::subset_by_date_range(time_frame_range(input$wikivoyage_feature_usage_timeframe,
input$wikivoyage_feature_usage_timeframe_daterange)) %>%
+ polloi::make_dygraph("Date", "Events", "Feature usage for Wikivoyage")
+ })
+
+ output$wiwosm_feature_usage <- renderDygraph({
+ usage_data$WIWOSM %>%
+ polloi::smoother(smooth_level =
polloi::smooth_switch(input$smoothing_global,
input$smoothing_wiwosm_feature_usage)) %>%
+
polloi::subset_by_date_range(time_frame_range(input$wiwosm_feature_usage_timeframe,
input$wiwosm_feature_usage_timeframe_daterange)) %>%
+ polloi::make_dygraph("Date", "Events", "Feature usage for WIWOSM")
})
})
diff --git a/ui.R b/ui.R
index 3596855..ca35ed5 100644
--- a/ui.R
+++ b/ui.R
@@ -1,7 +1,6 @@
library(shiny)
library(shinydashboard)
library(dygraphs)
-options(scipen = 500)
header <- dashboardHeader(title = "Wikimedia Maps", disable = FALSE)
@@ -22,58 +21,91 @@
menuSubItem(text = "WikiMiniAtlas", tabName = "wikiminiatlas"),
menuSubItem(text = "Wikivoyage", tabName = "wikivoyage"),
menuSubItem(text = "WIWOSM", tabName = "wiwosm")),
- selectInput(inputId = "smoothing_global", label = "Smoothing (Global
Setting)", selectize = TRUE, selected = "day",
- choices = c("No Smoothing" = "day", "Weekly Median" = "week",
"Monthly Median" = "month"))
+ menuItem(text = "Global Settings",
+ selectInput(inputId = "smoothing_global", label = "Smoothing",
selectize = TRUE, selected = "day",
+ choices = c("No Smoothing" = "day", "Weekly Median" =
"week", "Monthly Median" = "month")),
+ selectInput(inputId = "timeframe_global", label = "Time Frame",
selectize = TRUE, selected = "",
+ choices = c("All available data" = "all", "Last 7
days" = "week", "Last 30 days" = "month",
+ "Last 90 days" = "quarter", "Custom" =
"custom")),
+ conditionalPanel("input.timeframe_global == 'custom'",
+ dateRangeInput("daterange_global", label =
"Custom Date Range",
+ start = Sys.Date()-11, end =
Sys.Date()-1, min = "2015-04-14")),
+ icon = icon("cog", lib = "glyphicon"))
)
)
-# Standardised input selector for smoothing
-smooth_select <- function(input_id, label = "Smoothing") {
- return(selectInput(inputId = input_id, label = label, selectize = TRUE,
- selected = "global", choices = c("Use Global Setting" =
"global",
- "No Smoothing" = "day", "Weekly Median" = "week", "Monthly Median" =
"month")))
-}
-
body <- dashboardBody(
tabItems(
+ tabItem(tabName = "tiles_summary",
+ fluidRow(
+ column(selectInput("tiles_summary_variable", "Total", c("Users",
"Tiles")), width = 2),
+ column(polloi::smooth_select("smoothing_tiles_summary_series"),
width = 3),
+
column(polloi::timeframe_select("tiles_summary_series_timeframe"), width = 3),
+
column(polloi::timeframe_daterange("tiles_summary_series_timeframe"), width =
4)),
+ dygraphOutput("tiles_summary_series"),
+ div(id = "tiles_summary_series_legend", style = "text-align:
right;"),
+ includeMarkdown("./tab_documentation/tiles_summary.md")),
+ tabItem(tabName = "tiles_total_by_style",
+ fluidRow(
+ column(polloi::smooth_select("smoothing_tiles_style_series"),
width = 4),
+ column(polloi::timeframe_select("tiles_style_series_timeframe"),
width = 4),
+
column(polloi::timeframe_daterange("tiles_style_series_timeframe"), width = 4)),
+ dygraphOutput("tiles_style_series"),
+ div(id = "tiles_style_series_legend", style = "text-align:
right;"),
+ includeMarkdown("./tab_documentation/tiles_total_by_style.md")),
+ tabItem(tabName = "tiles_users_by_style",
+ fluidRow(
+ column(polloi::smooth_select("smoothing_tiles_users_series"),
width = 4),
+ column(polloi::timeframe_select("tiles_users_series_timeframe"),
width = 4),
+
column(polloi::timeframe_daterange("tiles_users_series_timeframe"), width = 4)),
+ dygraphOutput("tiles_users_series"),
+ div(id = "tiles_users_series_legend", style = "text-align:
right;"),
+ includeMarkdown("./tab_documentation/tiles_users_by_style.md")),
+ tabItem(tabName = "tiles_total_by_zoom",
+ fluidRow(
+ column(polloi::smooth_select("smoothing_tiles_zoom_series"),
width = 4),
+ column(polloi::timeframe_select("tiles_zoom_series_timeframe"),
width = 4),
+
column(polloi::timeframe_daterange("tiles_zoom_series_timeframe"), width = 4)),
+ fluidRow(column(uiOutput("zoom_level_selector_container"), width =
3),
+ column(dygraphOutput("tiles_zoom_series"), width = 8)),
+ div(id = "tiles_zoom_series_legend", style = "text-align: right;"),
+ includeMarkdown("./tab_documentation/tiles_total_by_zoom.md")),
tabItem(tabName = "platform_usage",
- smooth_select("smoothing_users_per_platform"),
+ fluidRow(
+ column(polloi::smooth_select("smoothing_users_per_platform"),
width = 4),
+ column(polloi::timeframe_select("users_per_platform_timeframe"),
width = 4),
+
column(polloi::timeframe_daterange("users_per_platform_timeframe"), width = 4)),
dygraphOutput("users_per_platform"),
+ div(id = "users_per_platform_legend", style = "text-align:
right;"),
includeMarkdown("./tab_documentation/unique_users.md")),
tabItem(tabName = "geohack",
- smooth_select("smoothing_geohack_feature_usage"),
+ fluidRow(
+ column(polloi::smooth_select("smoothing_geohack_feature_usage"),
width = 4),
+
column(polloi::timeframe_select("geohack_feature_usage_timeframe"), width = 4),
+
column(polloi::timeframe_daterange("geohack_feature_usage_timeframe"), width =
4)),
dygraphOutput("geohack_feature_usage"),
includeMarkdown("./tab_documentation/geohack_usage.md")),
tabItem(tabName = "wikiminiatlas",
- smooth_select("smoothing_wikiminiatlas_feature_usage"),
+ fluidRow(
+
column(polloi::smooth_select("smoothing_wikiminiatlas_feature_usage"), width =
4),
+
column(polloi::timeframe_select("wikiminiatlas_feature_usage_timeframe"), width
= 4),
+
column(polloi::timeframe_daterange("wikiminiatlas_feature_usage_timeframe"),
width = 4)),
dygraphOutput("wikiminiatlas_feature_usage"),
includeMarkdown("./tab_documentation/wikiminiatlas_usage.md")),
tabItem(tabName = "wikivoyage",
- smooth_select("smoothing_wikivoyage_feature_usage"),
+ fluidRow(
+
column(polloi::smooth_select("smoothing_wikivoyage_feature_usage"), width = 4),
+
column(polloi::timeframe_select("wikivoyage_feature_usage_timeframe"), width =
4),
+
column(polloi::timeframe_daterange("wikivoyage_feature_usage_timeframe"), width
= 4)),
dygraphOutput("wikivoyage_feature_usage"),
includeMarkdown("./tab_documentation/wikivoyage_usage.md")),
tabItem(tabName = "wiwosm",
- smooth_select("smoothing_wiwosm_feature_usage"),
+ fluidRow(
+ column(polloi::smooth_select("smoothing_wiwosm_feature_usage"),
width = 4),
+
column(polloi::timeframe_select("wiwosm_feature_usage_timeframe"), width = 4),
+
column(polloi::timeframe_daterange("wiwosm_feature_usage_timeframe"), width =
4)),
dygraphOutput("wiwosm_feature_usage"),
- includeMarkdown("./tab_documentation/wiwosm_usage.md")),
- tabItem(tabName = "tiles_summary",
- fluidRow(column(smooth_select("smoothing_tiles_summary_series"),
width = 6),
- column(selectInput("tiles_summary_variable", "Total",
c("Users", "Tiles")), width = 6)),
- dygraphOutput("tiles_summary_series"),
- includeMarkdown("./tab_documentation/tiles_summary.md")),
- tabItem(tabName = "tiles_total_by_style",
- smooth_select("smoothing_tiles_style_series"),
- dygraphOutput("tiles_style_series"),
- includeMarkdown("./tab_documentation/tiles_total_by_style.md")),
- tabItem(tabName = "tiles_users_by_style",
- smooth_select("smoothing_tiles_users_series"),
- dygraphOutput("tiles_users_series"),
- includeMarkdown("./tab_documentation/tiles_users_by_style.md")),
- tabItem(tabName = "tiles_total_by_zoom",
- smooth_select("smoothing_tiles_zoom_series"),
- fluidRow(column(uiOutput("zoom_level_selector_container"), width =
3),
- column(dygraphOutput("tiles_zoom_series"), width = 8)),
- includeMarkdown("./tab_documentation/tiles_total_by_zoom.md"))
+ includeMarkdown("./tab_documentation/wiwosm_usage.md"))
)
)
diff --git a/utils.R b/utils.R
index 5606f3e..4497270 100644
--- a/utils.R
+++ b/utils.R
@@ -8,16 +8,18 @@
# used in dygraphs.
read_actions <- function() {
# Read in data, split and rename it, and write it o
- data <- polloi::read_dataset("maps/actions_per_tool.tsv")
- data <- split(data[,c(1,3,4)], data$feature)
- usage_data <<- lapply(data, reshape2::dcast, formula = timestamp ~ variable,
fun.aggregate = sum)
+ data <- polloi::read_dataset("maps/actions_per_tool.tsv") %>%
+ dplyr::rename(date = timestamp)
+ data <- split(data[, c(1, 3, 4)], data$feature)
+ usage_data <<- lapply(data, reshape2::dcast, formula = date ~ variable,
fun.aggregate = sum)
return(invisible())
}
# Read in user count
read_users <- function() {
- data <- polloi::read_dataset("maps/users_per_feature.tsv")
- interim <- reshape2::dcast(data, formula = timestamp ~ variable,
fun.aggregate = sum)
+ data <- polloi::read_dataset("maps/users_per_feature.tsv") %>%
+ dplyr::rename(date = timestamp)
+ interim <- reshape2::dcast(data, formula = date ~ variable, fun.aggregate =
sum)
interim[is.na(interim)] <- 0
user_data <<- interim
return(invisible())
--
To view, visit https://gerrit.wikimedia.org/r/252272
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I741b28775e7369bb3e536989daf4b074316b53a8
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/discovery/wetzel
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