Skip to content

Commit

Permalink
increment time correctly between pages, fixes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanhees committed Mar 25, 2024
1 parent 91631dc commit 7325e24
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 3 additions & 1 deletion R/readGENEActiv.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ readGENEActiv = function(filename, start = 0, end = 0, progress_bar = FALSE,
}

# Correct timestamps
page_offset = (((start - 1) * 300) / rawdata$info$SampleRate)
if (start > 0) {
page_offset = (((start - 1) * 300) / rawdata$info$SampleRate)
}
starttime_num = as.numeric(starttime_posix) + page_offset
rawdata$time = rawdata$time + abs(rawdata$time[1]) + starttime_num
return(invisible(list(
Expand Down
1 change: 1 addition & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
\section{Changes in version 0.3.4 (release date:??-??-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 readGENEActiv: Fixed bug in incrementing time between file pages #61
}
}

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

0 comments on commit 7325e24

Please sign in to comment.