Skip to content

Commit 2bfa418

Browse files
authored
Merge pull request #47 from PhysicalActivityOpenTools/issue46_embeddingClassifyFunction
minor modifications to facilitate embedding of the function in GGIR
2 parents 25fa760 + eded0da commit 2bfa418

File tree

7 files changed

+46
-9
lines changed

7 files changed

+46
-9
lines changed

R/classify.R

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#' @param ID ID for this recording
1919
#' @param starttime Start time for the recording as extracted from \link{ReadAndCalibrate}
2020
#' @param data Raw data as read by \link{ReadAndCalibrate}
21+
#' @param parameters List with the definition of the parameters of the function.
2122
#'
2223
#' @return Function does not return anything, it only generates the reports and
2324
#' visualizations in the \code{output_directory}.
@@ -29,11 +30,23 @@
2930
#'
3031
#' @author Matthew N. Ahmadi <[email protected]>
3132
#' @author Jairo H. Migueles <[email protected]>
32-
classify = function(data = NULL, sf = NULL,
33+
classify = function(data = NULL, parameters = NULL, sf = NULL,
3334
classifier = NULL, infoClassifier = NULL,
3435
ID = NULL, starttime = NULL) {
36+
# -------------------------------------------------------------------------
3537
# Original code provided by Matthew N. Ahmadi
3638
# Jairo H. Migueles cleaned the code and isolated the classify function here
39+
# -------------------------------------------------------------------------
40+
# get parameters
41+
if (!is.null(parameters)) {
42+
if (!"infoClassifier" %in% names(parameters)) {
43+
parameters$infoClassifier = GetInfoClassifier(parameters$classifier)
44+
}
45+
sf = parameters$sf
46+
classifier = parameters$classifier
47+
infoClassifier = parameters$infoClassifier
48+
epoch = parameters$infoClassifier
49+
}
3750
epoch = infoClassifier$epoch
3851
# -------------------------------------------------------------------------
3952
# 1 - EXTRACT FEATURES
@@ -54,9 +67,12 @@ classify = function(data = NULL, sf = NULL,
5467
ts = as.data.frame(cbind(ts, laglead))
5568
}
5669
# Timestamp and ID
57-
timestamp = deriveTimestamps(from = starttime, length = nrow(ts), epoch = epoch)
58-
subject = rep(ID, nrow(ts))
59-
ts = as.data.frame(cbind(subject, timestamp, ts))
70+
if (!is.null(starttime)) {
71+
timestamp = deriveTimestamps(from = starttime, length = nrow(ts), epoch = epoch)
72+
if (!is.null(ID)) subject = rep(ID, nrow(ts)) else subject = NA
73+
ts = as.data.frame(cbind(subject, timestamp, ts))
74+
}
75+
# round numeric columns
6076
numeric_columns = sapply(ts, mode) == 'numeric'
6177
ts[numeric_columns] = round(ts[numeric_columns], 3)
6278
ts = do.call(data.frame,lapply(ts, function(x) replace(x, is.infinite(x), NA)))

man/classify.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/classifySleep.Rd

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/detectNonWear.Rd

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/featuresTrost2017.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/featuresTrost2018.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/inbed.Rd

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)