diff --git a/R/mergePHBfilePairs.R b/R/mergePHBfilePairs.R index 6281b8f..2333217 100644 --- a/R/mergePHBfilePairs.R +++ b/R/mergePHBfilePairs.R @@ -1,57 +1,40 @@ -mergePHBfilePairs = function(inputPath = ".", outputPath = ".", +mergePHBfilePairs = function(filenames = NULL, timeformat = "%m/%d/%Y %H:%M:%S", desiredtz = "", configtz = NULL, timeformatName = "timeformat") { # merges Philips Health Band xlsx files per participant # as there can be multiple files per participant. - fnames = dir(inputPath, recursive = FALSE, full.names = TRUE, pattern = "[.]xlsx") - fileOverview = data.frame(filename = fnames) - extractID = function(x) { - x = basename(x) - x = gsub(pattern = "sleep_wake", replacement = "sleepwake", x = tolower(x)) - ID = unlist(strsplit(x, "_"))[2] - return(ID) + if (length(filenames) != 2) { + stop("Provide two filenames") } - fileOverview$ID = unlist(lapply(fileOverview$filename, FUN = extractID)) - uids = unique(fileOverview$ID) - for (uid in uids) { - filesForThisPerson = fileOverview$filename[which(fileOverview$ID == uid)] - # Identify both file - file1 = grep(pattern = "datalist", x = filesForThisPerson, ignore.case = TRUE) - file2 = grep(pattern = "sleep_wake", x = filesForThisPerson, ignore.case = TRUE) - if (length(file1) == 0 && length(file2) == 0) { - next - } - # Data - deviceSN = NULL + # Identify both file + file1 = grep(pattern = "datalist", x = filenames, ignore.case = TRUE) + file2 = grep(pattern = "sleep_wake", x = filenames, ignore.case = TRUE) + + # Datalist file (with all variables except sleep/wake scores) + deviceSN = NULL + if (length(file1) > 0) { + data1 = readPHBCount(filename = filenames[file1], timeformat = timeformat, + desiredtz = desiredtz, configtz = configtz, + timeformatName = timeformatName) + deviceSN = data1$deviceSN + } + # Sleep wake scores file + if (length(file2) > 0) { + data2 = readPHBCount(filename = filenames[file2], timeformat = timeformat, + desiredtz = desiredtz, configtz = configtz, + timeformatName = timeformatName) + } + if (length(file1) > 0 && length(file2) > 0) { + data2$data = data2$data[, which(colnames(data2$data) != "sleepEventMarker")] + data = merge(data1$data, data2$data, by = "timestamp") + } else { if (length(file1) > 0) { - data1 = readPHBCount(filename = filesForThisPerson[file1], timeformat = timeformat, - desiredtz = desiredtz, configtz = configtz, - timeformatName = timeformatName) - deviceSN = data1$deviceSN - } - # Sleep wake scores - if (length(file2) > 0) { - data2 = readPHBCount(filename = filesForThisPerson[file2], timeformat = timeformat, - desiredtz = desiredtz, configtz = configtz, - timeformatName = timeformatName) - } - if (length(file1) > 0 && length(file2) > 0) { - data2$data = data2$data[, which(colnames(data2$data) != "sleepEventMarker")] - data = merge(data1$data, data2$data, by = "timestamp") + data = data1$data } else { - if (length(file1) > 0) { - data = data1$data - } else { - data = data2$data - } + data = data2$data } - colnames(data)[grep(pattern = "timestamp", x = colnames(data))] = "timestamp" - newName = gsub(pattern = "Sleep_Wake", replacement = "def", x = basename(filesForThisPerson[file2]), ignore.case = TRUE) - newName = paste0(unlist(strsplit(newName, "[.]")) , collapse = paste0("_", deviceSN, ".")) - newName = gsub(pattern = "xlsx", replacement = "csv", x = newName) - outputfile = paste0(outputPath, "/", newName) - write.csv(x = data, file = outputfile, row.names = FALSE) } + invisible(list(data = data, deviceSN = deviceSN)) } \ No newline at end of file diff --git a/R/readPHBCount.R b/R/readPHBCount.R index 5a1eff8..b25b0a8 100644 --- a/R/readPHBCount.R +++ b/R/readPHBCount.R @@ -1,12 +1,13 @@ readPHBCount = function(filename = NULL, timeformat = "%m/%d/%Y %H:%M:%S", desiredtz = "", configtz = NULL, timeformatName = "timeformat") { + if (length(configtz) == 0) configtz = desiredtz deviceSN = NULL if (length(grep(pattern = "datalist", x = filename, ignore.case = TRUE)) > 0) { data = as.data.frame(readxl::read_excel(path = filename, - col_types = "text", skip = 8), - row.names = FALSE) + col_types = "text", skip = 8), + row.names = FALSE) header = as.data.frame(readxl::read_excel(path = filename, col_types = "text", n_max = 8, .name_repair = "unique_quiet"), @@ -15,11 +16,17 @@ readPHBCount = function(filename = NULL, timeformat = "%m/%d/%Y %H:%M:%S", if (length(SNlocation) > 0) { deviceSN = unlist(strsplit(header[grep(pattern = "deviceSN", x = header)], " ")) deviceSN = deviceSN[length(deviceSN)] - } + } colnames(data)[grep(pattern = "counts", x = colnames(data), ignore.case = TRUE)] = "counts" colnames(data)[grep(pattern = "offWrist", x = colnames(data), ignore.case = TRUE)] = "nonwear" + for (varname in c("counts", "steps", "nonwear")) { + if (varname %in% colnames(data) == FALSE) { + stop(paste0("Expected column ", varname, " not found in file ", filename), call. = TRUE) + } + } data$counts = as.numeric(data$counts) data$nonwear = as.numeric(data$counts) + data$steps = as.numeric(data$steps) } else { data = as.data.frame(readxl::read_excel(path = filename, col_types = "text", skip = 8), row.names = FALSE) colnames(data)[grep(pattern = "sleepWake", x = colnames(data), ignore.case = TRUE)] = "sleep" @@ -37,7 +44,7 @@ readPHBCount = function(filename = NULL, timeformat = "%m/%d/%Y %H:%M:%S", # Establish starttime in the correct timezone if (configtz != desiredtz) { data$timestamp = as.POSIXct(x = as.numeric(data$timestamp), tz = desiredtz, - origin = "1970-01-01") + origin = "1970-01-01") } invisible(list(data = data, deviceSN = deviceSN)) } \ No newline at end of file diff --git a/inst/testfiles/def_AH1234567890_PhilipsHealthBand_000100621938.csv b/inst/testfiles/def_AH1234567890_PhilipsHealthBand_000100621938.csv deleted file mode 100644 index b464778..0000000 --- a/inst/testfiles/def_AH1234567890_PhilipsHealthBand_000100621938.csv +++ /dev/null @@ -1,247 +0,0 @@ -"timestamp","counts","heartRate","respirationRate","totalEnergyExpenditure","activeEnergyExpenditure","steps","nonwear","runDuration","walkDuration","activeMinutes","restingHeartRate","heartRateRecovery","cardioFitnessIndex","vo2Max","batteryDischarge","sleepEventMarker","missingData","sleep" -"11-05-2022 01:10:00","475","53","17","149.6173","0.0764","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:11:00","305","52","21","151.0414","0.1011","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:12:00","608","52","17","152.5025","0.1344","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:13:00","160","50","18","153.8994","0.0767","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:14:00","735","51","20","155.3830","0.1547","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:15:00","1345","52","19","156.8386","0.1294","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:16:00","144","55","17","158.5574","0.3664","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:17:00","243","54","19","159.9361","0.0603","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:18:00","171","53","17","161.3136","0.0592","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:19:00","63","54","17","162.6497","0.0219","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:20:00","761","55","18","164.0025","0.0369","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:21:00","1330","55","NaN","165.7321","0.3761","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:22:00","144","55","18","167.1846","0.1267","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:23:00","1669","52","17","168.7497","0.2281","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:24:00","356","52","18","170.2722","0.1897","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:25:00","122","51","19","171.6327","0.0439","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:26:00","121","50","19","172.9815","0.0333","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:27:00","729","51","19","174.4491","0.1403","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:28:00","1027","51","NaN","176.0438","0.2547","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:29:00","116","49","19","177.4303","0.0672","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:30:00","101","47","16","178.7790","0.0333","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:31:00","484","50","7","180.2040","0.1019","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:32:00","114","50","15","181.5673","0.0464","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:33:00","113","49","16","182.9161","0.0333","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:34:00","111","48","16","184.2648","0.0333","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:35:00","798","49","17","185.7552","0.1608","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 01:36:00","70","49","11","187.1309","0.0575","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:37:00","54","47","15","188.4611","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:38:00","54","48","15","189.7914","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:39:00","54","49","12","191.1216","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:40:00","58","48","8","192.4519","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:41:00","55","48","10","193.7821","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:42:00","56","49","13","195.1124","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:43:00","52","49","16","196.4426","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:44:00","51","48","11","197.7728","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:45:00","51","49","11","199.1031","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:46:00","50","47","15","200.4333","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:47:00","52","48","11","201.7636","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:48:00","80","47","13","203.0975","0.0200","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:49:00","46","47","14","204.4278","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:50:00","43","48","11","205.7580","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:51:00","44","47","12","207.0883","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:52:00","45","48","17","208.4185","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:53:00","49","48","17","209.7488","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:54:00","43","48","18","211.0790","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:55:00","45","48","17","212.4093","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:56:00","42","47","13","213.7395","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:57:00","175","47","15","215.0750","0.0214","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:58:00","46","47","12","216.4275","0.0367","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 01:59:00","43","47","15","217.7577","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:00:00","47","47","17","219.0880","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:01:00","45","47","17","220.4182","0.0167","0","0","0","0","0","53","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:02:00","45","47","17","221.7485","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:03:00","45","48","17","223.0787","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:04:00","1401","50","18","224.5367","0.1317","1","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:05:00","118","48","15","226.1046","0.2306","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:06:00","93","45","15","227.4583","0.0378","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:07:00","94","46","12","228.7889","0.0169","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:08:00","93","47","13","230.1191","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:09:00","92","47","16","231.4494","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:10:00","92","47","16","232.7796","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:11:00","96","47","15","234.1099","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:12:00","104","47","14","235.4441","0.0203","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:13:00","90","47","9","236.7790","0.0208","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:14:00","89","47","16","238.1093","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:15:00","90","47","14","239.4395","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:16:00","90","48","10","240.7698","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:17:00","90","47","12","242.1000","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:18:00","102","48","16","243.4377","0.0233","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:19:00","93","47","14","244.7679","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:20:00","94","48","15","246.0981","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:21:00","97","48","16","247.4324","0.0203","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:22:00","266","47","16","248.8068","0.0564","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:23:00","116","47","15","250.1568","0.0344","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:24:00","122","47","14","251.5056","0.0333","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:25:00","111","48","14","252.8543","0.0333","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:26:00","102","47","12","254.1985","0.0292","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:27:00","170","48","14","255.5318","0.0194","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:28:00","96","48","16","256.8889","0.0408","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:29:00","97","48","17","258.2225","0.0197","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:30:00","94","48","6","259.5528","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:31:00","93","48","12","260.8830","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:32:00","89","48","13","262.2133","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:33:00","1318","55","11","263.8333","0.2775","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:34:00","84","44","16","265.2198","0.0672","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:35:00","87","47","16","266.5555","0.0217","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:36:00","87","46","16","267.8858","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:37:00","88","46","16","269.2161","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:38:00","329","47","16","270.5611","0.0300","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:39:00","154","52","18","271.9626","0.0808","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:40:00","84","45","15","273.3012","0.0242","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:41:00","82","45","15","274.6315","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:42:00","82","45","15","275.9617","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:43:00","85","48","15","277.2920","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:44:00","185","49","16","278.6420","0.0344","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:45:00","101","47","14","279.9917","0.0342","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:46:00","110","46","15","281.3321","0.0258","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:47:00","70","47","16","282.6624","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:48:00","88","48","17","283.9960","0.0197","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:49:00","66","45","16","285.3262","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:50:00","90","45","12","286.6574","0.0175","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:51:00","69","48","15","287.9877","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:52:00","217","48","13","289.3528","0.0481","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:53:00","81","46","16","290.6905","0.0233","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:54:00","82","47","14","292.0210","0.0169","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:55:00","73","45","15","293.3513","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:56:00","1297","49","13","294.7873","0.1119","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:57:00","181","47","NaN","296.5975","0.4486","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:58:00","103","47","NaN","297.9691","0.0539","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 02:59:00","96","45","13","299.3120","0.0281","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:00:00","90","45","15","300.6423","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:01:00","90","46","16","301.9725","0.0167","0","0","0","0","0","53","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:02:00","88","45","15","303.3028","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:03:00","133","46","16","304.6392","0.0222","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:04:00","203","46","15","306.0028","0.0467","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:05:00","85","44","15","307.3500","0.0319","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:06:00","113","45","16","308.6920","0.0272","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:07:00","85","45","15","310.0222","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:08:00","266","46","15","311.3741","0.0361","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:09:00","90","45","15","312.7386","0.0475","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:10:00","94","45","16","314.0747","0.0219","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:11:00","93","46","16","315.4049","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:12:00","113","46","16","316.7358","0.0172","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:13:00","88","46","16","318.0756","0.0253","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:14:00","87","47","16","319.4059","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:15:00","86","46","16","320.7361","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:16:00","90","47","16","322.0663","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:17:00","87","46","16","323.3966","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:18:00","88","46","16","324.7268","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:19:00","89","46","16","326.0571","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:20:00","89","47","16","327.3874","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:21:00","90","47","17","328.7176","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:22:00","91","47","16","330.0479","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:23:00","90","46","16","331.3781","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:24:00","90","46","17","332.7083","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:25:00","1177","48","17","334.1222","0.0919","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:26:00","144","53","17","335.9157","0.4336","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:27:00","92","43","17","337.2830","0.0500","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:28:00","1445","56","17","339.0090","0.3728","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 03:29:00","147","43","12","340.4852","0.1481","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:30:00","111","43","6","341.8395","0.0383","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:31:00","124","44","12","343.1883","0.0333","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:32:00","604","44","15","344.6550","0.1394","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:33:00","166","43","16","346.0753","0.0978","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:34:00","2625","44","14","347.6342","0.2225","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 03:35:00","77","43","16","349.3531","0.3664","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:36:00","75","43","15","350.7108","0.0414","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:37:00","78","43","15","352.0410","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:38:00","81","43","15","353.3713","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:39:00","84","44","14","354.7015","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:40:00","120","43","16","356.0435","0.0272","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:41:00","68","43","14","357.3750","0.0178","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:42:00","74","44","15","358.7053","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:43:00","91","45","16","360.0395","0.0203","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:44:00","149","43","16","361.3852","0.0306","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:45:00","58","44","15","362.7191","0.0200","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:46:00","65","44","16","364.0494","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:47:00","58","44","15","365.3796","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:48:00","408","46","15","366.7207","0.0264","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:49:00","642","52","15","368.2762","0.2194","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:50:00","61","44","16","369.6179","0.0269","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:51:00","44","44","15","370.9482","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:52:00","50","46","16","372.2784","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:53:00","56","45","16","373.6087","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:54:00","49","44","14","374.9389","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:55:00","60","46","14","376.2691","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:56:00","45","44","13","377.5994","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:57:00","48","45","16","378.9296","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:58:00","46","45","14","380.2599","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 03:59:00","45","46","15","381.5901","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:00:00","45","47","16","382.9204","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:01:00","44","45","16","384.2506","0.0167","0","0","0","0","0","53","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:02:00","47","46","16","385.5809","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:03:00","48","47","16","386.9111","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:04:00","50","47","16","388.2414","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:05:00","50","47","15","389.5716","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:06:00","49","47","16","390.9018","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:07:00","53","46","15","392.2321","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:08:00","2226","53","16","394.0695","0.4731","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 04:09:00","81","45","16","395.5053","0.1117","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:10:00","625","52","17","396.9830","0.1494","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:11:00","35","44","15","398.3238","0.0261","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:12:00","77","45","16","399.6590","0.0211","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:13:00","35","44","16","400.9892","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:14:00","37","44","17","402.3195","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:15:00","35","45","17","403.6497","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:16:00","34","45","13","404.9800","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:17:00","31","44","18","406.2951","0.0031","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:18:00","36","47","11","407.6164","0.0086","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:19:00","39","52","8","408.9466","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:20:00","47","57","10","410.2769","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 04:21:00","1198","53","15","412.2281","0.5756","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:22:00","42","42","12","413.6093","0.0625","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:23:00","47","46","8","414.9395","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:24:00","50","45","9","416.2697","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:25:00","52","47","7","417.6000","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:26:00","51","46","9","418.9303","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:27:00","74","45","15","420.2605","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:28:00","70","46","15","421.5908","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:29:00","75","45","13","422.9210","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:30:00","618","47","12","424.2883","0.0500","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:31:00","1079","53","12","425.9768","0.3392","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:32:00","67","41","10","427.3404","0.0467","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:33:00","72","43","8","428.6707","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:34:00","150","43","15","430.0198","0.0336","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:35:00","83","44","10","431.3525","0.0189","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:36:00","1078","49","15","432.8787","0.1931","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:37:00","125","45","13","434.3432","0.1375","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:38:00","94","41","14","435.6926","0.0339","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:39:00","101","41","14","437.0296","0.0228","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:40:00","98","43","14","438.3722","0.0278","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:41:00","101","42","16","439.7043","0.0183","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:42:00","104","45","16","441.0518","0.0322","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:43:00","644","44","13","442.4861","0.1103","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:44:00","93","43","15","443.8738","0.0683","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:45:00","114","46","15","445.2220","0.0328","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:46:00","83","43","12","446.5574","0.0214","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:47:00","101","44","13","447.8914","0.0200","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:48:00","199","45","11","449.2336","0.0275","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:49:00","92","43","8","450.5929","0.0428","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:50:00","1699","45","13","452.0571","0.1372","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","0" -"11-05-2022 04:51:00","179","47","15","453.8639","0.4456","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:52:00","62","41","16","455.2210","0.0408","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:53:00","58","42","15","456.5513","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:54:00","59","41","16","457.8815","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:55:00","78","43","16","459.2120","0.0169","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:56:00","62","44","16","460.5423","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:57:00","57","41","15","461.8725","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:58:00","66","43","16","463.2028","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 04:59:00","60","45","17","464.5330","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:00:00","755","49","19","466.0179","0.1558","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:01:00","79","40","13","467.3834","0.0483","0","0","0","0","0","53","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:02:00","149","43","14","468.7364","0.0372","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:03:00","82","43","15","470.0719","0.0214","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:04:00","92","44","15","471.4022","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:05:00","88","43","12","472.7340","0.0181","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:06:00","87","46","14","474.0642","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:07:00","86","44","14","475.3944","0.0167","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:08:00","164","46","15","476.7395","0.0300","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:09:00","88","43","15","478.0846","0.0300","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:10:00","129","45","12","479.4281","0.0286","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:11:00","137","43","11","480.7722","0.0292","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:12:00","130","43","12","482.1293","0.0408","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:13:00","261","43","16","483.5062","0.0586","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:14:00","95","43","11","484.8556","0.0339","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" -"11-05-2022 05:15:00","94","45","14","486.1861","0.0169","0","0","0","0","0","NaN","NaN","NaN","NaN","0","0","0","1" diff --git a/man/mergePHBfilePairs.Rd b/man/mergePHBfilePairs.Rd index e285bc3..b10f129 100644 --- a/man/mergePHBfilePairs.Rd +++ b/man/mergePHBfilePairs.Rd @@ -9,19 +9,16 @@ xlsx file to csv. } \usage{ - mergePHBfilePairs(inputPath = ".", outputPath = ".", - timeformat = "\%m/\%d/\%Y \%H:\%M:\%S", - desiredtz = "", configtz = NULL, - timeformatName = "timeformat") + mergePHBfilePairs(filenames = NULL, + timeformat = "\%m/\%d/\%Y \%H:\%M:\%S", + desiredtz = "", configtz = NULL, + timeformatName = "timeformat") } \arguments{ - \item{inputPath}{ - Character, file path where xlsx files are located that need to be merged. - Assumption is that there is either one file starting with "Datalist_", one starting - with "Sleep_Wake_", or both for each recording. - } - \item{outputPath}{ - Character, path to store the merge output + \item{filenames}{ + Character vector, specifying the two filenames to be merged. + Assumption is that there is one file starting with "Datalist_" and one starting + with "Sleep_Wake_". } \item{timeformat}{ Character, timestemp format. @@ -43,8 +40,7 @@ } } \value{ - Function does not output values. Instead it stores the merged data as file in the location - as specified by outputPath. + Merged data from the two files. } \author{ Vincent T van Hees diff --git a/tests/testthat/test_mergePHBfilePairs.R b/tests/testthat/test_mergePHBfilePairs.R index 354585b..39c1b3b 100644 --- a/tests/testthat/test_mergePHBfilePairs.R +++ b/tests/testthat/test_mergePHBfilePairs.R @@ -4,32 +4,15 @@ test_that("merging of PHB files goes correctly", { # prepare folder with test files file1 = system.file("testfiles/DataList_AH1234567890_PhilipsHealthBand.xlsx", package = "GGIRread") file2 = system.file("testfiles/Sleep_Wake_AH1234567890_PhilipsHealthBand.xlsx", package = "GGIRread") - path = "./phb_test_folder" - if (!dir.exists(path)) { - dir.create(path) - } - invisible(file.copy(from = file1, to = path, overwrite = TRUE)) - invisible(file.copy(from = file2, to = path, overwrite = TRUE)) - # apply function to merge the files - mergePHBfilePairs(inputPath = path, outputPath = path, + D = mergePHBfilePairs(filenames = c(file1, file2), timeformat = "%m-%d-%Y %H:%M:%S", desiredtz = "Europe/Amsterdam") - - # check whether merged file exists - newfiles = dir(path, full.names = TRUE) - newFile = newfiles[grep(pattern = "def_AH1234567890_PhilipsHealthBand_000100621938.csv", x = newfiles)] - expect_true(length(newFile) == 1) - - # check file content - data = read.csv(newFile) - expect_equal(nrow(data), 246) - expect_equal(ncol(data), 19) - expect_equal(sum(data$counts), 50898) - expect_equal(sum(data$steps), 1) - expect_equal(data$timestamp[1], "2022-11-05 01:10:00") - - # clean up - if (dir.exists(path)) unlink(path, recursive = TRUE) + expect_equal(nrow(D$data), 246) + expect_equal(ncol(D$data), 19) + expect_equal(sum(D$data$counts), 50898) + expect_equal(sum(D$data$steps), 1) + expect_equal(format(D$data$timestamp[1]), "2022-11-05 01:10:00") + expect_equal(D$deviceSN, "000100621938") }) \ No newline at end of file