2020-10-23 16:41:00 +02:00
|
|
|
library("dplyr", warn.conflicts = F)
|
2020-06-24 21:46:27 +02:00
|
|
|
|
2020-12-03 00:41:03 +01:00
|
|
|
compute_wifi_feature <- function(data, feature, time_segment){
|
2021-06-03 17:49:30 +02:00
|
|
|
|
2020-06-24 21:46:27 +02:00
|
|
|
if(feature %in% c("countscans", "uniquedevices")){
|
2021-06-03 17:49:30 +02:00
|
|
|
data <- data %>% filter_data_by_segment(time_segment)
|
2020-09-01 00:51:06 +02:00
|
|
|
data <- data %>% group_by(local_segment)
|
2020-06-24 21:46:27 +02:00
|
|
|
data <- switch(feature,
|
2020-11-25 20:49:42 +01:00
|
|
|
"countscans" = data %>% summarise(!!feature := n()),
|
|
|
|
"uniquedevices" = data %>% summarise(!!feature := n_distinct(bssid)))
|
2020-06-24 21:46:27 +02:00
|
|
|
return(data)
|
2022-09-16 15:24:21 +02:00
|
|
|
|
2020-06-24 21:46:27 +02:00
|
|
|
} else if(feature == "countscansmostuniquedevice"){
|
|
|
|
# Get the most scanned device
|
2022-09-16 15:24:21 +02:00
|
|
|
mostuniquedevice <- data %>%
|
|
|
|
filter(bssid != "") %>%
|
2020-07-07 23:15:32 +02:00
|
|
|
group_by(bssid) %>%
|
2020-06-24 21:46:27 +02:00
|
|
|
mutate(N=n()) %>%
|
|
|
|
ungroup() %>%
|
2020-07-07 23:15:32 +02:00
|
|
|
filter(N == max(N)) %>%
|
|
|
|
head(1) %>% # if there are multiple device with the same amount of scans pick the first one only
|
|
|
|
pull(bssid)
|
2022-09-16 12:58:57 +02:00
|
|
|
|
2021-06-03 17:49:30 +02:00
|
|
|
data <- data %>% filter_data_by_segment(time_segment)
|
2022-09-16 12:58:57 +02:00
|
|
|
|
2020-06-24 21:46:27 +02:00
|
|
|
return(data %>%
|
2020-07-07 23:15:32 +02:00
|
|
|
filter(bssid == mostuniquedevice) %>%
|
2020-09-01 00:51:06 +02:00
|
|
|
group_by(local_segment) %>%
|
2022-09-16 15:24:21 +02:00
|
|
|
summarise(!!feature := n())
|
2022-09-16 12:58:57 +02:00
|
|
|
)
|
2022-09-16 15:24:21 +02:00
|
|
|
|
2020-06-24 21:46:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 00:41:03 +01:00
|
|
|
rapids_features <- function(sensor_data_files, time_segment, provider){
|
2020-10-08 00:11:06 +02:00
|
|
|
wifi_data <- read.csv(sensor_data_files[["sensor_data"]], stringsAsFactors = FALSE)
|
|
|
|
requested_features <- provider[["FEATURES"]]
|
|
|
|
# Output dataframe
|
|
|
|
features = data.frame(local_segment = character(), stringsAsFactors = FALSE)
|
2020-06-24 21:46:27 +02:00
|
|
|
|
2020-10-08 00:11:06 +02:00
|
|
|
# The name of the features this function can compute
|
|
|
|
base_features_names <- c("countscans", "uniquedevices", "countscansmostuniquedevice")
|
2020-06-24 21:46:27 +02:00
|
|
|
|
2020-10-08 00:11:06 +02:00
|
|
|
# The subset of requested features this function can compute
|
|
|
|
features_to_compute <- intersect(base_features_names, requested_features)
|
2020-06-24 21:46:27 +02:00
|
|
|
|
2020-10-08 00:11:06 +02:00
|
|
|
for(feature_name in features_to_compute){
|
2020-12-03 00:41:03 +01:00
|
|
|
feature <- compute_wifi_feature(wifi_data, feature_name, time_segment)
|
2020-10-08 00:11:06 +02:00
|
|
|
features <- merge(features, feature, by="local_segment", all = TRUE)
|
|
|
|
}
|
2022-09-20 10:03:48 +02:00
|
|
|
features <- features %>% mutate_all(~replace(., is.na(.), 0))
|
2020-10-08 00:11:06 +02:00
|
|
|
return(features)
|
2020-06-24 21:46:27 +02:00
|
|
|
}
|