From 379b38046d20bd0ef2eacd2f078d3be691e10005 Mon Sep 17 00:00:00 2001 From: jan Date: Tue, 31 Jan 2023 17:12:59 +0100 Subject: [PATCH] add grouptag --- R/box.R | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/R/box.R b/R/box.R index e2d0260..7783cae 100644 --- a/R/box.R +++ b/R/box.R @@ -154,7 +154,10 @@ parse_senseboxdata = function (boxdata) { sensors = boxdata$sensors location = boxdata$currentLocation lastMeasurement = boxdata$lastMeasurementAt # rename for backwards compat < 0.5.1 - boxdata[c('loc', 'locations', 'currentLocation', 'sensors', 'image', 'boxType', 'lastMeasurementAt')] = NULL + grouptags = boxdata$grouptag + boxdata[c( + 'loc', 'locations', 'currentLocation', 'sensors', 'image', 'boxType', 'lastMeasurementAt', 'grouptag' + )] = NULL thebox = as.data.frame(boxdata, stringsAsFactors = F) # parse timestamps (updatedAt might be not defined) @@ -185,6 +188,23 @@ parse_senseboxdata = function (boxdata) { if (length(location$coordinates) == 3) thebox$height = location$coordinates[[3]] + # extract grouptag(s) from box + if (length(grouptags) == 0) + thebox$grouptag = NULL + if (length(grouptags) > 0) { + # if box does not have grouptag dont set attribute + if(grouptags[[1]] == '') { + thebox$grouptag = NULL + } + else { + thebox$grouptag = grouptags[[1]] + } + } + if (length(grouptags) > 1) + thebox$grouptag2 = grouptags[[2]] + if (length(grouptags) > 2) + thebox$grouptag3 = grouptags[[3]] + # attach a custom class for methods osem_as_sensebox(thebox) }