OliverKeyes has submitted this change and it was merged.

Change subject: Add check 'n' notify funfeature + check_yesterday & 
check_past_week are used in dashboards   to check whether a dataset is missing 
data from the day   before or the past week, and if any missing data are   
detected then a notificationItem is returned. + M
......................................................................


Add check 'n' notify funfeature
+ check_yesterday & check_past_week are used in dashboards
  to check whether a dataset is missing data from the day
  before or the past week, and if any missing data are
  detected then a notificationItem is returned.
+ Minor documentation formatting changes.

Bug: T118872

Change-Id: I717a4d8583a62accade6189ed33af1110269f8fb
---
M DESCRIPTION
M NAMESPACE
M NEWS.md
A R/check_notify.R
M R/dygraphs.R
M R/shiny.R
M R/smoothing.R
A man/check_notify.Rd
M man/cond_color.Rd
M man/cond_icon.Rd
M man/make_dygraph.Rd
M man/smooth_switch.Rd
M man/time_frame_range.Rd
M man/timeframe_select.Rd
14 files changed, 133 insertions(+), 67 deletions(-)

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



diff --git a/DESCRIPTION b/DESCRIPTION
index 8ce8df1..9be90c3 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
 Package: polloi
 Type: Package
 Title: Common Functionality for Wikimedia Dashboards
