Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: motus
Type: Package
Version: 6.1.1
Version: 6.1.2
Title: Fetch and use data from the Motus Wildlife Tracking System
Description: Retrieve, filter, and visualize telemetry data from the Motus
Wildlife Tracking System <https://motus.org>.
Expand All @@ -23,7 +23,7 @@ Authors@R: c(
URL: https://motuswts.github.io/motus/
BugReports: https://github.com/MotusWTS/motus/issues
Depends:
R (>= 3.2.0)
R (>= 3.5)
Imports:
DBI (>= 1.0.0),
dbplyr (>= 2.1.1),
Expand Down
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# motus 6.1.2
* Add bandNumbers to `tagDeps` table
* Update vignettes to use new version of rnaturalearth

# motus 6.1.1
* Add support for Sigma Eight receivers

Expand All @@ -9,7 +13,9 @@
* `tagme()` fails gracefully if the directory specified does not exist
* Fixed `Error in as.POSIXlt.character(x, tz, ...)` when starting a download
* `tagme(new = TRUE)` now starts a download immediately
* Add `srvTimeout()` to specify the server timeout limit
* Add `srvTimeout()` to specify

# motus 6.0.0the server timeout limit
* Clean up helper functions `sunRiseSet()` and `timeToSunriset()`
* `sunRiseSet()` now required to run `timeToSunriset()`
* Changed function argument names for clarity
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
2 changes: 2 additions & 0 deletions RELEASE.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ remotes::install_deps(dependencies = TRUE)

## Update internal data files ------------------------------------------------

# - Update SQL fields/tables in data-raw/field_names.R

# - If merging sandbox - make sure that data-raw/updatesql.R updates unique to
# sandbox have a date later than beta updates (otherwise they won't trigger)

Expand Down
12 changes: 9 additions & 3 deletions data-raw/field_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ field_names <- srvSchema() %>%
rename_all(tolower) %>%
rename(column = column_name, table = table_name, type = data_type) %>%
mutate(type = toupper(type),
table = tolower(table)) %>%
table = tolower(table),
table = stringr::str_remove(table, "^vwr_")) %>%
filter(!column %in% c("accessLevel"),
!str_detect(column, "is_private"))

