Skip to content

Commit

Permalink
Check whether custom timestamps are available in `split.data.time.bas…
Browse files Browse the repository at this point in the history
…ed.by.timestamps`

If no custom event timestamps are available in the ProjectData object, an
error is thrown in `split.data.time.based.by.timestamps`, to avoid passing
`NULL` to the called splitting functions.

Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
  • Loading branch information
bockthom committed Apr 12, 2024
1 parent 6536a4c commit 6305adc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions util-split.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
## Copyright 2020 by Christian Hechtl <hechtl@cs.uni-saarland.de>
## Copyright 2017 by Felix Prasse <prassefe@fim.uni-passau.de>
## Copyright 2017-2018 by Thomas Bock <bockthom@fim.uni-passau.de>
## Copyright 2020 by Thomas Bock <bockthom@cs.uni-saarland.de>
## Copyright 2020, 2024 by Thomas Bock <bockthom@cs.uni-saarland.de>
## Copyright 2021 by Niklas Schneider <s8nlschn@stud.uni-saarland.de>
## Copyright 2021 by Johannes Hostert <s8johost@stud.uni-saarland.de>
## Copyright 2022 by Jonathan Baumann <joba00002@stud.uni-saarland.de>
Expand Down Expand Up @@ -135,7 +135,7 @@ split.data.by.bins = function(project.data, activity.amount, bins, split.basis =
#' and the last range ends with the last timestamp.
#'
#' If timestamps are not provided, the custom event timestamps in \code{project.data} are
#' used instead.
#' used instead. If no custom event timestamps are available in \code{project.data}, an error is thrown.
#'
#' @param project.data the *Data object from which the data is retrieved
#' @param bins a vector of timestamps [default: NULL]
Expand All @@ -148,6 +148,12 @@ split.data.time.based.by.timestamps = function(project.data, bins = NULL, projec

if (is.null(bins)) { # bins were not provided, use custom timestamps from project
bins = unlist(project.data$get.custom.event.timestamps())

if (is.null(bins)) { # stop if no custom timestamps are available
logging::logerror("There are no custom timestamps available for splitting (configured file: %s).",
project.data$get.project.conf.entry("custom.event.timestamps.file"))
stop("Stopping due to missing data.")
}
}

return (split.data.time.based(project.data, bins = bins, project.conf.new));
Expand Down

0 comments on commit 6305adc

Please sign in to comment.