-Version: 0.0.6
-Date: 2015-11-10
+Version: 0.0.7
+Date: 2015-11-17
 Authors@R: c(
     person("Oliver", "Keyes", , "oke...@wikimedia.org", role = c("aut", 
"cre")),
     person("Mikhail", "Popov", , "mpo...@wikimedia.org", role = "aut")
@@ -11,7 +11,8 @@
     Wikimedia Foundation's Shiny Dashboards.
 License: MIT + file LICENSE
 URL: https://git.wikimedia.org/summary/wikimedia%2Fdiscovery%2Fpolloi
-BugReports: 
https://phabricator.wikimedia.org/maniphest/task/create/?projects=Search-Team
+BugReports: https://phabricator.wikimedia.org/maniphest/task/create/?
+    projects=Search-Team
 Depends:
     R (>= 3.0.2)
 Imports:
@@ -23,6 +24,7 @@
     lubridate,
     plyr,
     shiny,
+    shinydashboard,
     zoo
 LazyData: TRUE
-RoxygenNote: 5.0.0
+RoxygenNote: 5.0.1
diff --git a/NAMESPACE b/NAMESPACE
index c0b6681..c9095f0 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,6 +1,8 @@
 # Generated by roxygen2: do not edit by hand
 
 export(cbind_fill)
+export(check_past_week)
+export(check_yesterday)
 export(compress)
 export(cond_color)
 export(cond_icon)
@@ -32,5 +34,6 @@
 importFrom(plyr,ddply)
 importFrom(readr,read_delim)
 importFrom(shiny,icon)
+importFrom(shinydashboard,notificationItem)
 importFrom(xts,xts)
 importFrom(zoo,rollmean)
diff --git a/NEWS.md b/NEWS.md
index 353c01b..999cbdb 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,8 @@
+polloi 0.0.7
+============
+- Added function for checking dataset for missing
+  data and creating a notification if any detected.
+
 polloi 0.0.6
 ============
 - Added features from Search Metrics dashboard
diff --git a/R/check_notify.R b/R/check_notify.R
new file mode 100644
index 0000000..fc8d3aa
--- /dev/null
+++ b/R/check_notify.R
@@ -0,0 +1,36 @@
+#'@title Check 'n' Notify
+#'@description Check a dataset for missing data from the day before and the
+#'  past week, and create a \code{notificationItem} if missing data has been
+#'  detected.
+#'@param dataset A data.frame with a 'date' column.
+#'@param label The label to use in the notification.
+#'@family Shiny Dashboarding
+#'@name check_notify
+NULL
+
+#'@rdname check_notify
+#'@importFrom shinydashboard notificationItem
+#'@importFrom shiny icon
+#'@export
+check_yesterday <- function(dataset, label) {
+  # e.g. label = "desktop events"
+  yesterday_date <- Sys.Date() - 1
+  if (!(yesterday_date %in% dataset$date)) {
+    return(notificationItem(text = paste("No", label," from yesterday."),
+                            icon = icon("table"), status = "danger"))
+  }
+  return(NULL)
+}
+
+#'@rdname check_notify
+#'@importFrom shinydashboard notificationItem
+#'@importFrom shiny icon
+#'@export
+check_past_week <- function(dataset, label) {
+  past_week <- Sys.Date() - c(1:7)
+  if (any(!(past_week %in% dataset$date))) {
+    return(notificationItem(text = paste("No", label," from past week."),
+                            icon = icon("table"), status = "danger"))
+  }
+  return(NULL)
+}
diff --git a/R/dygraphs.R b/R/dygraphs.R
index aa5ec97..c665f9c 100644
--- a/R/dygraphs.R
+++ b/R/dygraphs.R
@@ -1,38 +1,26 @@
 #'@title Construct a Standard Wikimedia Discovery Dygraph
-#'@description Construct a dygraph using the custom formatting Wikimedia 
dashboards use
-#'as standard. This is nothing special - a standard dygraph with a bit of 
custom CSS
-#'shipped with the package - but it's surrounded by code that allows the 
function to
-#'turn all our usual data.frame formats into XTS objects.
-#'
+#'@description Construct a dygraph using the custom formatting Wikimedia
+#'  dashboards use as standard. This is nothing special - a standard dygraph
+#'  with a bit of custom CSS shipped with the package - but it's surrounded by
+#'  code that allows the function to turn all our usual data.frame formats
+#'  into XTS objects.
 #'@param data a data.frame reformatted to be XTS-able.
-#'
 #'@param xlab the label to use for the dygraph's x-axis.
-#'
 #'@param ylab the label to use for the dygraph's y-axis.
-#'
 #'@param title the title to use on the dygraph.
-#'
-#'@param legend_name a custom name for the variable in the event that 
\code{is_single} is TRUE.
-#'NULL by default (in which case the variable will be named "events").
-#'
+#'@param legend_name a custom name for the variable in the event that
+#'  \code{is_single} is TRUE. NULL by default (in which case the variable
+#'  will be named "events").
 #'@param use_si whether to use si labelling (1000 becomes 1K). TRUE by default.
-#'
 #'@param expr an optional expression to evaluate prior to building the dygraph.
 #'  We use this in (for example) reactive graphing.
-#'
 #'@param group Group to associate this plot with. The x-axis zoom level of
 #'  plots within a group is automatically synchronized.
-#'
 #'@param ... Additional parameters to pass on to \code{dyOptions}.
-#'
 #'@importFrom dygraphs renderDygraph dyCSS dyOptions dyLegend dygraph
-#'
 #'@importFrom xts xts
-#'
 #'@importFrom RColorBrewer brewer.pal
-#'
 #'@importFrom magrittr "%>%"
-#'
 #'@export
 make_dygraph <- function(data, xlab, ylab, title,
                          legend_name = NULL, use_si = TRUE, expr = NULL,
@@ -69,11 +57,11 @@
 #'@title Select a Colour Conditionally
 #'@description select a colour based on the true/false nature of a condition.
 #'Uses green as the "true" colour by default, "red" as false, and
-#'
-#'@param condition a condition to be evaluated to produce a single TRUE or 
FALSE value
-#'
-#'@param true_color the colour used to represent a TRUE result. Green by 
default.
-#'
+#'@param condition a condition to be evaluated to produce a single TRUE or
+#'  FALSE value.
+#'@param true_color the colour used to represent a TRUE result. Green by
+#'  default.
+#'@family Shiny Dashboarding
 #'@export
 cond_color <- function(condition, true_color = "green") {
   if (is.na(condition)) {
@@ -85,14 +73,12 @@
 }
 
 #'@title Select an appropriate directional icon
-#'@description allows you to select an appropriate directional icon for a 
change
-#'in condition.
-#'
+#'@description allows you to select an appropriate directional icon for a
+#'  change in condition.
 #'@param condition a condition to be evaluated to produce a single TRUE/FALSE
-#'
 #'@param true_direction which direction represents a positive change. "up" by
 #'default.
-#'
+#'@family Shiny Dashboarding
 #'@importFrom shiny icon
 #'@export
 cond_icon <- function(condition, true_direction = "up") {
diff --git a/R/shiny.R b/R/shiny.R
index 71185ea..1c6ae7b 100644
--- a/R/shiny.R
+++ b/R/shiny.R
@@ -13,7 +13,7 @@
 #'@param label Label
 #'@return A \code{selectInput}
 #'@family inputs
-#'@seealso timeframe_daterange
+#'@seealso timeframe_daterange "Shiny Dashboarding"
 #'@export
 timeframe_select <- function(input_id, label = "Time Frame") {
   return(selectInput(inputId = input_id, label = label, selectize = TRUE, 
selected = "global",
@@ -53,7 +53,8 @@
 #'time_frame_range(input$timeframe, input$daterange,
 #'                 input$timeframe_global, input$daterange_global)
 #'}
-#'@seealso subset_by_date_range
+#'@seealso \code{\link{subset_by_date_range}}
+#'@family Shiny Dashboarding
 #'@export
 time_frame_range <- function(input_local_timeframe,
                              input_local_daterange,
diff --git a/R/smoothing.R b/R/smoothing.R
index c0b3c74..a8808e2 100644
--- a/R/smoothing.R
+++ b/R/smoothing.R
@@ -1,14 +1,11 @@
 #'@title Switch between global and local smoothing
-#'
-#'@description We use a lot of smoothing in our reactive graphs,
-#'and tend to offer both global (entire dashboard) and local (tab-specific) 
smoothing options.
-#'\code{smooth_switch} is a simple function to abstract away the logic behind 
determining whether
-#'the global or local option should be relied on.
-#'
+#'@description We use a lot of smoothing in our reactive graphs, and tend to
+#'  offer both global (entire dashboard) and local (tab-specific) smoothing
+#'  options. \code{smooth_switch} is a simple function to abstract away the
+#'  logic behind determining whether the global or local option should be
+#'  relied on.
 #'@param global the input variable for global smoothing.
-#'
 #'@param local the input variable for local smoothing.
-#'
 #'@export
 smooth_switch <- function(global, local){
   if(local == "global"){
@@ -18,23 +15,17 @@
 }
 
 #' @title Dynamically Smooth Data
-#'
 #' @description Takes an untidy (read: dygraph-appropriate) dataset and adds
 #' columns for each variable consisting of the smoothed, averaged mean.
-#'
 #' @param dataset an untidy, dygraph-appropriate data.frame
-#'
 #' @param smooth_level the level of smoothing. Options are "day", "moving_avg",
 #' "week" and "month".
-#'
 #' @param rename whether to rename the fields once smoothed. TRUE by default.
-#'
 #' @export
 #' @importFrom plyr ddply
 #' @importFrom lubridate week year month
 #' @importFrom zoo rollmean
 smoother <- function(dataset, smooth_level = "day", rename = TRUE) {
-
   # Determine the names and levels of aggregation. By default
   # a smoothing level of "day" is assumed, which is no smoothing
   # whatsoever, and so the original dataset is returned.
@@ -56,7 +47,6 @@
 
   # If we're still here it was weekly or monthly. Calculate
   # the average for each unique permutation of filters
-
   result <- plyr::ddply(.data = dataset,
                         .variables = c("filter_1", "filter_2"),
                         .fun = function(df, name_append){
diff --git a/man/check_notify.Rd b/man/check_notify.Rd
new file mode 100644
index 0000000..987528d
--- /dev/null
+++ b/man/check_notify.Rd
@@ -0,0 +1,27 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/check_notify.R
+\name{check_notify}
+\alias{check_notify}
+\alias{check_past_week}
+\alias{check_yesterday}
+\title{Check 'n' Notify}
+\usage{
+check_yesterday(dataset, label)
+
+check_past_week(dataset, label)
+}
+\arguments{
+\item{dataset}{A data.frame with a 'date' column.}
+
+\item{label}{The label to use in the notification.}
+}
+\description{
+Check a dataset for missing data from the day before and the
+ past week, and create a \code{notificationItem} if missing data has been
+ detected.
+}
+\seealso{
+Other Shiny Dashboarding: \code{\link{cond_color}},
+  \code{\link{cond_icon}}, \code{\link{time_frame_range}}
+}
+
diff --git a/man/cond_color.Rd b/man/cond_color.Rd
index 7129613..cb7f9c1 100644
--- a/man/cond_color.Rd
+++ b/man/cond_color.Rd
@@ -7,12 +7,18 @@
 cond_color(condition, true_color = "green")
 }
 \arguments{
-\item{condition}{a condition to be evaluated to produce a single TRUE or FALSE 
value}
+\item{condition}{a condition to be evaluated to produce a single TRUE or
+FALSE value.}
 
-\item{true_color}{the colour used to represent a TRUE result. Green by 
default.}
+\item{true_color}{the colour used to represent a TRUE result. Green by
+default.}
 }
 \description{
 select a colour based on the true/false nature of a condition.
 Uses green as the "true" colour by default, "red" as false, and
 }
+\seealso{
+Other Shiny Dashboarding: \code{\link{check_notify}},
+  \code{\link{cond_icon}}, \code{\link{time_frame_range}}
+}
 
diff --git a/man/cond_icon.Rd b/man/cond_icon.Rd
index b3963ff..c81bf4e 100644
--- a/man/cond_icon.Rd
+++ b/man/cond_icon.Rd
@@ -13,7 +13,11 @@
 default.}
 }
 \description{
-allows you to select an appropriate directional icon for a change
-in condition.
+allows you to select an appropriate directional icon for a
+ change in condition.
+}
+\seealso{
+Other Shiny Dashboarding: \code{\link{check_notify}},
+  \code{\link{cond_color}}, \code{\link{time_frame_range}}
 }
 
diff --git a/man/make_dygraph.Rd b/man/make_dygraph.Rd
index 3deb686..3f16127 100644
--- a/man/make_dygraph.Rd
+++ b/man/make_dygraph.Rd
@@ -16,8 +16,9 @@
 
 \item{title}{the title to use on the dygraph.}
 
-\item{legend_name}{a custom name for the variable in the event that 
\code{is_single} is TRUE.
-NULL by default (in which case the variable will be named "events").}
+\item{legend_name}{a custom name for the variable in the event that
+\code{is_single} is TRUE. NULL by default (in which case the variable
+will be named "events").}
 
 \item{use_si}{whether to use si labelling (1000 becomes 1K). TRUE by default.}
 
@@ -30,9 +31,10 @@
 \item{...}{Additional parameters to pass on to \code{dyOptions}.}
 }
 \description{
-Construct a dygraph using the custom formatting Wikimedia dashboards use
-as standard. This is nothing special - a standard dygraph with a bit of custom 
CSS
-shipped with the package - but it's surrounded by code that allows the 
function to
-turn all our usual data.frame formats into XTS objects.
+Construct a dygraph using the custom formatting Wikimedia
+ dashboards use as standard. This is nothing special - a standard dygraph
+ with a bit of custom CSS shipped with the package - but it's surrounded by
+ code that allows the function to turn all our usual data.frame formats
+ into XTS objects.
 }
 
diff --git a/man/smooth_switch.Rd b/man/smooth_switch.Rd
index b93ecc9..234523d 100644
--- a/man/smooth_switch.Rd
+++ b/man/smooth_switch.Rd
@@ -12,9 +12,10 @@
 \item{local}{the input variable for local smoothing.}
 }
 \description{
-We use a lot of smoothing in our reactive graphs,
-and tend to offer both global (entire dashboard) and local (tab-specific) 
smoothing options.
-\code{smooth_switch} is a simple function to abstract away the logic behind 
determining whether
-the global or local option should be relied on.
+We use a lot of smoothing in our reactive graphs, and tend to
+ offer both global (entire dashboard) and local (tab-specific) smoothing
+ options. \code{smooth_switch} is a simple function to abstract away the
+ logic behind determining whether the global or local option should be
+ relied on.
 }
 
diff --git a/man/time_frame_range.Rd b/man/time_frame_range.Rd
index 9eb60c3..0e67def 100644
--- a/man/time_frame_range.Rd
+++ b/man/time_frame_range.Rd
@@ -35,6 +35,9 @@
 }
 }
 \seealso{
-subset_by_date_range
+\code{\link{subset_by_date_range}}
+
+Other Shiny Dashboarding: \code{\link{check_notify}},
+  \code{\link{cond_color}}, \code{\link{cond_icon}}
 }
 
diff --git a/man/timeframe_select.Rd b/man/timeframe_select.Rd
index 17c92e9..ff7f240 100644
--- a/man/timeframe_select.Rd
+++ b/man/timeframe_select.Rd
@@ -15,7 +15,7 @@
 A \code{selectInput}
 }
 \seealso{
-timeframe_daterange
+timeframe_daterange "Shiny Dashboarding"
 
 Other inputs: \code{\link{smooth_select}},
   \code{\link{timeframe_daterange}}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I717a4d8583a62accade6189ed33af1110269f8fb
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/discovery/polloi
Gerrit-Branch: master
Gerrit-Owner: Bearloga <mpo...@wikimedia.org>
Gerrit-Reviewer: OliverKeyes <oke...@wikimedia.org>

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

Reply via email to