Expand Down Expand Up @@ -46,7 +47,7 @@ t <- field_names %>%
# batches ------------------------------------------------------------------
# "batches" table applies to batches_for_receiver and batches_for_tag
t <- field_names %>%
filter(str_detect(table, "batches_for_tag_project$"),
filter(str_detect(table, "^batches_for_tag_project$"),
!column %in% c("version")) %>%
mutate(table = "batches",
keys = column == "batchID") %>%
Expand Down Expand Up @@ -175,7 +176,6 @@ t <- field_names %>%
# tagDeps --------------------------------------------------------------------
t <- field_names %>%
filter(str_detect(table, "tags_deps")) %>%
add_row(column = "bandNumber", type = "TEXT") %>%
add_row(column = "id", type = "INTEGER") %>%
add_row(column = "bi", type = "INTEGER") %>%
add_row(column = "fullID", type = "INTEGER") %>%
Expand Down Expand Up @@ -370,6 +370,12 @@ consolidate <- function(x) {
x
}

# Check for duplicates -----------------------------------------------
dups <- t %>%
summarize(n = n(), .by = c("table", "column")) %>%
filter(n > 1)

if(nrow(dups) > 0) stop("Duplicate fields, check it out!\n", paste0(capture.output(dups), collapse = "\n"))

# ** COMBINE ---------------------------------------------------------------
sql_fields <- t %>%
Expand Down
16 changes: 12 additions & 4 deletions tests/testthat/test_05_helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_that("filterByActivity filters as expected", {

expect_equal(dplyr::arrange(a, .data$probability, .data$hitID) %>%
dplyr::select("probability", "hitID"),
rbind(b, g) %>%
dplyr::arrange(rbind(b, g), .data$probability, .data$hitID) %>%
dplyr::select("probability", "hitID"))

# Matches motusFilter results
Expand Down Expand Up @@ -219,10 +219,18 @@ test_that("PROJ 1 - remove deprecated batches", {
test_that("RECV - remove deprecated batches", {
skip_if_no_server()
skip_if_no_auth()
withr::local_file("SG-1814BBBK0461.motus")
withr::local_db_connection(
suppressMessages(t <- tagme("SG-1814BBBK0461", new = TRUE)))

# Jump start database at batch number to have runs
s <- srvAuth() # Authorize to update data versions
withr::local_file(list("SG-4002BBBK1580.motus"))
withr::local_db_connection(t <- tagme("SG-4002BBBK1580", update = FALSE, new = TRUE))
deviceID <- srvDeviceIDForReceiver(get_projRecv(t))[[2]]
ensureDBTables(t, get_projRecv(t), deviceID)
DBI::dbExecute(t, "INSERT INTO batches (batchID) VALUES (2733020)")

# Get some runs
suppressMessages(t <- tagme("SG-4002BBBK1580", update = TRUE, new = FALSE))

# Deprecated batches listed, but not removed to start
dep <- dplyr::tbl(t, "deprecated") %>%
dplyr::collect()
Expand Down
16 changes: 5 additions & 11 deletions tests/testthat/test_07_data_returned.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ test_that("Reciever data returned as expected", {
skip_on_cran()
skip_if_no_server()
skip_if_no_auth()
withr::local_file("SG-3115BBBK0782.motus")
unlink("SG-4002BBBK1580.motus") # For windows...
withr::local_file("SG-4002BBBK1580.motus")
withr::local_options(list(motus.test.max = 1))

# Create empty data
expect_message(tags <- withr::local_db_connection(
tagme(projRecv = "SG-3115BBBK0782", new = TRUE))) %>%
tagme(projRecv = "SG-4002BBBK1580", new = TRUE))) %>%
suppressMessages()
expect_s4_class(tags, "SQLiteConnection")

Expand All @@ -107,17 +108,10 @@ test_that("Reciever data returned as expected", {
expect_true(!!i %in% DBI::dbListTables(tags))
}

# Skip to batches with data (Kids - don't do this at home!)
withr::local_options(list(motus.test.max = 10))
dbInsertOrReplace(tags, "batches", data.frame(batchID = 1789309))
expect_message(tags <- withr::local_db_connection(
tagme(projRecv = "SG-3115BBBK0782"))) %>%
suppressMessages()

#activity
expect_silent(a <- dplyr::tbl(tags, "activity") %>% dplyr::collect())
expect_true(nrow(a) > 0)
expect_false(all(sapply(a, function(x) all(is.na(x))))) # No all missing values
#expect_true(nrow(a) > 0)
#expect_false(all(sapply(a, function(x) all(is.na(x))))) # No all missing values

expect_type(a$ant, "character") # All numeric/integer (except ant)
for(i in names(a)[names(a) != "ant"]) {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_11_tagme.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ test_that("tellme() - Receivers", {
skip_on_cran()
skip_if_no_server()
skip_if_no_auth()
unlink("SG-3115BBBK1127.motus") # For windows...
unlink("SG-4002BBBK1580.motus") # For windows...

withr::local_file("SG-3115BBBK1127.motus")
expect_silent(tellme("SG-3115BBBK1127", new = TRUE)) %>%
withr::local_file("SG-4002BBBK1580.motus")
expect_silent(tellme("SG-4002BBBK1580", new = TRUE)) %>%
expect_s3_class("data.frame")
})
44 changes: 25 additions & 19 deletions tests/testthat/test_99_data_version.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("Proj - DB updates - new = TRUE", {
skip_on_os("windows")
sample_auth()
skip_if_no_server()
withr::local_file("project-176.motus")
Expand All @@ -18,6 +19,7 @@ test_that("Proj - DB updates - new = TRUE", {
})

test_that("Proj - DB updates - forceMeta", {
skip_on_os("windows")
sample_auth()
skip_if_no_server()
withr::local_file("project-176.motus")
Expand All @@ -37,6 +39,7 @@ test_that("Proj - DB updates - forceMeta", {
})

test_that("Proj - DB updates - new = FALSE", {
skip_on_os("windows")
sample_auth()
skip_if_no_server()
withr::local_file("project-176.motus")
Expand Down Expand Up @@ -71,6 +74,7 @@ test_that("Proj - DB updates - new = FALSE", {
})

test_that("Proj - Update fails if backup present", {
skip_on_os("windows")
sample_auth()
skip_if_no_server()
withr::local_file("project-176_v1.motus")
Expand All @@ -93,47 +97,49 @@ test_that("Recv - DB updates - 2", {
skip_on_os("windows")
skip_if_no_server()
skip_if_no_auth()
withr::local_file("SG-3115BBBK1127.motus")
withr::local_file("SG-3115BBBK1127_v1.motus")

recv <- "SG-4002BBBK1580"
recv_f1 <- paste0(recv, ".motus")
recv_f2 <- paste0(recv, "_v1.motus")

withr::local_file(recv_f1)
withr::local_file(recv_f2)

# Create dummy version 1 - more data
withr::local_options(list(motus.test.max = 30))
tags <- withr::local_db_connection(
tagme("SG-3115BBBK1127", new = TRUE)) %>%
tagme(recv, new = TRUE)) %>%
suppressMessages()
DBI_Execute(tags, "UPDATE admInfo set data_version = 1")

expect_false(file.exists("SG-3115BBBK1127_v1.motus")) # No backup
expect_false(file.exists(recv_f2)) # No backup
expect_message(
t <- withr::local_db_connection(
tagme("SG-3115BBBK1127", rename = TRUE))) %>%
tagme(recv, rename = TRUE))) %>%
suppressMessages()
expect_true(file.exists("SG-3115BBBK1127_v1.motus")) # Backup

# Expect data
new <- withr::local_db_connection(
DBI::dbConnect(RSQLite::SQLite(), dbname = "SG-3115BBBK1127.motus"))

expect_gt(DBI_Query(new, "SELECT * FROM activity") %>% nrow(), 0)
expect_gt(DBI_Query(new, "SELECT * FROM hits") %>% nrow(), 0)
expect_gt(DBI_Query(new, "SELECT * FROM runs") %>% nrow(), 0)
expect_true(file.exists(recv_f2)) # Backup
})

test_that("Recv - Update fails if backup present", {
skip_on_os("windows")
skip_if_no_auth()
skip_if_no_server()

recv <- "SG-4002BBBK1580"
recv_f1 <- paste0(recv, ".motus")
recv_f2 <- paste0(recv, "_v1.motus")

withr::local_file("SG-3115BBBK1127_v1.motus")
withr::local_file("SG-3115BBBK1127.motus")
file.create("SG-3115BBBK1127_v1.motus")
withr::local_file(recv_f2)
withr::local_file(recv_f1)
file.create(recv_f2)

# Get old version
file.copy(system.file("extdata", "project-176_v1.motus", package = "motus"),
"./SG-3115BBBK1127.motus")
recv_f1)

expect_error(expect_message(
t <- withr::local_db_connection(
tagme("SG-3115BBBK1127", rename = TRUE)),
tagme(recv, rename = TRUE)),
"DATABASE UPDATE"),
"_v1.motus already exists") %>%
suppressMessages()
Expand Down
15 changes: 9 additions & 6 deletions vignettes/articles/04-deployments.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ title: "Chapter 4 - Tag and receiver deployments"

```{r setup, include = FALSE}
library(rnaturalearth)
dir.create("map-data")

# Get and update sample data to avoid messages later
sql_motus <- motus:::get_sample_data()
if(!file.exists("map-data/ne_50m_lakes.shp")) {
if(!file.exists("map-data/ne_50m_lakes.gpkg")) {
ne_download(scale = "medium", type = 'lakes', category = 'physical',
returnclass = "sf", destdir = "map-data")
returnclass = "sf", destdir = "map-data", load = FALSE)
}
```

Expand Down Expand Up @@ -175,17 +177,18 @@ Load base map files from the `rnaturalearth` package. You will need to have the

```{r eval = FALSE, message = FALSE, warning = FALSE}
world <- ne_countries(scale = "medium", returnclass = "sf")
# only need this first time downloading
lakes <- ne_download(scale = "medium", type = 'lakes', category = 'physical',
returnclass = "sf", destdir = "map-data") # only need this first time downloading
returnclass = "sf", destdir = "map-data", load = FALSE)


```

You only need to download the shapefiles once. If you return to an analysis later and run code again, you can use the `ne_load` function because the shapefiles are already stored on your computer:
You only need to download the spatial files once. If you return to an analysis later and run code again, you can use the `ne_load` function because the spatial files are already stored on your computer:

```{r eval = FALSE, message = FALSE, warning = FALSE}
lakes <- ne_load(type = "lakes", scale = "medium", category = 'physical',
returnclass = "sf",
destdir = "map-data") # use this if already downloaded shapefiles
returnclass = "sf", destdir = "map-data")

```

Expand Down