-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from itismeghasyam/develop
Updated Tests, Tapping features and Vignettes
- Loading branch information
Showing
19 changed files
with
371 additions
and
212 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
# email: [email protected] | ||
#################################################### | ||
|
||
######################## *** NOTE *** ######################## | ||
## Still have to write tests for | ||
# (throws error, handle funs = NA, models = NA case) get_heartrate | ||
######################## *** NOTE *** ######################## | ||
|
||
### Require mHealthTools | ||
require(mhealthtools) | ||
|
||
|
@@ -23,7 +28,7 @@ library(purrr) | |
|
||
### Load data file | ||
data("heartrate_data") | ||
datHR <- heartrate_data | ||
datHR <- mhealthtools::heartrate_data | ||
|
||
### Individual test functions | ||
context('Extract Heart rate') | ||
|
@@ -37,11 +42,7 @@ test_that('Function to extract heart rate per channel(R,G,B)',{ | |
expect_is(mhealthtools:::get_heartrate(dat = datHR), 'list') # Check if output is in correct format | ||
|
||
tempDat <- copy(datHR) | ||
tempDat <- tempDat %>% dplyr::rename('t' = 'timestamp') # Changed the column name of timestamp to t | ||
expect_equal(mhealthtools:::get_heartrate(dat = tempDat), testTibble) # Error if timestamp column is missing | ||
|
||
tempDat <- copy(datHR) | ||
tempDat$timestamp <- rep(1, length(datHR$timestamp)) | ||
tempDat$t <- rep(1, length(datHR$t)) | ||
expect_equal(mhealthtools:::get_heartrate(dat = tempDat), testTibble) # Error if sampling rate cannot be calculated from timestamp | ||
|
||
tempDat <- copy(datHR) | ||
|
@@ -75,4 +76,4 @@ test_that('Bandpass filter the input signal',{ | |
|
||
expect_is(mhealthtools:::getfilteredsignal(x = timeSeries,samplingRate = 60), 'numeric') # Check if output is in correct format | ||
|
||
}) | ||
}) |
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 |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
# email: [email protected] | ||
#################################################### | ||
|
||
######################## *** NOTE *** ######################## | ||
## Still have to write tests for | ||
# (throws error for custom models) get_kinetic_tremor_features | ||
######################## *** NOTE *** ######################## | ||
|
||
# When I input gravity sensor data into the function get_kinetic_tremor_features, the whole error column is like | ||
# 'Phone rotated within window' for all the windows. Is this normal, or is this happening because of the test data (I don't think so) | ||
# This needs to be checked. | ||
|
@@ -28,7 +33,7 @@ library(purrr) | |
|
||
### Load data file | ||
data("sensor_data") | ||
dat <- sensor_data | ||
dat <- mhealthtools::sensor_data | ||
|
||
### flatten data to the format needed for mHealthTools | ||
flatten_data <- function(dat, metric) { | ||
|
@@ -50,11 +55,28 @@ test_that('Get accelerometer, gyroscope features',{ | |
# actual function in get_kinetic_tremor_features.R: get_kinetic_tremor_features | ||
testTibble <- dplyr::tibble(Window = NA, error = NA) | ||
|
||
expect_is(mhealthtools::get_kinetic_tremor_features(accelerometer_data = datAccel, gyroscope_data = datGyro), 'data.frame') | ||
expect_is(mhealthtools::get_kinetic_tremor_features(accelerometer_data = datAccel, gyroscope_data = datGyro), 'list') | ||
# Give both Accelerometer and Gyroscope data and expect a dataframe, with rest of the inputs being default | ||
expect_is(mhealthtools::get_kinetic_tremor_features(accelerometer_data = datAccel, gyroscope_data = datGyro, gravity_data = datGravity), 'data.frame') | ||
expect_is(mhealthtools::get_kinetic_tremor_features(accelerometer_data = datAccel, gyroscope_data = datGyro, gravity_data = datGravity), 'list') | ||
# Similar test to previous one except also included gravity data | ||
|
||
expect_is(mhealthtools::get_kinetic_tremor_features(accelerometer_data = datAccel, gyroscope_data = datGyro, funs = list(mean)), 'list') | ||
# Custum functions should also work (using base mean as the list of functions, this works even if mean does not give a | ||
# dataframe of features as output??) | ||
|
||
custom_model <- function(dat){ | ||
avec <- dat['jerk']*dat['velocity'] | ||
|
||
avec <- avec %>% | ||
unlist() %>% | ||
as.numeric() | ||
|
||
return(data.frame(f1 = mean(avec, na.rm = T))) | ||
} | ||
expect_is(mhealthtools::get_kinetic_tremor_features(accelerometer_data = datAccel, gyroscope_data = datGyro, models = custom_model), 'list') | ||
# Custum models should also work, the output format of custom models is not defined specifically like the output of | ||
# each function in the list of funs | ||
|
||
testTibble$error <- 'Malformed accelerometer data' | ||
expect_equal(mhealthtools:::get_kinetic_tremor_features(accelerometer_data = NA, gyroscope_data = datGyro), testTibble) | ||
# Give error tibble if accelerometer data has any NAs | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
# email: [email protected] | ||
#################################################### | ||
|
||
######################## *** NOTE *** ######################## | ||
## Still have to write tests for | ||
# (throws error for custom models) get_rest_features | ||
######################## *** NOTE *** ######################## | ||
|
||
# When I input gravity sensor data into the function get_rest_features, the whole error column is like | ||
# 'Phone rotated within window' for all the windows. Is this normal, or is this happening because of the test data (I don't think so) | ||
# This needs to be checked. | ||
|
@@ -28,7 +33,7 @@ library(purrr) | |
|
||
### Load data file | ||
data("sensor_data") | ||
dat <- sensor_data | ||
dat <- mhealthtools::sensor_data | ||
|
||
### flatten data to the format needed for mHealthTools | ||
flatten_data <- function(dat, metric) { | ||
|
@@ -50,11 +55,29 @@ test_that('Get accelerometer, gyroscope features',{ | |
# actual function in get_rest_features.R: get_rest_features | ||
testTibble <- dplyr::tibble(Window = NA, error = NA) | ||
|
||
expect_is(mhealthtools::get_rest_features(accelerometer_data = datAccel, gyroscope_data = datGyro), 'data.frame') | ||
expect_is(mhealthtools::get_rest_features(accelerometer_data = datAccel, gyroscope_data = datGyro), 'list') | ||
# Give both Accelerometer and Gyroscope data and expect a dataframe, with rest of the inputs being default | ||
expect_is(mhealthtools::get_rest_features(accelerometer_data = datAccel, gyroscope_data = datGyro, gravity_data = datGravity), 'data.frame') | ||
expect_is(mhealthtools::get_rest_features(accelerometer_data = datAccel, gyroscope_data = datGyro, gravity_data = datGravity), 'list') | ||
# Similar test to previous one except also included gravity data | ||
|
||
expect_is(mhealthtools::get_rest_features(accelerometer_data = datAccel, gyroscope_data = datGyro, funs = list(mean)), 'list') | ||
# Custum functions should also work (using base mean as the list of functions, this works even if mean does not give a | ||
# dataframe of features as output??) | ||
|
||
custom_model <- function(dat){ | ||
avec <- dat['jerk']*dat['velocity'] | ||
|
||
avec <- avec %>% | ||
unlist() %>% | ||
as.numeric() | ||
|
||
return(data.frame(f1 = mean(avec, na.rm = T))) | ||
} | ||
expect_is(mhealthtools::get_rest_features(accelerometer_data = datAccel, gyroscope_data = datGyro, models = custom_model), 'list') | ||
# Custum models should also work, the output format of custom models is not defined specifically like the output of | ||
# each function in the list of funs | ||
|
||
|
||
testTibble$error <- 'Malformed accelerometer data' | ||
expect_equal(mhealthtools:::get_rest_features(accelerometer_data = NA, gyroscope_data = datGyro), testTibble) | ||
# Give error tibble if accelerometer data has any NAs | ||
|
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
Oops, something went wrong.