From 595bdd6f5bf9e08c9484590f52560345968ef8b4 Mon Sep 17 00:00:00 2001 From: Mingze Cao <29229557+Martinze@users.noreply.github.com> Date: Fri, 3 Apr 2020 12:07:09 -0500 Subject: [PATCH] Refactor bluetooth features: replace "metrics" with "features" Co-authored-by: Meng Li Co-authored-by: JulioV --- docs/features/extracted.rst | 18 ++++++++--------- rules/features.snakefile | 6 +++--- ...uetooth_metrics.R => bluetooth_features.R} | 20 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) rename src/features/{bluetooth_metrics.R => bluetooth_features.R} (60%) diff --git a/docs/features/extracted.rst b/docs/features/extracted.rst index 9a2c4ccd..24247260 100644 --- a/docs/features/extracted.rst +++ b/docs/features/extracted.rst @@ -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 ` Table below +features The different measures that can be retrieved from the Bluetooth dataset. See :ref:`Available Bluetooth 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 diff --git a/rules/features.snakefile b/rules/features.snakefile index d793f75b..816d91bf 100644 --- a/rules/features.snakefile +++ b/rules/features.snakefile @@ -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: diff --git a/src/features/bluetooth_metrics.R b/src/features/bluetooth_features.R similarity index 60% rename from src/features/bluetooth_metrics.R rename to src/features/bluetooth_features.R index 21200364..8027dd10 100644 --- a/src/features/bluetooth_metrics.R +++ b/src/features/bluetooth_features.R @@ -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) }