-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' Bicycle Crunch data | ||
#' | ||
#' @description | ||
#' Sensor-based measurements and quality ratings of athletes performing the | ||
#' Bicycle Crunch exercise, recorded across multiple sets and repetitions. | ||
#' | ||
#' | ||
#' @source <https://github.com/andrebert/body-weight-exercises> | ||
#' @references `r format_bib("ebert2018open")` | ||
#' @format A tibble with 20,760 rows and 8 variables: | ||
#' \describe{ | ||
#' \item{id}{ID of the athlete.} | ||
#' \item{set}{The set number of the exercise.} | ||
#' \item{loc}{Location of body extremity.} | ||
#' \item{sens}{Indicator for acceleration (acc) or rotation (rot).} | ||
#' \item{dim}{Dimension of rotation.} | ||
#' \item{rep}{The number of repetitions.} | ||
#' \item{rating}{Quality of their exercise sets within a range of 1 to 5.} | ||
#' \item{activity}{} | ||
#' } | ||
#' @examples | ||
#' bodyweight | ||
"bodyweight" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
library(dplyr) | ||
library(stringr) | ||
|
||
# source: https://github.com/andrebert/body-weight-exercises | ||
path <- "~/github/body-weight-exercises" | ||
files <- list.files(path, recursive = TRUE) | ||
files <- files[tools::file_ext(files) != "zip"] | ||
seg_files <- str_subset(files, "txt|INFO$", negate = TRUE) | ||
info_files <- str_subset(files, "INFO$") | ||
|
||
ratings <- lapply(file.path(path, info_files), function(file) { | ||
readr::read_delim(file, | ||
delim = ":", col_names = c("name", "value"), show_col_types = FALSE | ||
) |> | ||
filter(name == "Rating") |> | ||
pull(value) |> | ||
str_split("-", simplify = TRUE) |> | ||
as.numeric() | ||
}) | ||
names(ratings) <- str_remove(info_files, "/INFO") | ||
|
||
bodyweight <- seg_files |> | ||
str_split("/|-", simplify = TRUE) |> | ||
as_tibble(.name_repair = "minimal") |> | ||
setNames(c("id", "ex", "set", "loc", "sens", "dim", "rep")) |> | ||
filter(ex == "bi") |> | ||
mutate(id = as.integer(id), rep = as.integer(rep)) | ||
|
||
bw_files <- str_subset(seg_files, "bi") | ||
bi_files <- file.path(path, bw_files) | ||
|
||
bi <- lapply(bi_files, function(file) { | ||
readr::read_table(file, col_names = FALSE, show_col_types = FALSE) |> | ||
t() |> | ||
as_tibble(.name_repair = "minimal") |> | ||
setNames(c("value", "arg")) |> | ||
relocate(arg, value) |> | ||
distinct(arg, .keep_all = TRUE) | ||
}) |> | ||
tf::tfd() | ||
|
||
bi_ratings <- vapply(seq_len(nrow(bodyweight)), function(i) { | ||
loc <- str_c(bodyweight[i, 1:3], collapse = "/") | ||
rep <- bodyweight[i, "rep", drop = TRUE] | ||
if (is.na(ratings[loc])) NA else ratings[[loc]][rep] | ||
}, numeric(1)) | ||
|
||
bodyweight <- bodyweight |> | ||
mutate( | ||
loc = factor(loc, | ||
levels = c("TL", "TR", "BL", "BR", "CH"), | ||
labels = c("left arm", "right arm", "left leg", "right leg", "chest") | ||
), | ||
sens = factor(sens, | ||
levels = c("acc", "rot"), labels = c("acceleration", "rotation") | ||
), | ||
dim = as.factor(dim), | ||
set = factor(set, levels = c("set1", "set2", "set3"), ordered = TRUE), | ||
rating = bi_ratings, | ||
activity = bi | ||
) |> | ||
select(-ex) | ||
|
||
usethis::use_data(bodyweight, overwrite = TRUE, compress = "xz") |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.