R/calc_unweighted_gpa.R

Defines functions calc_unweighted_gpa

Documented in calc_unweighted_gpa

#' Calculate Unweighted GPA by Student by Year
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function was deprecated with the addition of the more generalized \code{\link{calc_gpa}} function
#'
#' @param include_school logical. if TRUE, will include the student's school in the output
#' @param ... pass year to fetch_grades function
#'
#' @return
#' @export
#'
#' @keywords internal
#'
#' @examples \dontrun{
#' calc_unweighted_gpa(2018)
#' }
calc_unweighted_gpa <- function(..., include_school = TRUE) {

  lifecycle::deprecate_warn("0.0.1.2", "calc_unweighted_gpa", "calc_gpa")

  #fetching grades
  grds <- ccpsr::fetch_grades(..., secondary_only = TRUE)


  tmp <- grds %>%
    dplyr::filter(mark_name %in% c("Final Grade", "Fall Final Grade", "Spring Final Grade"),
           !(term_code %in% c("Q4", "S1", "S2", "SS2")),
           !(mark %in% c("P", "N", "NC", "AW", "W", "I"))) %>%
    dplyr::left_join(ccpsr::grading_lookup, by = c("mark" = "Letter")) %>%
    dplyr::rename(gp = Regular)


  ret <- if (include_school == TRUE) {
    tmp %>%
      dplyr::group_by(sch_yr, student_id, school_code) %>%
      dplyr::summarize(gpa = mean(gp),
                n_gpa_class = dplyr::n()) %>%
      dplyr::ungroup()
  } else {
    tmp %>%
      dplyr::group_by(sch_yr, student_id) %>%
      dplyr::summarize(gpa = mean(gp),
                n_gpa_class = dplyr::n()) %>%
      dplyr::ungroup()
  }

  return(ret)

}
ekholme-ccps/ccpsr documentation built on Aug. 17, 2021, 10:01 p.m.