mirror of
https://github.com/sensebox/opensensmapr
synced 2025-02-21 13:23:57 +01:00
compatibility with API version v6
This commit is contained in:
parent
3e56cd1a0e
commit
c618907853
1 changed files with 4 additions and 10 deletions
14
R/box.R
14
R/box.R
|
@ -147,13 +147,16 @@ parse_senseboxdata = function (boxdata) {
|
|||
# to allow a simple data.frame structure
|
||||
sensors = boxdata$sensors
|
||||
location = boxdata$currentLocation
|
||||
boxdata[c('loc', 'locations', 'currentLocation', 'sensors', 'image', 'boxType')] = NULL
|
||||
lastMeasurement = boxdata$lastMeasurementAt # rename for backwards compat < 0.5.1
|
||||
boxdata[c('loc', 'locations', 'currentLocation', 'sensors', 'image', 'boxType', 'lastMeasurementAt')] = NULL
|
||||
thebox = as.data.frame(boxdata, stringsAsFactors = F)
|
||||
|
||||
# parse timestamps (updatedAt might be not defined)
|
||||
thebox$createdAt = as.POSIXct(strptime(thebox$createdAt, format = '%FT%T', tz = 'GMT'))
|
||||
if (!is.null(thebox$updatedAt))
|
||||
thebox$updatedAt = as.POSIXct(strptime(thebox$updatedAt, format = '%FT%T', tz = 'GMT'))
|
||||
if (!is.null(lastMeasurement))
|
||||
thebox$lastMeasurement = as.POSIXct(strptime(lastMeasurement, format = '%FT%T', tz = 'GMT'))
|
||||
|
||||
# create a dataframe of sensors
|
||||
thebox$sensors = sensors %>%
|
||||
|
@ -169,15 +172,6 @@ parse_senseboxdata = function (boxdata) {
|
|||
lapply(function(s) s$title) %>%
|
||||
unlist %>% list # convert to vector
|
||||
|
||||
# FIXME: if one sensor has NA, max() returns bullshit
|
||||
get_last_measurement = function(s) {
|
||||
if (!is.null(s$lastMeasurement))
|
||||
as.POSIXct(strptime(s$lastMeasurement$createdAt, format = '%FT%T', tz = 'GMT'))
|
||||
else
|
||||
NA
|
||||
}
|
||||
thebox$lastMeasurement = max(lapply(sensors, get_last_measurement)[[1]])
|
||||
|
||||
# extract coordinates & transform to simple feature object
|
||||
thebox$lon = location$coordinates[[1]]
|
||||
thebox$lat = location$coordinates[[2]]
|
||||
|
|
Loading…
Add table
Reference in a new issue