mirror of
https://github.com/sensebox/opensensmapr
synced 2025-03-12 05:00:27 +01:00
ensure archive resource is available
This commit is contained in:
parent
334a49a309
commit
1732084856
2 changed files with 41 additions and 3 deletions
27
R/archive.R
27
R/archive.R
|
@ -1,12 +1,12 @@
|
||||||
# client for archive.opensensemap.org
|
# client for archive.opensensemap.org
|
||||||
# in this archive, CSV files for measurements of each sensor per day is provided.
|
# in this archive, CSV files for measurements of each sensor per day is provided.
|
||||||
|
|
||||||
|
default_archive_url = 'https://archive.opensensemap.org/'
|
||||||
|
|
||||||
#' Returns the default endpoint for the archive *download*
|
#' Returns the default endpoint for the archive *download*
|
||||||
#' While the front end domain is archive.opensensemap.org, file downloads
|
#' While the front end domain is archive.opensensemap.org, file downloads
|
||||||
#' are provided via sciebo.
|
#' are provided via sciebo.
|
||||||
osem_archive_endpoint = function () {
|
osem_archive_endpoint = function () default_archive_url
|
||||||
'https://uni-muenster.sciebo.de/index.php/s/HyTbguBP4EkqBcp/download?path=/data'
|
|
||||||
}
|
|
||||||
|
|
||||||
#' Fetch day-wise measurements for a single box from the openSenseMap archive.
|
#' Fetch day-wise measurements for a single box from the openSenseMap archive.
|
||||||
#'
|
#'
|
||||||
|
@ -93,6 +93,8 @@ osem_measurements_archive.sensebox = function (x, fromDate, toDate = fromDate, s
|
||||||
#' @param progress whether to print progress
|
#' @param progress whether to print progress
|
||||||
#' @return A \code{tbl_df} containing observations of all selected sensors for each time stamp.
|
#' @return A \code{tbl_df} containing observations of all selected sensors for each time stamp.
|
||||||
archive_fetch_measurements = function (box, sensorId, fromDate, toDate, progress) {
|
archive_fetch_measurements = function (box, sensorId, fromDate, toDate, progress) {
|
||||||
|
osem_ensure_archive_available()
|
||||||
|
|
||||||
dates = list()
|
dates = list()
|
||||||
from = fromDate
|
from = fromDate
|
||||||
while (from <= toDate) {
|
while (from <= toDate) {
|
||||||
|
@ -150,3 +152,22 @@ osem_box_to_archivename = function (box) {
|
||||||
name = gsub('[^A-Za-z0-9._-]', '_', box$name)
|
name = gsub('[^A-Za-z0-9._-]', '_', box$name)
|
||||||
paste(box$X_id, name, sep = '-')
|
paste(box$X_id, name, sep = '-')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#' Check if the given openSenseMap archive endpoint is available
|
||||||
|
#' @param endpoint The archive base URL to check, defaulting to \code{\link{osem_archive_endpoint}}
|
||||||
|
#' @return \code{TRUE} if the archive is available, otherwise \code{stop()} is called.
|
||||||
|
osem_ensure_archive_available = function(endpoint = osem_archive_endpoint()) {
|
||||||
|
code = FALSE
|
||||||
|
try({
|
||||||
|
code = httr::status_code(httr::GET(endpoint))
|
||||||
|
}, silent = TRUE)
|
||||||
|
|
||||||
|
if (code == 200)
|
||||||
|
return(TRUE)
|
||||||
|
|
||||||
|
errtext = paste('The archive at', endpoint, 'is currently not available.')
|
||||||
|
if (code != FALSE)
|
||||||
|
errtext = paste0(errtext, ' (HTTP code ', code, ')')
|
||||||
|
stop(paste(errtext, collapse='\n '), call. = FALSE)
|
||||||
|
FALSE
|
||||||
|
}
|
17
man/osem_ensure_archive_available.Rd
Normal file
17
man/osem_ensure_archive_available.Rd
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/archive.R
|
||||||
|
\name{osem_ensure_archive_available}
|
||||||
|
\alias{osem_ensure_archive_available}
|
||||||
|
\title{Check if the given openSenseMap archive endpoint is available}
|
||||||
|
\usage{
|
||||||
|
osem_ensure_archive_available(endpoint = osem_archive_endpoint())
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{endpoint}{The archive base URL to check, defaulting to \code{\link{osem_archive_endpoint}}}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
\code{TRUE} if the archive is available, otherwise \code{stop()} is called.
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Check if the given openSenseMap archive endpoint is available
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue