Skip to content

Commit 6e06588

Browse files
Merge pull request #1541 from wadpac/issue1540_unisensExampleData
Movisens test independent of internet access
2 parents 0497616 + 9830246 commit 6e06588

2 files changed

Lines changed: 44 additions & 70 deletions

File tree

‎NEWS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# CHANGES IN GGIR VERSION 3.3-?
22

3+
- Tests: Made the Movisens test independent of internet access by including the test data in inst/testfiles (#1540)
4+
35
- Part 3: Add new guider named LowAcc, with new parameter LowAcc_threshold. Further, parameter HDCZA_roll_windowsize was added related to guider HDCZA. #1287
46

57
- Part 3: Added new parameter HDCZA_roll_windowsize to control the size of the rolling window used by the HDCZA guider algorithm.
68

7-
- Part 1: Skip movisens tests on both CRAN and GitHub Actions. These tests are now only run locally as they depend on the downloading of test data.
8-
99
- Part 5: Allow for day segment analysis for the WW and OO window definition. #1407
1010

1111
# CHANGES IN GGIR VERSION 3.3-8

‎tests/testthat/test_greadaccfile.R‎

Lines changed: 42 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,48 @@ test_that("g.readaccfile and g.inspectfile can read movisens, gt3x, cwa, Axivity
157157
inspectfileobject = IGA)
158158
expect_true(MGA$filetooshort)
159159

160+
cat("\n Movisens")
161+
162+
# Test data from the unisensExample at:
163+
# https://github.com/Unisens/unisensR/tree/0.3.4/tests/unisensExample
164+
output_dir = "output_unisensExample"
165+
on.exit({if (file.exists(output_dir)) unlink(output_dir, recursive = TRUE)}, add = TRUE)
166+
if (file.exists(output_dir)) unlink(output_dir, recursive = TRUE)
167+
168+
movisensFile = system.file(
169+
"extdata/unisensExample/acc.bin",
170+
package = "unisensR"
171+
)
172+
173+
expect_true(file.exists(movisensFile))
174+
175+
Mcsv = g.inspectfile(movisensFile, desiredtz = desiredtz)
176+
expect_equal(Mcsv$monc, MONITOR$MOVISENS)
177+
expect_equal(Mcsv$dformc, FORMAT$BIN)
178+
expect_equal(Mcsv$sf, 64)
179+
180+
movisens_blocksize = 3000
181+
movisens_read = g.readaccfile(movisensFile, blocksize = movisens_blocksize, blocknumber = 1, filequality = filequality,
182+
dayborder = dayborder, ws = 3,
183+
PreviousEndPage = 1, inspectfileobject = Mcsv,
184+
params_rawdata = params_rawdata, params_general = params_general)
185+
expect_equal(nrow(movisens_read$P$data), movisens_blocksize)
186+
expect_false(movisens_read$filequality$filecorrupt)
187+
expect_false(movisens_read$filequality$filetooshort)
188+
expect_equal(movisens_read$endpage, movisens_blocksize)
189+
190+
# read the next block (set PreviousEndPage to movisens_read$endpage)
191+
movisens_read2 = g.readaccfile(movisensFile, blocksize = movisens_blocksize, blocknumber = 2, filequality = filequality,
192+
dayborder = dayborder, ws = 3,
193+
PreviousEndPage = movisens_read$endpage, inspectfileobject = Mcsv,
194+
params_rawdata = params_rawdata, params_general = params_general)
195+
expect_equal(nrow(movisens_read2$P$data), movisens_blocksize)
196+
expect_equal(movisens_read2$endpage, movisens_blocksize * 2)
197+
198+
# if the 1st sample of 2nd block is identical to the last sample of the 1st block,
199+
# this means that we calculated the startpage of the 2nd block incorrectly.
200+
expect_false(any(movisens_read2$P$data[1,] == movisens_read$P$data[nrow(movisens_read$P$data),]))
201+
cat("\n ad-hoc csv file")
160202
# ad-hoc csv file
161203

162204
# Create test file: No header, with temperature, with time.
@@ -429,72 +471,4 @@ test_that("g.readaccfile and g.inspectfile can read movisens, gt3x, cwa, Axivity
429471
if (file.exists(testfile_two_col)) file.remove(testfile_two_col)
430472
if (file.exists(testfile)) file.remove(testfile)
431473
if (file.exists(filename)) file.remove(filename)
432-
})
433-
434-
test_that("g.readaccfile and g.inspectfile can read movisens files correctly", {
435-
436-
skip_if(Sys.getenv("GITHUB_ACTIONS") == "true", message = "Skipping on GitHub Actions")
437-
skip_on_cran()
438-
439-
desiredtz = "Pacific/Auckland"
440-
configtz = "Europe/Berlin"
441-
params = extract_params(input = list(frequency_tol = 0.1, interpolationType = 1,
442-
desiredtz = desiredtz, configtz = configtz))
443-
params_rawdata = params$params_rawdata
444-
params_general = params$params_general
445-
446-
filequality = list(filecorrupt = FALSE, filetooshort = FALSE)
447-
dayborder = 0
448-
449-
cat("\n Movisens")
450-
451-
output_dir = "output_unisensExample"
452-
on.exit({if (file.exists(output_dir)) unlink(output_dir, recursive = TRUE)}, add = TRUE)
453-
if (file.exists(output_dir)) unlink(output_dir, recursive = TRUE)
454-
455-
zip_file = "0.3.4.zip"
456-
on.exit({if (file.exists(zip_file)) unlink(zip_file)}, add = TRUE)
457-
if (!file.exists(zip_file)) {
458-
# link to a tagged release of Unisens/unisensR github repo
459-
movisens_url = "https://github.com/Unisens/unisensR/archive/refs/tags/0.3.4.zip"
460-
download.file(url = movisens_url, destfile = zip_file, quiet = TRUE)
461-
}
462-
movisens_dir = "unisensR-0.3.4"
463-
on.exit({if (file.exists(movisens_dir)) unlink(movisens_dir, recursive = TRUE)}, add = TRUE)
464-
if (file.exists(movisens_dir)) {
465-
unlink(movisens_dir, recursive = TRUE)
466-
}
467-
unzip(zipfile = zip_file, exdir = ".")
468-
movisensFile = file.path(getwd(), "unisensR-0.3.4/tests/unisensExample/acc.bin")
469-
470-
Mcsv = g.inspectfile(movisensFile, desiredtz = desiredtz)
471-
expect_equal(Mcsv$monc, MONITOR$MOVISENS)
472-
expect_equal(Mcsv$dformc, FORMAT$BIN)
473-
expect_equal(Mcsv$sf, 64)
474-
475-
movisens_blocksize = 3000
476-
movisens_read = g.readaccfile(movisensFile, blocksize = movisens_blocksize, blocknumber = 1, filequality = filequality,
477-
dayborder = dayborder, ws = 3,
478-
PreviousEndPage = 1, inspectfileobject = Mcsv,
479-
params_rawdata = params_rawdata, params_general = params_general)
480-
expect_equal(nrow(movisens_read$P$data), movisens_blocksize)
481-
expect_false(movisens_read$filequality$filecorrupt)
482-
expect_false(movisens_read$filequality$filetooshort)
483-
expect_equal(sum(movisens_read$P$data[c("x","y","z")]), 4383.67, tolerance = .01, scale = 1)
484-
expect_equal(movisens_read$endpage, movisens_blocksize)
485-
486-
# read the next block (set PreviousEndPage to movisens_read$endpage)
487-
movisens_read2 = g.readaccfile(movisensFile, blocksize = movisens_blocksize, blocknumber = 2, filequality = filequality,
488-
dayborder = dayborder, ws = 3,
489-
PreviousEndPage = movisens_read$endpage, inspectfileobject = Mcsv,
490-
params_rawdata = params_rawdata, params_general = params_general)
491-
expect_equal(nrow(movisens_read2$P$data), movisens_blocksize)
492-
expect_equal(movisens_read2$endpage, movisens_blocksize * 2)
493-
494-
# if the 1st sample of 2nd block is identical to the last sample of the 1st block,
495-
# this means that we calculated the startpage of the 2nd block incorrectly.
496-
expect_false(any(movisens_read2$P$data[1,] == movisens_read$P$data[nrow(movisens_read$P$data),]))
497-
498-
if (dir.exists("unisensR-0.3.4/")) unlink("unisensR-0.3.4/", recursive = TRUE)
499-
if (file.exists(zip_file)) file.remove(zip_file)
500474
})

0 commit comments

Comments
 (0)