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: I5691a31c337d56ad70d9217745d530df27c5710e
---
M CHANGELOG.md
M README.md
M server.R
M tab_documentation/wdqs_basic.md
M twilightsparql.Rproj
M ui.R
M utils.R
7 files changed, 66 insertions(+), 28 deletions(-)

Approvals:
  OliverKeyes: Verified; Looks good to me, approved



diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3628ba9..33dc709 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,10 @@
 # Change Log (Patch Notes)
 All notable changes to this project will be documented in this file.
 
+## 2015/11/10
+- Refactored large sections of code
+- Added smoothing and time frame selection
+
 ## 2015/09/30
 - Added a change log
 - Added a contributor code of conduct
diff --git a/README.md b/README.md
index c07b4c8..e3693c5 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 # Wikidata Query Service (WDQS) Dashboard
 
-This project is part of the [Discovery 
Dashboards](http://searchdata.wmflabs.org/) project.
+This project is part of the [Discovery 
Dashboards](http://discovery.wmflabs.org/) project.
 
 ## Quick start
 
diff --git a/server.R b/server.R
index f384f25..57f3d64 100644
--- a/server.R
+++ b/server.R
@@ -1,17 +1,6 @@
 source("utils.R")
 
-existing_date <- (Sys.Date() - 1)
-
-read_wdqs <- function(){
-  data <- polloi::read_dataset("wdqs/wdqs_aggregates.tsv")
-  data <- data[order(data$timestamp),]
-  wdqs_usage <<- dplyr::filter(data, path == "/" & http_success) %>%
-    dplyr::select(c(timestamp, events))
-  
-  sparql_usage <<- dplyr::filter(data, path == "/bigdata/namespace/wdq/sparql" 
& http_success) %>%
-    dplyr::select(c(timestamp, events))
-  return(invisible())
-}
+existing_date <- Sys.Date() - 1
 
 shinyServer(function(input, output) {
   
@@ -20,16 +9,28 @@
     existing_date <<- Sys.Date()
   }
   
+  # 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$wdqs_usage_plot <- renderDygraph(
-    polloi::make_dygraph(data = as.data.frame(wdqs_usage), xlab = "Date", ylab 
= "Events",
-                         title = "Daily WDQS Homepage usage") %>%
+    wdqs_usage %>%
+      polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_usage)) %>%
+      polloi::subset_by_date_range(time_frame_range(input$usage_timeframe, 
input$usage_timeframe_daterange)) %>%
+      polloi::make_dygraph(xlab = "Date", ylab = "Events", title = "Daily WDQS 
Homepage usage", group = "usage") %>%
+      dyLegend(labelsDiv = "usage_legend") %>%
       dyAnnotation(as.Date("2015-09-07"), text = "A", tooltip = "WDQS 
Announced Publically")
   )
   
   output$sparql_usage_plot <- renderDygraph(
-    polloi::make_dygraph(data = as.data.frame(sparql_usage), xlab = "Date", 
ylab = "Events",
-                         title = "Daily SPARQL usage") %>%
-      dyAnnotation(as.Date("2015-09-07"), text = "A", tooltip = "WDQS 
Announced Publically")
+    sparql_usage %>%
+      polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_usage)) %>%
+      polloi::subset_by_date_range(time_frame_range(input$usage_timeframe, 
input$usage_timeframe_daterange)) %>%
+      polloi::make_dygraph(xlab = "Date", ylab = "Events", title = "Daily 
SPARQL usage", group = "usage") %>%
+      dyLegend(labelsDiv = "usage_legend") %>%
+      dyAnnotation(as.Date("2015-09-07"), text = "A", tooltip = "WDQS 
Announced Publically") %>%
+      dyAnnotation(as.Date("2015-11-05"), text = "B", tooltip = "Possible 
Broken Bot on Labs")
   )
   
-})
\ No newline at end of file
+})
diff --git a/tab_documentation/wdqs_basic.md b/tab_documentation/wdqs_basic.md
index 330d26f..609e841 100644
--- a/tab_documentation/wdqs_basic.md
+++ b/tab_documentation/wdqs_basic.md
@@ -4,7 +4,7 @@
 Outages and inaccuracies
 ------
 
-  * None so far!
+  * From 2015-11-04 to 2015-11-06 there was what we believe to be a broken bot 
responsible for 21+ million requests.
 
 Questions, bug reports, and feature suggestions
 ------
diff --git a/twilightsparql.Rproj b/twilightsparql.Rproj
index d063e8b..0a8dc07 100644
--- a/twilightsparql.Rproj
+++ b/twilightsparql.Rproj
@@ -11,3 +11,5 @@
 
 RnwWeave: knitr
 LaTeX: pdfLaTeX
+
+AutoAppendNewline: Yes
diff --git a/ui.R b/ui.R
index 512b107..35dfeca 100644
--- a/ui.R
+++ b/ui.R
@@ -1,6 +1,6 @@
 library(shiny)
 library(shinydashboard)
-library(dygraphs) # optional, used for dygraphs
+library(dygraphs)
 
 # Header elements for the visualization
 header <- dashboardHeader(title = "Wikidata Query Service", disable = FALSE)
@@ -12,19 +12,34 @@
     tags$script(src = "custom.js")
   ),
   sidebarMenu(
-    menuItem(text = "WDQS Usage", tabName = "wdqs_usage")
-  ) # /sidebarMenu
-) # /dashboardSidebar
+    menuItem(text = "WDQS Usage", tabName = "wdqs_usage"),
+    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"))
+  )
+)
 
 #Body elements for the search visualizations.
 body <- dashboardBody(
   tabItems(
     tabItem(tabName = "wdqs_usage",
+            fluidRow(
+              column(polloi::smooth_select("smoothing_usage"), width = 3),
+              column(polloi::timeframe_select("usage_timeframe"), width = 3),
+              column(polloi::timeframe_daterange("usage_timeframe"), width = 
3),
+              column(div(id = "usage_legend"), width = 3)),
             dygraphOutput("wdqs_usage_plot", height = "200px"),
             dygraphOutput("sparql_usage_plot", height = "200px"),
             includeMarkdown("./tab_documentation/wdqs_basic.md"))
-  ) # /tabItems
-) # /dashboardBody
+  )
+)
 
 dashboardPage(header, sidebar, body, skin = "purple",
-              title = "WDQS Usage Dashboard | Discovery | Engineering | 
Wikimedia Foundation")
\ No newline at end of file
+              title = "WDQS Usage Dashboard | Discovery | Engineering | 
Wikimedia Foundation")
diff --git a/utils.R b/utils.R
index 54b4844..4ef09bb 100644
--- a/utils.R
+++ b/utils.R
@@ -1,4 +1,20 @@
 #Dependent libs
 library(reshape2)
 library(polloi)
-library(dplyr)
\ No newline at end of file
+library(dplyr)
+
+read_wdqs <- function() {
+  data <- polloi::read_dataset("wdqs/wdqs_aggregates.tsv") %>%
+    dplyr::rename(date = timestamp) %>%
+    dplyr::arrange(date)
+  
+  wdqs_usage <<- data %>%
+    dplyr::filter(path == "/" & http_success) %>%
+    dplyr::select(c(date, events)) %>% as.data.frame
+  
+  sparql_usage <<- data %>%
+    dplyr::filter(path == "/bigdata/namespace/wdq/sparql" & http_success) %>%
+    dplyr::select(c(date, events)) %>% as.data.frame
+    
+  return(invisible())
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/252271
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5691a31c337d56ad70d9217745d530df27c5710e
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/discovery/twilightsparql
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

Reply via email to