From c618907853c731791f96369804de77016c0bf784 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Sat, 9 Feb 2019 22:03:33 +0100 Subject: [PATCH] compatibility with API version v6 --- R/box.R | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/R/box.R b/R/box.R index 290f6ef..0004b3c 100644 --- a/R/box.R +++ b/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]]