mirror of
https://github.com/sensebox/opensensmapr
synced 2025-03-11 03:30:27 +01:00
osem_measurements: use factors for paged reqs
This commit is contained in:
parent
dc7b86d391
commit
a65cb9a280
2 changed files with 9 additions and 4 deletions
3
R/api.R
3
R/api.R
|
@ -32,7 +32,8 @@ get_measurements_ = function (..., endpoint) {
|
|||
# parse the CSV response manually & mute readr
|
||||
suppressWarnings({
|
||||
result = readr::read_csv(result, col_types = readr::cols(
|
||||
.default = readr::col_factor(NULL),
|
||||
# factor as default would raise issues with concatenation of multiple requests
|
||||
.default = readr::col_character(),
|
||||
createdAt = readr::col_datetime(),
|
||||
value = readr::col_double(),
|
||||
lat = readr::col_double(),
|
||||
|
|
|
@ -140,8 +140,8 @@ paged_measurements_req = function (query) {
|
|||
|
||||
# auto paging: make a request for one 31day interval each (max supprted length)
|
||||
# generate a list 31day intervals
|
||||
from = query$from
|
||||
to = query$to
|
||||
from = query$`from-date`
|
||||
to = query$`to-date`
|
||||
dates = list()
|
||||
while (from < to) {
|
||||
in31days = from + as.difftime(31, units = 'days')
|
||||
|
@ -150,7 +150,7 @@ paged_measurements_req = function (query) {
|
|||
}
|
||||
|
||||
# use the dates as pages for multiple requests
|
||||
lapply(dates, function(page) {
|
||||
df = lapply(dates, function(page) {
|
||||
query$`from-date` = date_as_isostring(page$from)
|
||||
query$`to-date` = date_as_isostring(page$to)
|
||||
res = do.call(get_measurements_, query)
|
||||
|
@ -159,4 +159,8 @@ paged_measurements_req = function (query) {
|
|||
res
|
||||
}) %>%
|
||||
dplyr::bind_rows()
|
||||
|
||||
# coerce all character columns (sensorId, unit, ...) to factors AFTER binding
|
||||
df[sapply(df, is.character)] <- lapply(df[sapply(df, is.character)], as.factor)
|
||||
df
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue