Skip to content

Commit

Permalink
Merge pull request #62 from wadpac/issue61_increamenting_time_GENEActiv
Browse files Browse the repository at this point in the history
Increment time correctly between pages GENEActiv
  • Loading branch information
vincentvanhees authored Mar 27, 2024
2 parents 91631dc + 63055d3 commit af8a376
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: GGIRread
Type: Package
Title: Wearable Accelerometer Data File Readers
Version: 0.3.3
Date: 2024-01-24
Version: 1.0.0
Date: 2024-03-27
Authors@R: c(person("Vincent T","van Hees",role=c("aut","cre"),
email="[email protected]"),
person(given = "Patrick",family = "Bos",
Expand Down
6 changes: 5 additions & 1 deletion R/readGENEActiv.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ readGENEActiv = function(filename, start = 0, end = 0, progress_bar = FALSE,
}

# Correct timestamps
page_offset = (((start - 1) * 300) / rawdata$info$SampleRate)
if (start > 1) {
page_offset = (((start - 1) * 300) / rawdata$info$SampleRate)
} else {
page_offset = 0
}
starttime_num = as.numeric(starttime_posix) + page_offset
rawdata$time = rawdata$time + abs(rawdata$time[1]) + starttime_num
return(invisible(list(
Expand Down
5 changes: 3 additions & 2 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
\title{News for Package \pkg{GGIRread}}
\newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}

\section{Changes in version 0.3.4 (release date:??-??-2024)}{
\section{Changes in version 1.0.0 (release date:27-03-2024)}{
\itemize{
\item GENEActiv no longer prints error to console when more data is requested than is in the file because this is not an error, issue #58
\item GENEActiv no longer prints error to console when more data is requested
than is in the file because this is not an error, issue #58
}
}

Expand Down
4 changes: 2 additions & 2 deletions man/GGIRread-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
\tabular{ll}{
Package: \tab GGIRread\cr
Type: \tab Package\cr
Version: \tab 0.3.3\cr
Date: \tab 2024-01-24\cr
Version: \tab 1.0.0\cr
Date: \tab 2024-03-27\cr
License: \tab LGPL (>= 2.0, < 3)\cr
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/GENEActivReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,14 @@ Rcpp::List GENEActivReader(std::string filename, std::size_t start = 0, std::siz
while (std::getline(input_file, line)) {
++blockCount;
if (blockCount >= start && blockCount <= end) {
blockTime = lastvalue;
// header: "Recorded Data" (0), serialCode (1), seq num (2),
// blockTime (3), unassigned (4), temp (5), batteryVolt (6),
// deviceStatus (7), freq (8), data (9)
for (int i = 1; i < blockHeaderSize; i++) {
try {
std::getline(input_file, header);
if (i == 3) {
std::stringstream ss(header);
int milliseconds;
ss >> milliseconds;
blockTime = lastvalue + milliseconds;
} else if (i == 5) {
if (i == 5) {
std::stringstream ss(header);
ss.ignore(max_streamsize, ':');
ss >> temperature;
Expand Down Expand Up @@ -168,7 +164,6 @@ Rcpp::List GENEActivReader(std::string filename, std::size_t start = 0, std::siz
double y = 0.0;
double z = 0.0;
double t = 0.0;

int i = 0;
while (hexPosition < data.size() - 1) {
try {
Expand All @@ -182,9 +177,8 @@ Rcpp::List GENEActivReader(std::string filename, std::size_t start = 0, std::siz
x = (xRaw * 100. - mfrOffset[0]) / mfrGain[0];
y = (yRaw * 100. - mfrOffset[1]) / mfrGain[1];
z = (zRaw * 100. - mfrOffset[2]) / mfrGain[2];

t = (double)blockTime + (double)i * (1.0 / freq) * 1000; // Unix millis
lastvalue = t;
lastvalue = t + (1.0 / freq) * 1000;
time_array.push_back(t);
x_array.push_back(x);
y_array.push_back(y);
Expand Down
16 changes: 9 additions & 7 deletions tests/testthat/test_readGENEActiv.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test_that("GENEActivReader reads data from file correctly", {
expect_equal(cppdata$info$SampleRate, 85.7)
expect_equal(cppdata$info$numBlocksTotal, 222048)
expect_equal(length(cppdata$time), 300)
expect_equal(cppdata$time[300], 3488)
expect_equal(length(cppdata$x), 300)
expect_equal(length(cppdata$y), 300)
expect_equal(length(cppdata$z), 300)
Expand All @@ -21,7 +22,7 @@ test_that("GENEActivReader reads data from file correctly", {
test_that("readGENEActiv reads data from file correctly", {
old <- options(digits.secs = 3)
binfile = system.file("testfiles/GENEActiv_testfile.bin", package = "GGIRread")[1]
rdata = readGENEActiv(filename = binfile, start = 1, end = 1, desiredtz = "Europe/London")
rdata = readGENEActiv(filename = binfile, start = 1, end = 2, desiredtz = "Europe/London")

expect_equal(rdata$header$ReadOK, 1)
expect_equal(rdata$header$ReadErrors, 0)
Expand All @@ -31,12 +32,13 @@ test_that("readGENEActiv reads data from file correctly", {
expect_equal(rdata$header$RecordingID, "")
expect_equal(rdata$header$DeviceLocation, "")
expect_equal(rdata$header$DeviceModel, "1.1")
expect_equal(length(rdata$data$time), 300)
expect_equal(length(rdata$data$x), 300)
expect_equal(length(rdata$data$y), 300)
expect_equal(length(rdata$data$z), 300)
expect_equal(length(rdata$data$temperature), 300)
expect_equal(length(rdata$data$light), 300)
expect_equal(length(rdata$data$time), 600)
expect_equal(rdata$data$time[600], 1369905181)
expect_equal(length(rdata$data$x), 600)
expect_equal(length(rdata$data$y), 600)
expect_equal(length(rdata$data$z), 600)
expect_equal(length(rdata$data$temperature), 600)
expect_equal(length(rdata$data$light), 600)
expect_equal(rdata$data$temperature[1], 21.5)
expect_equal(rdata$data$light[2], 2.666667, tolerance = 4)
expect_equal(rdata$data$z[300], -0.80836403369903564453, tolerance = 15)
Expand Down

0 comments on commit af8a376

Please sign in to comment.