Refactor bluetooth features: replace "metrics" with "features"

Co-authored-by: Meng Li <AnnieLM1996@gmail.com>
Co-authored-by: JulioV <juliovhz@gmail.com>
pull/95/head
Mingze Cao 2020-04-03 12:07:09 -05:00
parent 106f552442
commit 595bdd6f5b
3 changed files with 22 additions and 22 deletions

View File

@ -289,7 +289,7 @@ See `Bluetooth Config Code`_
.. - Apply readable datetime to Bluetooth dataset: ``expand("data/raw/{pid}/{sensor}_with_datetime.csv", pid=config["PIDS"], sensor=config["SENSORS"]),``
- Extract Bluetooth Metrics
- Extract Bluetooth Features
| ``expand("data/processed/{pid}/bluetooth_{segment}.csv",``
| ``pid=config["PIDS"],``
@ -305,9 +305,9 @@ See `Bluetooth Config Code`_
- **Script:** ``src/data/readable_datetime.R`` See the readable_datetime.R_ script.
- **Rule:** ``rules/features.snakefile/bluetooth_metrics`` - See the bluetooth_metric_ rule.
- **Rule:** ``rules/features.snakefile/bluetooth_features`` - See the bluetooth_feature_ rule.
- **Script:** ``src/features/bluetooth_metrics.R`` - See the bluetooth_metrics.R_ script.
- **Script:** ``src/features/bluetooth_features.R`` - See the bluetooth_features.R_ script.
.. _bluetooth-parameters:
@ -318,14 +318,14 @@ See `Bluetooth Config Code`_
Name Description
============ ===================
day_segment The particular ``day_segments`` that will be analyzed. The available options are ``daily``, ``morning``, ``afternoon``, ``evening``, ``night``
metrics The different measures that can be retrieved from the Bluetooth dataset. See :ref:`Available Bluetooth Metrics <bluetooth-available-metrics>` Table below
features The different measures that can be retrieved from the Bluetooth dataset. See :ref:`Available Bluetooth Features <bluetooth-available-features>` Table below
============ ===================
.. _bluetooth-available-metrics:
.. _bluetooth-available-features:
**Available Bluetooth Metrics**
**Available Bluetooth Features**
The following table shows a list of the available metrics for Bluetooth.
The following table shows a list of the available features for Bluetooth.
=========================== ========= =============
Name Units Description
@ -1153,8 +1153,8 @@ stddurationactivebout minutes Std duration active bout: The standard
.. _call_metrics: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/features.snakefile#L13
.. _call_metrics.R: https://github.com/carissalow/rapids/blob/master/src/features/call_metrics.R
.. _`Bluetooth Config Code`: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/config.yaml#L76
.. _bluetooth_metric: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/features.snakefile#L63
.. _bluetooth_metrics.R: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/src/features/bluetooth_metrics.R
.. _bluetooth_feature: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/features.snakefile#L63
.. _bluetooth_features.R: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/src/features/bluetooth_features.R
.. _`Accelerometer Config Code`: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/config.yaml#L98
.. _accelerometer_metrics: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/rules/features.snakefile#L124
.. _accelerometer_metrics.py: https://github.com/carissalow/rapids/blob/765bb462636d5029a05f54d4c558487e3786b90b/src/features/accelerometer_metrics.py

View File

@ -62,16 +62,16 @@ rule location_barnett_metrics:
script:
"../src/features/location_barnett_metrics.R"
rule bluetooth_metrics:
rule bluetooth_features:
input:
"data/raw/{pid}/bluetooth_with_datetime.csv"
params:
day_segment = "{day_segment}",
metrics = config["BLUETOOTH"]["METRICS"]
features = config["BLUETOOTH"]["FEATURES"]
output:
"data/processed/{pid}/bluetooth_{day_segment}.csv"
script:
"../src/features/bluetooth_metrics.R"
"../src/features/bluetooth_features.R"
rule activity_metrics:
input:

View File

@ -9,14 +9,14 @@ filter_by_day_segment <- function(data, day_segment) {
return(data %>% group_by(local_date))
}
compute_bluetooth_metric <- function(data, metric, day_segment){
if(metric %in% c("countscans", "uniquedevices")){
compute_bluetooth_feature <- function(data, feature, day_segment){
if(feature %in% c("countscans", "uniquedevices")){
data <- data %>% filter_by_day_segment(day_segment)
data <- switch(metric,
"countscans" = data %>% summarise(!!paste("bluetooth", day_segment, metric, sep = "_") := n()),
"uniquedevices" = data %>% summarise(!!paste("bluetooth", day_segment, metric, sep = "_") := n_distinct(bt_address)))
data <- switch(feature,
"countscans" = data %>% summarise(!!paste("bluetooth", day_segment, feature, sep = "_") := n()),
"uniquedevices" = data %>% summarise(!!paste("bluetooth", day_segment, feature, sep = "_") := n_distinct(bt_address)))
return(data)
} else if(metric == "countscansmostuniquedevice"){
} else if(feature == "countscansmostuniquedevice"){
# Get the most scanned device
data <- data %>% group_by(bt_address) %>%
mutate(N=n()) %>%
@ -24,17 +24,17 @@ compute_bluetooth_metric <- function(data, metric, day_segment){
filter(N == max(N))
return(data %>%
filter_by_day_segment(day_segment) %>%
summarise(!!paste("bluetooth", day_segment, metric, sep = "_") := n()))
summarise(!!paste("bluetooth", day_segment, feature, sep = "_") := n()))
}
}
data <- read.csv(snakemake@input[[1]], stringsAsFactors = FALSE)
day_segment <- snakemake@params[["day_segment"]]
metrics <- snakemake@params[["metrics"]]
requested_features <- snakemake@params[["features"]]
features = data.frame(local_date = character(), stringsAsFactors = FALSE)
for(metric in metrics){
feature <- compute_bluetooth_metric(data, metric, day_segment)
for(requested_feature in requested_features){
feature <- compute_bluetooth_feature(data, requested_feature, day_segment)
features <- merge(features, feature, by="local_date", all = TRUE)
}