R/jira_sprint_days.R

Defines functions jira_sprint_days

Documented in jira_sprint_days

#' jira_sprint_days
#'
#' Calculate the average number of days per ticket in each status in the sprint
#' @param x The sprint dataframe
#' @param cols A string or vector of strings of named columns to group by - 'change_from' is automatically part of the grouping, so leave it out
#' @seealso \code{\link{jira_sprint_review}} which creates the underlying data set
#' @export

jira_sprint_days <- function(x,cols) {

  require(tidyverse)

  #add the new columns

  if (is_empty(cols) == FALSE) {

    cols_to_group <- c('change_from',cols)

  } else {

    cols_to_group <- 'change_from'

  }

  status_summary <- x %>%
    #get rid of the rows with missing data
    filter(!is.na(change_from)) %>%
    group_by_(.dots = cols_to_group) %>%
    summarize(tickets = n_distinct(issue),
              avg_days_in_status = round(sum(days_difference) / tickets,3)) %>%
    ungroup() %>%
    rename(status = 1)

  return(status_summary)

}
neugelb/njira documentation built on Sept. 2, 2020, 7:02 p.m.