From d0889c50fcabf4c258f2090af45e86dd57a14440 Mon Sep 17 00:00:00 2001 From: laureng-hd Date: Thu, 15 Feb 2024 12:07:38 -0800 Subject: [PATCH] # Updates to align with newest version of API, handles added 'tag' endpoint. 3 new columns added to `get_tests_` outputs: test_type_tag_ids, test_type_tag_names, test_type_tag_desc --- .Rhistory | 8 ++++++++ DESCRIPTION | 2 +- NEWS.md | 6 ++++++ R/get_tests.R | 40 +++++++++++++++++++++++++++++++++++++--- R/get_tests_ath.R | 34 ++++++++++++++++++++++++++++++++++ R/get_tests_group.R | 34 ++++++++++++++++++++++++++++++++++ R/get_tests_team.R | 34 ++++++++++++++++++++++++++++++++++ R/get_tests_type.R | 34 ++++++++++++++++++++++++++++++++++ README.Rmd | 2 +- README.md | 4 ++-- man/get_tests.Rd | 12 +++++++++--- man/get_tests_ath.Rd | 6 ++++++ man/get_tests_group.Rd | 6 ++++++ man/get_tests_team.Rd | 6 ++++++ man/get_tests_type.Rd | 6 ++++++ 15 files changed, 224 insertions(+), 10 deletions(-) diff --git a/.Rhistory b/.Rhistory index bc91c08..7c0a27b 100644 --- a/.Rhistory +++ b/.Rhistory @@ -98,3 +98,11 @@ base::paste0("?syncFrom=",from) base::paste0("?from=",from) } devtools::load_all(".") +pkgdown::build_site() +library(usethis) +edit_r_environ() +install.packages("remotes") +library(remotes) +library(remotes) +install_github("laureng_hd/hawkinR") +install_github("HawkinDynamics/hawkinR") diff --git a/DESCRIPTION b/DESCRIPTION index 7b7abed..75b7b57 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hawkinR Title: R package to work with data from the Hawkin Dynamics API -Version: 1.0.3.2 +Version: 1.0.4 Authors@R: person("Lauren", "Green", , "lauren@hawkindynamics.com", role = c("aut", "cre")) Description: Provides simple functionality with Hawkin Dynamics API. These functions are for use with 'Hawkin Dynamics Beta API' version 1.8-beta. You must be an Hawkin Dynamics user with active integration account to utilize functions within the package. This API is designed to get data out of your Hawkin Dynamics database into your own database. It is not designed to be accessed from client applications directly. There is a limit on the amount of data that can be returned in a single request. As your database grows, it will be necessary to use the from and to parameters to limit the size of the responses. Responses that exceed the memory limit will fail. diff --git a/NEWS.md b/NEWS.md index 75cbe78..0b5dc8b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,11 @@ # Change Log +## hawkinR v1.0.4 + +# changes to API endpoint (inclusion of test tag details). All `get_tests_...` function outputs now +include tag Ids, names, and description columns with the prefix 'test_type_tag_'. These can be +found after 'test_type_cacnnonicalId' column. + ## hawkinR v1.0.3.2 # bug fixes to all `get_tests_...` functions to handle NULL externalIds diff --git a/R/get_tests.R b/R/get_tests.R index 6b9902a..172eddd 100644 --- a/R/get_tests.R +++ b/R/get_tests.R @@ -34,11 +34,17 @@ #' #' **segment** *chr* Description of the test type and trial number of the session (testType:trialNo) #' -#' **testType_id** *chr* Id of the test type of the trial +#' **test_type_id** *chr* Id of the test type of the trial #' -#' **testType_name** *chr* Name of the test type of the trial +#' **test_type_name** *chr* Name of the test type of the trial #' -#' **testType_canonicalId** *chr* Canonical Id of the test type of the trial +#' **test_type_canonicalId** *chr* Canonical Id of the test type of the trial +#' +#' **test_type_tag_ids** *chr* String of Ids associated with tags used during the test trial +#' +#' **test_type_tag_names** *chr* String of names of tags used during the test trial +#' +#' **test_type_tag_desc** *chr* String of descriptions of tags used during the test trial #' #' **athlete_id** *chr* Unique Id of the athlete #' @@ -245,6 +251,34 @@ get_tests <- function(from = NULL, to = NULL, sync = FALSE, active = TRUE) { # Create testType df t <- x$testType + # extract tags array from data frame + tagList <- t$tags + + # Define a function to pad empty data frames with NA values + # and condense multiple rows into one with values separated by '|' + pad_and_condense <- function(df) { + if (base::is.null(df) || base::nrow(df) == 0) { + return(base::data.frame(tagIds = NA, tagNames = NA, tagDesc = NA)) + } else { + condensed_row <- base::data.frame( + tagIds = base::paste(df$id, collapse = ','), + tagNames = base::paste(df$name, collapse = ','), + tagDesc = base::ifelse(all(df$description == ""), NA, base::paste(df$description, collapse = '|')) + ) + return(condensed_row) + } + } + + # Apply the padding function to all data frames in the list + paddedTagList <- base::lapply(tagList, pad_and_condense) + + # Combine all data frames into one + tagsDF <- base::do.call(rbind, paddedTagList) + + # Replace new tags columns to testType df + t <- dplyr::select(t, -'tags') + t <- base::cbind(t,tagsDF) + # append testType prefix base::names(t) <- base::paste0('testType_', base::names(t)) diff --git a/R/get_tests_ath.R b/R/get_tests_ath.R index 8f5ab1a..fc42608 100644 --- a/R/get_tests_ath.R +++ b/R/get_tests_ath.R @@ -43,6 +43,12 @@ #' #' **testType.canonicalId** *chr* Canonical Id of the test type of the trial #' +#' **test_type_tag_ids** *chr* String of Ids associated with tags used during the test trial +#' +#' **test_type_tag_names** *chr* String of names of tags used during the test trial +#' +#' **test_type_tag_desc** *chr* String of descriptions of tags used during the test trial +#' #' **athlete.id** *chr* Unique Id of the athlete #' #' **athlete.name** *chr* Athlete given name @@ -245,6 +251,34 @@ get_tests_ath <- function(athleteId, from = NULL, to = NULL, sync = FALSE, activ # Create testType df t <- x$testType + # extract tags array from data frame + tagList <- t$tags + + # Define a function to pad empty data frames with NA values + # and condense multiple rows into one with values separated by '|' + pad_and_condense <- function(df) { + if (base::is.null(df) || base::nrow(df) == 0) { + return(base::data.frame(tagIds = NA, tagNames = NA, tagDesc = NA)) + } else { + condensed_row <- base::data.frame( + tagIds = base::paste(df$id, collapse = ','), + tagNames = base::paste(df$name, collapse = ','), + tagDesc = base::ifelse(all(df$description == ""), NA, base::paste(df$description, collapse = '|')) + ) + return(condensed_row) + } + } + + # Apply the padding function to all data frames in the list + paddedTagList <- base::lapply(tagList, pad_and_condense) + + # Combine all data frames into one + tagsDF <- base::do.call(rbind, paddedTagList) + + # Replace new tags columns to testType df + t <- dplyr::select(t, -'tags') + t <- base::cbind(t,tagsDF) + # append testType prefix base::names(t) <- base::paste0('testType_', base::names(t)) diff --git a/R/get_tests_group.R b/R/get_tests_group.R index ca4fa79..e756a5b 100644 --- a/R/get_tests_group.R +++ b/R/get_tests_group.R @@ -44,6 +44,12 @@ #' #' **testType.canonicalId** *chr* Canonical Id of the test type of the trial #' +#' **test_type_tag_ids** *chr* String of Ids associated with tags used during the test trial +#' +#' **test_type_tag_names** *chr* String of names of tags used during the test trial +#' +#' **test_type_tag_desc** *chr* String of descriptions of tags used during the test trial +#' #' **athlete.id** *chr* Unique Id of the athlete #' #' **athlete.name** *chr* Athlete given name @@ -274,6 +280,34 @@ get_tests_group <- function(groupId, from = NULL, to = NULL, sync = FALSE, activ # Create testType df t <- x$testType + # extract tags array from data frame + tagList <- t$tags + + # Define a function to pad empty data frames with NA values + # and condense multiple rows into one with values separated by '|' + pad_and_condense <- function(df) { + if (base::is.null(df) || base::nrow(df) == 0) { + return(base::data.frame(tagIds = NA, tagNames = NA, tagDesc = NA)) + } else { + condensed_row <- base::data.frame( + tagIds = base::paste(df$id, collapse = ','), + tagNames = base::paste(df$name, collapse = ','), + tagDesc = base::ifelse(all(df$description == ""), NA, base::paste(df$description, collapse = '|')) + ) + return(condensed_row) + } + } + + # Apply the padding function to all data frames in the list + paddedTagList <- base::lapply(tagList, pad_and_condense) + + # Combine all data frames into one + tagsDF <- base::do.call(rbind, paddedTagList) + + # Replace new tags columns to testType df + t <- dplyr::select(t, -'tags') + t <- base::cbind(t,tagsDF) + # append testType prefix base::names(t) <- base::paste0('testType_', base::names(t)) diff --git a/R/get_tests_team.R b/R/get_tests_team.R index e4bf94c..2efba77 100644 --- a/R/get_tests_team.R +++ b/R/get_tests_team.R @@ -44,6 +44,12 @@ #' #' **testType.canonicalId** *chr* Canonical Id of the test type of the trial #' +#' **test_type_tag_ids** *chr* String of Ids associated with tags used during the test trial +#' +#' **test_type_tag_names** *chr* String of names of tags used during the test trial +#' +#' **test_type_tag_desc** *chr* String of descriptions of tags used during the test trial +#' #' **athlete.id** *chr* Unique Id of the athlete #' #' **athlete.name** *chr* Athlete given name @@ -274,6 +280,34 @@ get_tests_team <- function(teamId, from = NULL, to = NULL, sync = FALSE, active # Create testType df t <- x$testType + # extract tags array from data frame + tagList <- t$tags + + # Define a function to pad empty data frames with NA values + # and condense multiple rows into one with values separated by '|' + pad_and_condense <- function(df) { + if (base::is.null(df) || base::nrow(df) == 0) { + return(base::data.frame(tagIds = NA, tagNames = NA, tagDesc = NA)) + } else { + condensed_row <- base::data.frame( + tagIds = base::paste(df$id, collapse = ','), + tagNames = base::paste(df$name, collapse = ','), + tagDesc = base::ifelse(all(df$description == ""), NA, base::paste(df$description, collapse = '|')) + ) + return(condensed_row) + } + } + + # Apply the padding function to all data frames in the list + paddedTagList <- base::lapply(tagList, pad_and_condense) + + # Combine all data frames into one + tagsDF <- base::do.call(rbind, paddedTagList) + + # Replace new tags columns to testType df + t <- dplyr::select(t, -'tags') + t <- base::cbind(t,tagsDF) + # append testType prefix base::names(t) <- base::paste0('testType_', base::names(t)) diff --git a/R/get_tests_type.R b/R/get_tests_type.R index cc0e7d2..18a3029 100644 --- a/R/get_tests_type.R +++ b/R/get_tests_type.R @@ -42,6 +42,12 @@ #' #' **testType.canonicalId** *chr* Canonical Id of the test type of the trial #' +#' **test_type_tag_ids** *chr* String of Ids associated with tags used during the test trial +#' +#' **test_type_tag_names** *chr* String of names of tags used during the test trial +#' +#' **test_type_tag_desc** *chr* String of descriptions of tags used during the test trial +#' #' **athlete.id** *chr* Unique Id of the athlete #' #' **athlete.name** *chr* Athlete given name @@ -264,6 +270,34 @@ get_tests_type <- function(typeId, from = NULL, to = NULL, sync = FALSE, active= # Create testType df t <- x$testType + # extract tags array from data frame + tagList <- t$tags + + # Define a function to pad empty data frames with NA values + # and condense multiple rows into one with values separated by '|' + pad_and_condense <- function(df) { + if (base::is.null(df) || base::nrow(df) == 0) { + return(base::data.frame(tagIds = NA, tagNames = NA, tagDesc = NA)) + } else { + condensed_row <- base::data.frame( + tagIds = base::paste(df$id, collapse = ','), + tagNames = base::paste(df$name, collapse = ','), + tagDesc = base::ifelse(all(df$description == ""), NA, base::paste(df$description, collapse = '|')) + ) + return(condensed_row) + } + } + + # Apply the padding function to all data frames in the list + paddedTagList <- base::lapply(tagList, pad_and_condense) + + # Combine all data frames into one + tagsDF <- base::do.call(rbind, paddedTagList) + + # Replace new tags columns to testType df + t <- dplyr::select(t, -'tags') + t <- base::cbind(t,tagsDF) + # append testType prefix base::names(t) <- base::paste0('testType_', base::names(t)) diff --git a/README.Rmd b/README.Rmd index 888043e..aa502dc 100644 --- a/README.Rmd +++ b/README.Rmd @@ -24,7 +24,7 @@ knitr::opts_chunk$set( [![R-CMD-check](https://github.com/HawkinDynamics/hawkinR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/HawkinDynamics/hawkinR/actions/workflows/R-CMD-check.yaml) [![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-yellowgreen.svg)](/commits/master) [![license](https://img.shields.io/badge/license-MIT%20+%20file%20LICENSE-lightgrey.svg)](https://choosealicense.com/) [![minimal R version](https://img.shields.io/badge/R%3E%3D-`r "3.5.0"`-6666ff.svg)](https://cran.r-project.org/) [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) -[![packageversion](https://img.shields.io/badge/Package%20version-`r "1.0.3.2"`-orange.svg?style=flat-square)](commits/master) +[![packageversion](https://img.shields.io/badge/Package%20version-`r "1.0.4"`-orange.svg?style=flat-square)](commits/master) [![thanks-md](https://img.shields.io/badge/THANKS-md-ff69b4.svg)](THANKS.md) diff --git a/README.md b/README.md index 785a778..56acf23 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![R-CMD-check](https://github.com/HawkinDynamics/hawkinR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/HawkinDynamics/hawkinR/actions/workflows/R-CMD-check.yaml) -[![Last-changedate](https://img.shields.io/badge/last%20change-2024--02--01-yellowgreen.svg)](/commits/master) +[![Last-changedate](https://img.shields.io/badge/last%20change-2024--02--15-yellowgreen.svg)](/commits/master) [![license](https://img.shields.io/badge/license-MIT%20+%20file%20LICENSE-lightgrey.svg)](https://choosealicense.com/) [![minimal R version](https://img.shields.io/badge/R%3E%3D-3.5.0-6666ff.svg)](https://cran.r-project.org/) @@ -16,7 +16,7 @@ version](https://img.shields.io/badge/R%3E%3D-3.5.0-6666ff.svg)](https://cran.r- state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) -[![packageversion](https://img.shields.io/badge/Package%20version-1.0.3.2-orange.svg?style=flat-square)](commits/master) +[![packageversion](https://img.shields.io/badge/Package%20version-1.0.4-orange.svg?style=flat-square)](commits/master) [![thanks-md](https://img.shields.io/badge/THANKS-md-ff69b4.svg)](THANKS.md) diff --git a/man/get_tests.Rd b/man/get_tests.Rd index 78227fc..ad15705 100644 --- a/man/get_tests.Rd +++ b/man/get_tests.Rd @@ -35,11 +35,17 @@ Response will be a data frame containing the trials within the time range (if sp \strong{segment} \emph{chr} Description of the test type and trial number of the session (testType:trialNo) -\strong{testType_id} \emph{chr} Id of the test type of the trial +\strong{test_type_id} \emph{chr} Id of the test type of the trial -\strong{testType_name} \emph{chr} Name of the test type of the trial +\strong{test_type_name} \emph{chr} Name of the test type of the trial -\strong{testType_canonicalId} \emph{chr} Canonical Id of the test type of the trial +\strong{test_type_canonicalId} \emph{chr} Canonical Id of the test type of the trial + +\strong{test_type_tag_ids} \emph{chr} String of Ids associated with tags used during the test trial + +\strong{test_type_tag_names} \emph{chr} String of names of tags used during the test trial + +\strong{test_type_tag_desc} \emph{chr} String of descriptions of tags used during the test trial \strong{athlete_id} \emph{chr} Unique Id of the athlete diff --git a/man/get_tests_ath.Rd b/man/get_tests_ath.Rd index 7012d44..34a41b9 100644 --- a/man/get_tests_ath.Rd +++ b/man/get_tests_ath.Rd @@ -44,6 +44,12 @@ range (if specified). \strong{testType.canonicalId} \emph{chr} Canonical Id of the test type of the trial +\strong{test_type_tag_ids} \emph{chr} String of Ids associated with tags used during the test trial + +\strong{test_type_tag_names} \emph{chr} String of names of tags used during the test trial + +\strong{test_type_tag_desc} \emph{chr} String of descriptions of tags used during the test trial + \strong{athlete.id} \emph{chr} Unique Id of the athlete \strong{athlete.name} \emph{chr} Athlete given name diff --git a/man/get_tests_group.Rd b/man/get_tests_group.Rd index 44d7464..1f9b1d6 100644 --- a/man/get_tests_group.Rd +++ b/man/get_tests_group.Rd @@ -45,6 +45,12 @@ range (if specified). \strong{testType.canonicalId} \emph{chr} Canonical Id of the test type of the trial +\strong{test_type_tag_ids} \emph{chr} String of Ids associated with tags used during the test trial + +\strong{test_type_tag_names} \emph{chr} String of names of tags used during the test trial + +\strong{test_type_tag_desc} \emph{chr} String of descriptions of tags used during the test trial + \strong{athlete.id} \emph{chr} Unique Id of the athlete \strong{athlete.name} \emph{chr} Athlete given name diff --git a/man/get_tests_team.Rd b/man/get_tests_team.Rd index faf2b14..7614072 100644 --- a/man/get_tests_team.Rd +++ b/man/get_tests_team.Rd @@ -45,6 +45,12 @@ range (if specified). \strong{testType.canonicalId} \emph{chr} Canonical Id of the test type of the trial +\strong{test_type_tag_ids} \emph{chr} String of Ids associated with tags used during the test trial + +\strong{test_type_tag_names} \emph{chr} String of names of tags used during the test trial + +\strong{test_type_tag_desc} \emph{chr} String of descriptions of tags used during the test trial + \strong{athlete.id} \emph{chr} Unique Id of the athlete \strong{athlete.name} \emph{chr} Athlete given name diff --git a/man/get_tests_type.Rd b/man/get_tests_type.Rd index 97ade06..08f4b7e 100644 --- a/man/get_tests_type.Rd +++ b/man/get_tests_type.Rd @@ -43,6 +43,12 @@ Response will be a data frame containing the trials of the specified type and wi \strong{testType.canonicalId} \emph{chr} Canonical Id of the test type of the trial +\strong{test_type_tag_ids} \emph{chr} String of Ids associated with tags used during the test trial + +\strong{test_type_tag_names} \emph{chr} String of names of tags used during the test trial + +\strong{test_type_tag_desc} \emph{chr} String of descriptions of tags used during the test trial + \strong{athlete.id} \emph{chr} Unique Id of the athlete \strong{athlete.name} \emph{chr} Athlete given name