Skip to content

Commit

Permalink
feat: bodyweight data
Browse files Browse the repository at this point in the history
  • Loading branch information
m-muecke committed Dec 4, 2024
1 parent 5e9c3f9 commit bd2ef2b
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
11 changes: 11 additions & 0 deletions R/bibentries.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ bibentries <- c(
pages = "e3298",
year = "2017",
publisher = "PeerJ Inc."
),
ebert2018open = bibentry("proceedings",
author = "Ebert, Andre and Marouane, Chadly and Ungnadner, Christian and Klein, Adrian",
editor = "Perego, Paolo and Rahmani, Amir M. and TaheriNejad, Nima",
title = "An Open, Labeled Dataset for Analysis and Assessment of Human Motion",
booktitle = "Wireless Mobile Communication and Healthcare",
year = "2018",
publisher = "Springer International Publishing",
address = "Cham",
pages = "99--106",
isbn = "978-3-319-98551-0"
)
)
# nolint end
23 changes: 23 additions & 0 deletions R/bodyweight.R
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"
64 changes: 64 additions & 0 deletions data-raw/bodyweight.R
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 added data/bodyweight.rda
Binary file not shown.
38 changes: 38 additions & 0 deletions man/bodyweight.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd2ef2b

Please sign in to comment.