From 4501704e758c6116d8817482c5b2ce65176099dc Mon Sep 17 00:00:00 2001 From: noerw Date: Thu, 24 Aug 2017 13:57:46 +0200 Subject: [PATCH] add boxes$lastActive distribution to monitor --- tools/monitor/get-boxes.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/monitor/get-boxes.R b/tools/monitor/get-boxes.R index d49a9b8..2277f02 100644 --- a/tools/monitor/get-boxes.R +++ b/tools/monitor/get-boxes.R @@ -7,6 +7,10 @@ if (is.null(as.list(environment())$osem_boxes_ts)) b = osem_boxes() +# for $`active` computations +diffNow = (opensensmapr:::utc_date(Sys.time()) - b$lastMeasurement) %>% as.numeric(unit='hours') +neverActive = b[is.na(b$lastMeasurement), ] %>% nrow() + # only keep aggregated data b_agg = data.frame(time = Sys.time(), boxcount = nrow(b)) b_agg$model = b$model %>% table() %>% as.list() %>% list() @@ -14,6 +18,14 @@ b_agg$exposure = b$exposure %>% table() %>% as.list() %>% list() b_agg$geometry = b %>% osem_as_sf() %>% st_geometry() %>% list() b_agg$phenomena = b %>% osem_phenomena() %>% list() +b_agg$active = list( + 'never' = neverActive, + '1h' = nrow(b[diffNow <= 1, ]) - neverActive, + '1d' = nrow(b[diffNow <= 24, ]) - neverActive, + '30d' = nrow(b[diffNow <= 720, ]) - neverActive, + '365d' = nrow(b[diffNow <= 8760, ]) - neverActive +) %>% list() + # combine with existing time series osem_boxes_ts = rbind(b_agg, osem_boxes_ts)