зеркало из https://github.com/microsoft/wpa.git
feat: allow dynamic signals (#56)
This commit is contained in:
Родитель
e8ae5da4c6
Коммит
a29e320046
|
@ -29,8 +29,11 @@
|
|||
#' and "abs".
|
||||
#'
|
||||
#' @param signals Character vector to specify which collaboration metrics to use:
|
||||
#' You may use "email" (default) for emails only, "IM" for Teams messages only,
|
||||
#' or a combination of the two `c("email", "IM")`.
|
||||
#' - "email" (default) for emails only
|
||||
#' - "IM" for Teams messages only,
|
||||
#' - "unscheduled_calls" for Unscheduled Calls only
|
||||
#' - "meetings" for Meetings only
|
||||
#' - or a combination of signals, such as `c("email", "IM")`
|
||||
#'
|
||||
#' @param start_hour A character vector specifying starting hours,
|
||||
#' e.g. "0900". Note that this currently only supports **hourly** increments.
|
||||
|
|
|
@ -66,54 +66,16 @@ workpatterns_classify_bw <- function(data,
|
|||
end_hour <- as.numeric(gsub(pattern = "00$", replacement = "", x = end_hour))
|
||||
|
||||
# Calculate hours within working hours
|
||||
d <-(end_hour - start_hour)-1
|
||||
d <- (end_hour - start_hour) - 1
|
||||
|
||||
## Select input variable names
|
||||
if("email" %in% signals & "IM" %in% signals){
|
||||
# Text replacement only for allowed values
|
||||
|
||||
## Create 24 summed `Signals_sent` columns
|
||||
signal_cols <-
|
||||
purrr::map(0:23, ~combine_signals(data2, hr = .)) %>%
|
||||
dplyr::bind_cols()
|
||||
if(any(signals %in% c("email", "IM", "unscheduled_calls", "meetings"))){
|
||||
|
||||
## Use names for matching
|
||||
input_var <- names(signal_cols)
|
||||
|
||||
## Signals sent by Person and date
|
||||
signals_df <-
|
||||
data2 %>%
|
||||
.[, c("PersonId", "Date")] %>%
|
||||
cbind(signal_cols)
|
||||
|
||||
## Signal label
|
||||
sig_label <- "Signals_sent"
|
||||
|
||||
} else if(signals == "IM"){
|
||||
|
||||
match_index <- grepl(pattern = "^IMs_sent", x = names(data2))
|
||||
input_var <- names(data2)[match_index]
|
||||
input_var2 <- c("PersonId", "Date", input_var)
|
||||
|
||||
## signals sent by Person and date
|
||||
signals_df <-
|
||||
data2 %>%
|
||||
.[, ..input_var2]
|
||||
|
||||
sig_label <- "IMs_sent"
|
||||
|
||||
|
||||
} else if(signals == "email"){
|
||||
|
||||
match_index <- grepl(pattern = "^Emails_sent", x = names(data2))
|
||||
input_var <- names(data2)[match_index]
|
||||
input_var2 <- c("PersonId", "Date", input_var)
|
||||
|
||||
## signals sent by Person and date
|
||||
signals_df <-
|
||||
data2 %>%
|
||||
.[, ..input_var2]
|
||||
|
||||
sig_label <- "Emails_sent"
|
||||
signal_set <- gsub(pattern = "email", replacement = "Emails_sent", x = signals) # case-sensitive
|
||||
signal_set <- gsub(pattern = "IM", replacement = "IMs_sent", x = signal_set)
|
||||
signal_set <- gsub(pattern = "unscheduled_calls", replacement = "Unscheduled_calls", x = signal_set)
|
||||
signal_set <- gsub(pattern = "meetings", replacement = "Meetings", x = signal_set)
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -121,6 +83,75 @@ workpatterns_classify_bw <- function(data,
|
|||
|
||||
}
|
||||
|
||||
## Create 24 summed `Signals_sent` columns
|
||||
signal_cols <- purrr::map(0:23, ~combine_signals(data, hr = ., signals = signal_set))
|
||||
signal_cols <- bind_cols(signal_cols)
|
||||
|
||||
## Use names for matching
|
||||
input_var <- names(signal_cols)
|
||||
|
||||
## Signals sent by Person and Date
|
||||
signals_df <-
|
||||
data2 %>%
|
||||
.[, c("PersonId", "Date")] %>%
|
||||
cbind(signal_cols)
|
||||
|
||||
## Signal label
|
||||
sig_label <- ifelse(length(signal_set) > 1, "Signals_sent", signal_set)
|
||||
|
||||
# ## Select input variable names
|
||||
# if("email" %in% signals & "IM" %in% signals){
|
||||
#
|
||||
# ## Create 24 summed `Signals_sent` columns
|
||||
# signal_cols <-
|
||||
# purrr::map(0:23, ~combine_signals(data2, hr = .)) %>%
|
||||
# dplyr::bind_cols()
|
||||
#
|
||||
# ## Use names for matching
|
||||
# input_var <- names(signal_cols)
|
||||
#
|
||||
# ## Signals sent by Person and date
|
||||
# signals_df <-
|
||||
# data2 %>%
|
||||
# .[, c("PersonId", "Date")] %>%
|
||||
# cbind(signal_cols)
|
||||
#
|
||||
# ## Signal label
|
||||
# sig_label <- "Signals_sent"
|
||||
#
|
||||
# } else if(signals == "IM"){
|
||||
#
|
||||
# match_index <- grepl(pattern = "^IMs_sent", x = names(data2))
|
||||
# input_var <- names(data2)[match_index]
|
||||
# input_var2 <- c("PersonId", "Date", input_var)
|
||||
#
|
||||
# ## signals sent by Person and date
|
||||
# signals_df <-
|
||||
# data2 %>%
|
||||
# .[, ..input_var2]
|
||||
#
|
||||
# sig_label <- "IMs_sent"
|
||||
#
|
||||
#
|
||||
# } else if(signals == "email"){
|
||||
#
|
||||
# match_index <- grepl(pattern = "^Emails_sent", x = names(data2))
|
||||
# input_var <- names(data2)[match_index]
|
||||
# input_var2 <- c("PersonId", "Date", input_var)
|
||||
#
|
||||
# ## signals sent by Person and date
|
||||
# signals_df <-
|
||||
# data2 %>%
|
||||
# .[, ..input_var2]
|
||||
#
|
||||
# sig_label <- "Emails_sent"
|
||||
#
|
||||
# } else {
|
||||
#
|
||||
# stop("Invalid input for `signals`.")
|
||||
#
|
||||
# }
|
||||
|
||||
|
||||
## Create binary variable 0 or 1
|
||||
num_cols <- names(which(sapply(signals_df, is.numeric))) # Get numeric columns
|
||||
|
|
|
@ -49,57 +49,14 @@ workpatterns_classify_pav <- function(data,
|
|||
start_hour <- as.numeric(sub(pattern = "00$", replacement = "", x = start_hour))
|
||||
end_hour <- as.numeric(sub(pattern = "00$", replacement = "", x = end_hour))
|
||||
|
||||
## Select input variable names
|
||||
if("email" %in% signals & "IM" %in% signals){
|
||||
# Text replacement only for allowed values
|
||||
|
||||
## Create 24 summed `Signals_sent` columns
|
||||
signal_cols <-
|
||||
purrr::map(0:23,
|
||||
~combine_signals(data,
|
||||
hr = .)) %>%
|
||||
bind_cols()
|
||||
if(any(signals %in% c("email", "IM", "unscheduled_calls", "meetings"))){
|
||||
|
||||
## Use names for matching
|
||||
input_var <- names(signal_cols)
|
||||
|
||||
## Average signals sent by Person
|
||||
signals_df <-
|
||||
data %>%
|
||||
select(PersonId) %>%
|
||||
cbind(signal_cols) %>%
|
||||
group_by(PersonId) %>%
|
||||
summarise_all(~mean(.))
|
||||
|
||||
## Signal label
|
||||
sig_label <- "Signals_sent"
|
||||
|
||||
} else if(signals == "IM"){
|
||||
|
||||
match_index <- grepl(pattern = "^IMs_sent", x = names(data))
|
||||
input_var <-names(data)[match_index]
|
||||
|
||||
## Average signals sent by Person
|
||||
signals_df <-
|
||||
data %>%
|
||||
select(PersonId, all_of(input_var)) %>%
|
||||
group_by(PersonId) %>%
|
||||
summarise_all(~mean(.))
|
||||
|
||||
sig_label <- "IMs_sent"
|
||||
|
||||
} else if(signals == "email"){
|
||||
|
||||
match_index <- grepl(pattern = "^Emails_sent", x = names(data))
|
||||
input_var <-names(data)[match_index]
|
||||
|
||||
## Average signals sent by Person
|
||||
signals_df <-
|
||||
data %>%
|
||||
select(PersonId, all_of(input_var)) %>%
|
||||
group_by(PersonId) %>%
|
||||
summarise_all(~mean(.))
|
||||
|
||||
sig_label <- "Emails_sent"
|
||||
signal_set <- gsub(pattern = "email", replacement = "Emails_sent", x = signals) # case-sensitive
|
||||
signal_set <- gsub(pattern = "IM", replacement = "IMs_sent", x = signal_set)
|
||||
signal_set <- gsub(pattern = "unscheduled_calls", replacement = "Unscheduled_calls", x = signal_set)
|
||||
signal_set <- gsub(pattern = "meetings", replacement = "Meetings", x = signal_set)
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -107,6 +64,82 @@ workpatterns_classify_pav <- function(data,
|
|||
|
||||
}
|
||||
|
||||
## Create 24 summed `Signals_sent` columns
|
||||
signal_cols <- purrr::map(0:23, ~combine_signals(data, hr = ., signals = signal_set))
|
||||
signal_cols <- bind_cols(signal_cols)
|
||||
|
||||
## Use names for matching
|
||||
input_var <- names(signal_cols)
|
||||
|
||||
## Average signals sent by Person
|
||||
signals_df <-
|
||||
data %>%
|
||||
select(PersonId) %>%
|
||||
cbind(signal_cols) %>%
|
||||
group_by(PersonId) %>%
|
||||
summarise_all(~mean(.))
|
||||
|
||||
## Signal label
|
||||
sig_label <- ifelse(length(signal_set) > 1, "Signals_sent", signal_set)
|
||||
|
||||
# ## Select input variable names
|
||||
# if("email" %in% signals & "IM" %in% signals){
|
||||
#
|
||||
# ## Create 24 summed `Signals_sent` columns
|
||||
# signal_cols <-
|
||||
# purrr::map(0:23,
|
||||
# ~combine_signals(data,
|
||||
# hr = .)) %>%
|
||||
# bind_cols()
|
||||
#
|
||||
# ## Use names for matching
|
||||
# input_var <- names(signal_cols)
|
||||
#
|
||||
# ## Average signals sent by Person
|
||||
# signals_df <-
|
||||
# data %>%
|
||||
# select(PersonId) %>%
|
||||
# cbind(signal_cols) %>%
|
||||
# group_by(PersonId) %>%
|
||||
# summarise_all(~mean(.))
|
||||
#
|
||||
# ## Signal label
|
||||
# sig_label <- "Signals_sent"
|
||||
#
|
||||
# } else if(signals == "IM"){
|
||||
#
|
||||
# match_index <- grepl(pattern = "^IMs_sent", x = names(data))
|
||||
# input_var <-names(data)[match_index]
|
||||
#
|
||||
# ## Average signals sent by Person
|
||||
# signals_df <-
|
||||
# data %>%
|
||||
# select(PersonId, all_of(input_var)) %>%
|
||||
# group_by(PersonId) %>%
|
||||
# summarise_all(~mean(.))
|
||||
#
|
||||
# sig_label <- "IMs_sent"
|
||||
#
|
||||
# } else if(signals == "email"){
|
||||
#
|
||||
# match_index <- grepl(pattern = "^Emails_sent", x = names(data))
|
||||
# input_var <-names(data)[match_index]
|
||||
#
|
||||
# ## Average signals sent by Person
|
||||
# signals_df <-
|
||||
# data %>%
|
||||
# select(PersonId, all_of(input_var)) %>%
|
||||
# group_by(PersonId) %>%
|
||||
# summarise_all(~mean(.))
|
||||
#
|
||||
# sig_label <- "Emails_sent"
|
||||
#
|
||||
# } else {
|
||||
#
|
||||
# stop("Invalid input for `signals`.")
|
||||
#
|
||||
# }
|
||||
|
||||
|
||||
## Normalised pattern data
|
||||
ptn_data_norm <-
|
||||
|
|
|
@ -28,8 +28,11 @@
|
|||
#' or absolute values in "data" and "plot". Valid values are "percent" (default)
|
||||
#' and "abs".
|
||||
#' @param signals Character vector to specify which collaboration metrics to use:
|
||||
#' You may use "email" (default) for emails only, "IM" for Teams messages only,
|
||||
#' "unscheduled_calls" for Unscheduled Calls only, or a combination, such as `c("email", "IM")`.
|
||||
#' - "email" (default) for emails only
|
||||
#' - "IM" for Teams messages only,
|
||||
#' - "unscheduled_calls" for Unscheduled Calls only
|
||||
#' - "meetings" for Meetings only
|
||||
#' - or a combination of signals, such as `c("email", "IM")`
|
||||
#' @param start_hour A character vector specifying starting hours,
|
||||
#' e.g. "0900"
|
||||
#' @param end_hour A character vector specifying starting hours,
|
||||
|
|
|
@ -28,8 +28,13 @@ or absolute values in "data" and "plot". Valid values are "percent" (default)
|
|||
and "abs".}
|
||||
|
||||
\item{signals}{Character vector to specify which collaboration metrics to use:
|
||||
You may use "email" (default) for emails only, "IM" for Teams messages only,
|
||||
or a combination of the two \code{c("email", "IM")}.}
|
||||
\itemize{
|
||||
\item "email" (default) for emails only
|
||||
\item "IM" for Teams messages only,
|
||||
\item "unscheduled_calls" for Unscheduled Calls only
|
||||
\item "meetings" for Meetings only
|
||||
\item or a combination of signals, such as \code{c("email", "IM")}
|
||||
}}
|
||||
|
||||
\item{start_hour}{A character vector specifying starting hours,
|
||||
e.g. "0900". Note that this currently only supports \strong{hourly} increments.}
|
||||
|
|
|
@ -30,8 +30,13 @@ or absolute values in "data" and "plot". Valid values are "percent" (default)
|
|||
and "abs".}
|
||||
|
||||
\item{signals}{Character vector to specify which collaboration metrics to use:
|
||||
You may use "email" (default) for emails only, "IM" for Teams messages only,
|
||||
"unscheduled_calls" for Unscheduled Calls only, or a combination, such as \code{c("email", "IM")}.}
|
||||
\itemize{
|
||||
\item "email" (default) for emails only
|
||||
\item "IM" for Teams messages only,
|
||||
\item "unscheduled_calls" for Unscheduled Calls only
|
||||
\item "meetings" for Meetings only
|
||||
\item or a combination of signals, such as \code{c("email", "IM")}
|
||||
}}
|
||||
|
||||
\item{start_hour}{A character vector specifying starting hours,
|
||||
e.g. "0900"}
|
||||
|
|
Загрузка…
Ссылка в новой задаче