-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mergeFitbitData and allign with mergePHBdata #68
- Loading branch information
1 parent
3eab460
commit 671a663
Showing
10 changed files
with
140 additions
and
60 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,22 @@ | ||
mergeFitbitData = function(filenames = NULL, desiredtz = "", configtz = NULL) { | ||
if (length(filenames) < 2) { | ||
stop("Provide at least two filenames") | ||
} | ||
cnt = 1 | ||
while (cnt <= length(filenames)) { | ||
D = readFitbit(filename = filenames[cnt], desiredtz = desiredtz, configtz = configtz) | ||
if (cnt == 1) { | ||
data = D | ||
} else { | ||
if (length(intersect(x = data$dateTime, D$dateTime)) == 0) { | ||
warning(paste0("Time series do not intersect for files ", | ||
basename(filenames[cnt]), " and ", basename(filenames[cnt - 1])), | ||
call. = FALSE) | ||
} | ||
|
||
data = merge(data, D, by = "dateTime", all = TRUE) | ||
} | ||
cnt = cnt + 1 | ||
} | ||
return(data) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,142 +1,142 @@ | ||
[{ | ||
"dateTime" : "06/23/95 00:00:00", | ||
"dateTime" : "06/24/95 16:00:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:01:00", | ||
"dateTime" : "06/24/95 16:01:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:02:00", | ||
"dateTime" : "06/24/95 16:02:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:03:00", | ||
"dateTime" : "06/24/95 16:03:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:04:00", | ||
"dateTime" : "06/24/95 16:04:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:05:00", | ||
"dateTime" : "06/24/95 16:05:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:06:00", | ||
"dateTime" : "06/24/95 16:06:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:07:00", | ||
"dateTime" : "06/24/95 16:07:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:08:00", | ||
"dateTime" : "06/24/95 16:08:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:09:00", | ||
"dateTime" : "06/24/95 16:09:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:10:00", | ||
"dateTime" : "06/24/95 16:10:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:11:00", | ||
"dateTime" : "06/24/95 16:11:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:12:00", | ||
"dateTime" : "06/24/95 16:12:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:13:00", | ||
"dateTime" : "06/24/95 16:13:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:14:00", | ||
"dateTime" : "06/24/95 16:14:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:15:00", | ||
"dateTime" : "06/24/95 16:15:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:16:00", | ||
"dateTime" : "06/24/95 16:16:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:17:00", | ||
"dateTime" : "06/24/95 16:17:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:18:00", | ||
"dateTime" : "06/24/95 16:18:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:19:00", | ||
"dateTime" : "06/24/95 16:19:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:20:00", | ||
"dateTime" : "06/24/95 16:20:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:21:00", | ||
"dateTime" : "06/24/95 16:21:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:22:00", | ||
"dateTime" : "06/24/95 16:22:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:23:00", | ||
"dateTime" : "06/24/95 16:23:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:24:00", | ||
"dateTime" : "06/24/95 16:24:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:25:00", | ||
"dateTime" : "06/24/95 16:25:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:26:00", | ||
"dateTime" : "06/24/95 16:26:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:27:00", | ||
"dateTime" : "06/24/95 16:27:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:28:00", | ||
"dateTime" : "06/24/95 16:28:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:29:00", | ||
"dateTime" : "06/24/95 16:29:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:30:00", | ||
"dateTime" : "06/24/95 16:30:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:31:00", | ||
"dateTime" : "06/24/95 16:31:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:32:00", | ||
"dateTime" : "06/24/95 16:32:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:33:00", | ||
"dateTime" : "06/24/95 16:33:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:34:00", | ||
"dateTime" : "06/24/95 16:34:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:35:00", | ||
"dateTime" : "06/24/95 16:35:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:36:00", | ||
"dateTime" : "06/24/95 16:36:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:37:00", | ||
"dateTime" : "06/24/95 16:37:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:38:00", | ||
"dateTime" : "06/24/95 16:38:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:39:00", | ||
"dateTime" : "06/24/95 16:39:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:40:00", | ||
"dateTime" : "06/24/95 16:40:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:41:00", | ||
"dateTime" : "06/24/95 16:41:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:42:00", | ||
"dateTime" : "06/24/95 16:42:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:43:00", | ||
"dateTime" : "06/24/95 16:43:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:44:00", | ||
"dateTime" : "06/24/95 16:44:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:45:00", | ||
"dateTime" : "06/24/95 16:45:00", | ||
"value" : "1.48" | ||
},{ | ||
"dateTime" : "06/23/95 00:46:00", | ||
"dateTime" : "06/24/95 16:46:00", | ||
"value" : "1.48" | ||
}] |
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,35 @@ | ||
\name{mergeFitbitData} | ||
\alias{mergeFitbitData} | ||
\title{ | ||
Merge Fitbit json files into one data.frame | ||
} | ||
\description{ | ||
Read and merge Fitbit json files into one data.frame, and | ||
give warning if time series do not intersect. | ||
} | ||
\usage{ | ||
mergeFitbitData(filenames = NULL, | ||
desiredtz = "", configtz = NULL) | ||
} | ||
\arguments{ | ||
\item{filenames}{ | ||
Character vector, specifying the filenames (at least two) to be merged. | ||
} | ||
\item{desiredtz}{ | ||
Character, timezone name where the accelerometer was worn. Timezone names are | ||
expected to be the timezone database names, e.g. Europe/London. See also: | ||
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | ||
} | ||
\item{configtz}{ | ||
Character, timezone name where the accelerometer was configured. Leave NULL | ||
if equal to desiredtz. Timezones name are expected to be the timezone database | ||
names, e.g. Europe/London. See also: | ||
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | ||
} | ||
} | ||
\value{ | ||
Merged data from the two or more files. | ||
} | ||
\author{ | ||
Vincent T van Hees <v.vanhees@accelting.com> | ||
} |
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,22 @@ | ||
library(GGIRread) | ||
context("merge PHB files") | ||
test_that("merging of PHB files goes correctly", { | ||
file1 = system.file("testfiles/steps-1995-06-23_Fitbit.json", package = "GGIRread") | ||
file2 = system.file("testfiles/calories-1995-06-23_Fitbit.json", package = "GGIRread") | ||
file3 = system.file("testfiles/sleep-1995-06-23_Fitbit.json", package = "GGIRread") | ||
|
||
# apply function to merge the files | ||
D = mergeFitbitData(filenames = c(file1, file2), | ||
desiredtz = "Europe/Amsterdam") | ||
expect_equal(nrow(D), 47) | ||
expect_equal(ncol(D), 3) | ||
expect_equal(sum(D$steps, na.rm = TRUE), 607) | ||
expect_equal(sum(D$calories, na.rm = TRUE), 69.56) | ||
expect_equal(format(D$dateTime[1]), "1995-06-24 16:00:00") | ||
|
||
# apply function to merge the files | ||
expect_warning(mergeFitbitData(filenames = c(file1, file2, file3), | ||
desiredtz = "Europe/Amsterdam"), | ||
regexp = "Time series*") | ||
}) | ||
|
3 changes: 1 addition & 2 deletions
3
tests/testthat/test_mergePHBfilePairs.R → tests/testthat/test_mergePHBdata.R
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