Skip to content

Commit 990e7f3

Browse files
authored
Merge pull request #229 from microsoft/release/checks-for-v1.8.0
Release: housekeeping and checks for `v1.8.0`
2 parents d6aae65 + 3dc6c80 commit 990e7f3

24 files changed

+352
-55031
lines changed

CRAN-SUBMISSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: 1.7.0
2-
Date: 2022-06-06 13:37:15 UTC
3-
SHA: 7aefaa599891ef7c20db669a8f52b59e80ef48ef
1+
Version: 1.8.0
2+
Date: 2022-07-05 14:56:34 UTC
3+
SHA: da3ceafbd54598a196fe0c3c1b29f58f1adc728d

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: wpa
22
Type: Package
33
Title: Tools for Analysing and Visualising Viva Insights Data
4-
Version: 1.7.0.9000
4+
Version: 1.8.0
55
Authors@R: c(
66
person(given = "Martin", family = "Chan", role = c("aut", "cre"), email = "[email protected]"),
77
person(given = "Carlos", family = "Morales", role = "aut", email = "[email protected]"),

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export(hrvar_count)
9696
export(hrvar_count_all)
9797
export(hrvar_trend)
9898
export(identify_churn)
99+
export(identify_datefreq)
99100
export(identify_holidayweeks)
100101
export(identify_inactiveweeks)
101102
export(identify_nkw)
@@ -147,6 +148,7 @@ export(one2one_summary)
147148
export(one2one_trend)
148149
export(p2p_data_sim)
149150
export(p_test)
151+
export(pad2)
150152
export(pairwise_count)
151153
export(period_change)
152154
export(personas_hclust)

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# wpa (development version)
1+
# wpa 1.8.0
22

33
- Updated and improved output and algorithm for `workpatterns_classify()`
44
- Additional visual options for `workpatterns_classify()` and `flex_index()`
5+
- Added the `external_*` family of functions to visualize the metric `Collaboration_hours_external`
6+
- Added experimental function `identify_datefreq()` for detecting date frequency (#131)
57

68
# wpa 1.7.0
79

R/external_dist.R

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' @inherit create_dist return
1919
#'
2020
#' @family Visualization
21-
#' @family External
21+
#' @family External Collaboration
2222
#'
2323
#' @examples
2424
#' # Return plot
@@ -38,13 +38,18 @@ external_dist <- function(data,
3838
return = "plot",
3939
cut = c(5, 10, 15)) {
4040

41-
# Calculate Internal / External Collaboration time
42-
plot_data <- data %>% mutate(External_collaboration_hours = Collaboration_hours_external)
41+
# Rename metric
42+
plot_data <-
43+
data %>%
44+
mutate(External_collaboration_hours = Collaboration_hours_external)
4345

44-
plot_data %>% create_dist(metric = "External_collaboration_hours",
45-
hrvar = hrvar,
46-
mingroup = mingroup,
47-
return = return,
48-
cut = cut,
49-
dist_colours = c("#3F7066", "#64B4A4", "#B1EDE1","#CBF3EB"))
46+
plot_data %>%
47+
create_dist(
48+
metric = "External_collaboration_hours",
49+
hrvar = hrvar,
50+
mingroup = mingroup,
51+
return = return,
52+
cut = cut,
53+
dist_colours = c("#3F7066", "#64B4A4", "#B1EDE1","#CBF3EB")
54+
)
5055
}

R/external_sum.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#' @inherit create_stacked return
1515
#'
1616
#' @family Visualization
17-
#' @family External
17+
#' @family External Collaboration
1818
#'
1919
#' @examples
20-
#' # Return a plot
20+
#' # Return a plot
2121
#' external_sum(sq_data, hrvar = "LevelDesignation")
2222
#'
2323
#' # Return summary table
@@ -32,9 +32,9 @@ external_sum <- function(data,
3232
return = "plot"){
3333

3434

35-
# Calculate Internal / External Collaboration time
36-
plot_data <- data %>% mutate(Internal_hours= Collaboration_hours - Collaboration_hours_external) %>% mutate(External_hours= Collaboration_hours_external)
37-
35+
# Calculate Internal / External Collaboration time
36+
plot_data <- data %>% mutate(Internal_hours= Collaboration_hours - Collaboration_hours_external) %>% mutate(External_hours= Collaboration_hours_external)
37+
3838
# Plot Internal / External Collaboration time by Organization
3939
plot_data %>% create_stacked(hrvar = hrvar, metrics = c("Internal_hours", "External_hours"), plot_title = "Internal and External Collaboration Hours", stack_colours = stack_colours, mingroup = mingroup, return = return)
4040

R/globals.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ utils::globalVariables(
257257
"HRAttribute",
258258
"identifier",
259259
"PersonasNet",
260-
"Unique values"
260+
"Unique values",
261+
"Collaboration_hours_external",
262+
".GRP",
263+
"Id"
261264
)
262265
)

R/identify_datefreq.R

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See LICENSE.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
#' @title Identify date frequency based on a series of dates
7+
#'
8+
#' @description
9+
#' `r lifecycle::badge('experimental')`
10+
#'
11+
#' Takes a vector of dates and identify whether the frequency is 'daily',
12+
#' 'weekly', or 'monthly'. The primary use case for this function is to provide
13+
#' an accurate description of the query type used and for raising errors should
14+
#' a wrong date grouping be used in the data input.
15+
#'
16+
#' @param x Vector containing a series of dates.
17+
#'
18+
#' @details
19+
#' Date frequency detection works as follows:
20+
#' - If at least three days of the week are present (e.g., Monday, Wednesday,
21+
#' Thursday) in the series, then the series is classified as 'daily'
22+
#' - If the total number of months in the series is equal to the length, then
23+
#' the series is classified as 'monthly'
24+
#' - If the total number of sundays in the series is equal to the length of
25+
#' the series, then the series is classified as 'weekly
26+
#'
27+
#' @section Limitations:
28+
#' One of the assumptions made behind the classification is that weeks are
29+
#' denoted with Sundays, hence the count of sundays to measure the number of
30+
#' weeks. In this case, weeks where a Sunday is missing would result in an
31+
#' 'unable to classify' error.
32+
#'
33+
#' Another assumption made is that dates are evenly distributed, i.e. that the
34+
#' gap between dates are equal. If dates are unevenly distributed, e.g. only two
35+
#' days of the week are available for a given week, then the algorithm will fail
36+
#' to identify the frequency as 'daily'.
37+
#'
38+
#' @return
39+
#' String describing the detected date frequency, i.e.:
40+
#' - 'daily'
41+
#' - 'weekly'
42+
#' - 'monthly'
43+
#'
44+
#' @examples
45+
#' start_date <- as.Date("2022/06/26")
46+
#' end_date <- as.Date("2022/11/27")
47+
#'
48+
#' # Daily
49+
#' day_seq <-
50+
#' seq.Date(
51+
#' from = start_date,
52+
#' to = end_date,
53+
#' by = "day"
54+
#' )
55+
#'
56+
#' identify_datefreq(day_seq)
57+
#'
58+
#' # Weekly
59+
#' week_seq <-
60+
#' seq.Date(
61+
#' from = start_date,
62+
#' to = end_date,
63+
#' by = "week"
64+
#' )
65+
#'
66+
#' identify_datefreq(week_seq)
67+
#'
68+
#' # Monthly
69+
#' month_seq <-
70+
#' seq.Date(
71+
#' from = start_date,
72+
#' to = end_date,
73+
#' by = "month"
74+
#' )
75+
#' identify_datefreq(month_seq)
76+
#'
77+
#' @export
78+
79+
identify_datefreq <- function(x){
80+
81+
# Data frame for checking
82+
date_df <- data.frame(
83+
weekdays = names(table(weekdays(x))),
84+
n = as.numeric(table(weekdays(x)))
85+
)
86+
87+
88+
dweekchr <- c(
89+
"Sunday",
90+
"Saturday",
91+
"Monday",
92+
"Tuesday",
93+
"Wednesday",
94+
"Thursday",
95+
"Friday"
96+
)
97+
98+
# At least 3 days of the week must be present
99+
check_wdays <- ifelse(
100+
sum(dweekchr %in% date_df$weekdays) >= 3, TRUE, FALSE)
101+
102+
# Check number of Sundays - should equal number of weeks if weekly
103+
check_nsun <- sum(date_df$n[date_df$weekdays == "Sunday"])
104+
105+
ifelse(
106+
length(months(x)) == length(x),
107+
"monthly",
108+
ifelse(
109+
check_nsun == length(x),
110+
"weekly",
111+
ifelse(
112+
check_wdays,
113+
"daily",
114+
"Unable to identify date frequency."
115+
)
116+
)
117+
)
118+
}

R/plot_flex_index.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ plot_flex_index <- function(data,
151151
)
152152

153153
## 00, 01, 02, etc.
154-
hours_col <- stringr::str_pad(seq(0,23), width = 2, pad = 0)
154+
hours_col <- pad2(x = seq(0,23))
155155

156156
# Use `mutate()` method
157157
# Will get 10 IDs, not 10 rows

R/plot_hourly_pat.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
#' @param legend_text String to be used in the bottom legend label.
2323
#'
2424
#' @param rows Number of rows to show in plot.
25-
#' @noRd
25+
#' @param title String to specify plot title.
26+
#' @param subtitle String to specify plot subtitle.
27+
#' @param caption String to specify plot caption.
28+
#' @param ylab String to specify plot y-axis label.
2629
#'
2730
#' @export
2831

@@ -41,7 +44,7 @@ plot_hourly_pat <- function(
4144
){
4245

4346
## 00, 01, 02, etc.
44-
hours_col <- stringr::str_pad(seq(0,23), width = 2, pad = 0)
47+
hours_col <- pad2(x = seq(0,23))
4548

4649
data %>%
4750
utils::head(rows) %>%

0 commit comments

Comments
 (0)