Skip to content

Commit af8a376

Browse files
Merge pull request #62 from wadpac/issue61_increamenting_time_GENEActiv
Increment time correctly between pages GENEActiv
2 parents 91631dc + 63055d3 commit af8a376

6 files changed

Lines changed: 24 additions & 23 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: GGIRread
22
Type: Package
33
Title: Wearable Accelerometer Data File Readers
4-
Version: 0.3.3
5-
Date: 2024-01-24
4+
Version: 1.0.0
5+
Date: 2024-03-27
66
Authors@R: c(person("Vincent T","van Hees",role=c("aut","cre"),
77
email="v.vanhees@accelting.com"),
88
person(given = "Patrick",family = "Bos",

R/readGENEActiv.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ readGENEActiv = function(filename, start = 0, end = 0, progress_bar = FALSE,
7070
}
7171

7272
# Correct timestamps
73-
page_offset = (((start - 1) * 300) / rawdata$info$SampleRate)
73+
if (start > 1) {
74+
page_offset = (((start - 1) * 300) / rawdata$info$SampleRate)
75+
} else {
76+
page_offset = 0
77+
}
7478
starttime_num = as.numeric(starttime_posix) + page_offset
7579
rawdata$time = rawdata$time + abs(rawdata$time[1]) + starttime_num
7680
return(invisible(list(

inst/NEWS.Rd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
\title{News for Package \pkg{GGIRread}}
33
\newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
44

5-
\section{Changes in version 0.3.4 (release date:??-??-2024)}{
5+
\section{Changes in version 1.0.0 (release date:27-03-2024)}{
66
\itemize{
7-
\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
7+
\item GENEActiv no longer prints error to console when more data is requested
8+
than is in the file because this is not an error, issue #58
89
}
910
}
1011

man/GGIRread-package.Rd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
\tabular{ll}{
1515
Package: \tab GGIRread\cr
1616
Type: \tab Package\cr
17-
Version: \tab 0.3.3\cr
18-
Date: \tab 2024-01-24\cr
17+
Version: \tab 1.0.0\cr
18+
Date: \tab 2024-03-27\cr
1919
License: \tab LGPL (>= 2.0, < 3)\cr
2020
}
2121
}

src/GENEActivReader.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,14 @@ Rcpp::List GENEActivReader(std::string filename, std::size_t start = 0, std::siz
127127
while (std::getline(input_file, line)) {
128128
++blockCount;
129129
if (blockCount >= start && blockCount <= end) {
130+
blockTime = lastvalue;
130131
// header: "Recorded Data" (0), serialCode (1), seq num (2),
131132
// blockTime (3), unassigned (4), temp (5), batteryVolt (6),
132133
// deviceStatus (7), freq (8), data (9)
133134
for (int i = 1; i < blockHeaderSize; i++) {
134135
try {
135136
std::getline(input_file, header);
136-
if (i == 3) {
137-
std::stringstream ss(header);
138-
int milliseconds;
139-
ss >> milliseconds;
140-
blockTime = lastvalue + milliseconds;
141-
} else if (i == 5) {
137+
if (i == 5) {
142138
std::stringstream ss(header);
143139
ss.ignore(max_streamsize, ':');
144140
ss >> temperature;
@@ -168,7 +164,6 @@ Rcpp::List GENEActivReader(std::string filename, std::size_t start = 0, std::siz
168164
double y = 0.0;
169165
double z = 0.0;
170166
double t = 0.0;
171-
172167
int i = 0;
173168
while (hexPosition < data.size() - 1) {
174169
try {
@@ -182,9 +177,8 @@ Rcpp::List GENEActivReader(std::string filename, std::size_t start = 0, std::siz
182177
x = (xRaw * 100. - mfrOffset[0]) / mfrGain[0];
183178
y = (yRaw * 100. - mfrOffset[1]) / mfrGain[1];
184179
z = (zRaw * 100. - mfrOffset[2]) / mfrGain[2];
185-
186180
t = (double)blockTime + (double)i * (1.0 / freq) * 1000; // Unix millis
187-
lastvalue = t;
181+
lastvalue = t + (1.0 / freq) * 1000;
188182
time_array.push_back(t);
189183
x_array.push_back(x);
190184
y_array.push_back(y);

tests/testthat/test_readGENEActiv.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test_that("GENEActivReader reads data from file correctly", {
99
expect_equal(cppdata$info$SampleRate, 85.7)
1010
expect_equal(cppdata$info$numBlocksTotal, 222048)
1111
expect_equal(length(cppdata$time), 300)
12+
expect_equal(cppdata$time[300], 3488)
1213
expect_equal(length(cppdata$x), 300)
1314
expect_equal(length(cppdata$y), 300)
1415
expect_equal(length(cppdata$z), 300)
@@ -21,7 +22,7 @@ test_that("GENEActivReader reads data from file correctly", {
2122
test_that("readGENEActiv reads data from file correctly", {
2223
old <- options(digits.secs = 3)
2324
binfile = system.file("testfiles/GENEActiv_testfile.bin", package = "GGIRread")[1]
24-
rdata = readGENEActiv(filename = binfile, start = 1, end = 1, desiredtz = "Europe/London")
25+
rdata = readGENEActiv(filename = binfile, start = 1, end = 2, desiredtz = "Europe/London")
2526

2627
expect_equal(rdata$header$ReadOK, 1)
2728
expect_equal(rdata$header$ReadErrors, 0)
@@ -31,12 +32,13 @@ test_that("readGENEActiv reads data from file correctly", {
3132
expect_equal(rdata$header$RecordingID, "")
3233
expect_equal(rdata$header$DeviceLocation, "")
3334
expect_equal(rdata$header$DeviceModel, "1.1")
34-
expect_equal(length(rdata$data$time), 300)
35-
expect_equal(length(rdata$data$x), 300)
36-
expect_equal(length(rdata$data$y), 300)
37-
expect_equal(length(rdata$data$z), 300)
38-
expect_equal(length(rdata$data$temperature), 300)
39-
expect_equal(length(rdata$data$light), 300)
35+
expect_equal(length(rdata$data$time), 600)
36+
expect_equal(rdata$data$time[600], 1369905181)
37+
expect_equal(length(rdata$data$x), 600)
38+
expect_equal(length(rdata$data$y), 600)
39+
expect_equal(length(rdata$data$z), 600)
40+
expect_equal(length(rdata$data$temperature), 600)
41+
expect_equal(length(rdata$data$light), 600)
4042
expect_equal(rdata$data$temperature[1], 21.5)
4143
expect_equal(rdata$data$light[2], 2.666667, tolerance = 4)
4244
expect_equal(rdata$data$z[300], -0.80836403369903564453, tolerance = 15)

0 commit comments

Comments
 (0)