# Participants to include in the analysis
# You must create a file for each participant named pXXX containing their device_id. This can be done manually or automatically
PIDS: [test01, test02, test03, test04]

# Global var with common time segments
TIME_SEGMENTS: &time_segments
  TYPE: PERIODIC # FREQUENCY, PERIODIC, EVENT
  FILE: "data/external/timesegments_periodic.csv"
  INCLUDE_PAST_PERIODIC_SEGMENTS: FALSE # Only relevant if TYPE=PERIODIC, if set to TRUE we consider time segments back enough in the past as to include the first day of data

# Use tz codes from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. Double check your code, for example EST is not US Eastern Time.
TIMEZONE: &timezone
  America/New_York

DATABASE_GROUP: &database_group
  MY_GROUP

# config section for the script that creates participant files automatically
PARTICIPANT_FILES: # run snakemake -j1 -R parse_participant_files
  PHONE_SECTION:
    ADD: FALSE
    PARSED_FROM: AWARE_DEVICE_TABLE #AWARE_DEVICE_TABLE or CSV_FILE
    PARSED_SOURCE: *database_group # DB credentials group or CSV file path. If CSV file, it should have: device_id, pid (optional), label (optional), start_date (optional), end_date (optional)
    IGNORED_DEVICE_IDS: []
  FITBIT_SECTION:
    ADD: FALSE
    SAME_AS_PHONE: FALSE # If TRUE, all config below is ignored
    PARSED_FROM: CSV_FILE
    PARSED_SOURCE: "external/my_fitbit_participants.csv" # CSV file should have: device_id, pid (optional), label (optional), start_date (optional), end_date (optional)

DEVICE_DATA:
  PHONE:
    SOURCE: 
      TYPE: DATABASE # Phone only supports DATABASE for now
      DATABASE_GROUP: *database_group
      DEVICE_ID_COLUMN: device_id # column name
    TIMEZONE: 
      TYPE: SINGLE # SINGLE or MULTIPLE
      VALUE: *timezone # IF TYPE=SINGLE, timezone code (e.g. America/New_York, see attribute TIMEZONE above). If TYPE=MULTIPLE, a table in your database with two columns (timestamp, timezone) where timestamp is a unix timestamp and timezone is one of https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  FITBIT:
    SOURCE: 
      TYPE: DATABASE # DATABASE or FILES (set each FITBIT_SENSOR TABLE attribute accordingly with a table name or a file path)
      DATABASE_GROUP: *database_group
      DEVICE_ID_COLUMN: device_id # column name
    TIMEZONE: 
      TYPE: SINGLE # Fitbit only supports SINGLE timezones
      VALUE: *timezone # timezone code (e.g. America/New_York, see attribute TIMEZONE above and https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)

PHONE_VALID_SENSED_BINS:
  COMPUTE: False # This flag is automatically ignored (set to True) if you are extracting PHONE_VALID_SENSED_DAYS or screen or Barnett's location features
  BIN_SIZE: &bin_size 5 # (in minutes)
  # Add as many PHONE sensors as you have, they all improve the computation of PHONE_VALID_SENSED_BINS and PHONE_VALID_SENSED_DAYS. 
  # If you are extracting screen or Barnett/Doryab location features, PHONE_SCREEN and PHONE_LOCATIONS tables are mandatory.
  # You can choose any of the keys shown below, just make sure its TABLE exists in your database!
  # PHONE_MESSAGES, PHONE_CALLS, PHONE_LOCATIONS, PHONE_BLUETOOTH, PHONE_ACTIVITY_RECOGNITION, PHONE_BATTERY, PHONE_SCREEN, PHONE_LIGHT,
  # PHONE_ACCELEROMETER, PHONE_APPLICATIONS_FOREGROUND, PHONE_WIFI_VISIBLE, PHONE_WIFI_CONNECTED, PHONE_CONVERSATION
  PHONE_SENSORS: []

PHONE_VALID_SENSED_DAYS:
  COMPUTE: False
  MIN_VALID_HOURS_PER_DAY: &min_valid_hours_per_day [16] # (out of 24) MIN_HOURS_PER_DAY
  MIN_VALID_BINS_PER_HOUR: &min_valid_bins_per_hour [6] # (out of 60min/BIN_SIZE bins)

# Communication SMS features config, TYPES and FEATURES keys need to match
PHONE_MESSAGES:
  TABLE: messages
  PROVIDERS:
    RAPIDS:
      COMPUTE: TRUE
      MESSAGES_TYPES : [received, sent]
      FEATURES: 
        received: [count, distinctcontacts, timefirstmessage, timelastmessage, countmostfrequentcontact]
        sent: [count, distinctcontacts, timefirstmessage, timelastmessage, countmostfrequentcontact]
      SRC_LANGUAGE: "r"
      SRC_FOLDER: "rapids" # inside src/features/phone_messages

# Communication call features config, TYPES and FEATURES keys need to match
PHONE_CALLS:
  TABLE: calls
  PROVIDERS:
    RAPIDS:
      COMPUTE: TRUE
      CALL_TYPES: [missed, incoming, outgoing]
      FEATURES:
        missed:  [count, distinctcontacts, timefirstcall, timelastcall, countmostfrequentcontact]
        incoming: [count, distinctcontacts, meanduration, sumduration, minduration, maxduration, stdduration, modeduration, entropyduration, timefirstcall, timelastcall, countmostfrequentcontact]
        outgoing: [count, distinctcontacts, meanduration, sumduration, minduration, maxduration, stdduration, modeduration, entropyduration, timefirstcall, timelastcall, countmostfrequentcontact]
      SRC_LANGUAGE: "r"
      SRC_FOLDER: "rapids" # inside src/features/phone_calls

PHONE_LOCATIONS:
  TABLE: locations
  LOCATIONS_TO_USE: FUSED_RESAMPLED # ALL, GPS OR FUSED_RESAMPLED  
  FUSED_RESAMPLED_CONSECUTIVE_THRESHOLD: 30 # minutes, only replicate location samples to the next sensed bin if the phone did not stop collecting data for more than this threshold
  FUSED_RESAMPLED_TIME_SINCE_VALID_LOCATION: 720 # minutes, only replicate location samples to consecutive sensed bins if they were logged within this threshold after a valid location row
  PROVIDERS:
    DORYAB:
      COMPUTE: False
      FEATURES: ["locationvariance","loglocationvariance","totaldistance","averagespeed","varspeed","circadianmovement","numberofsignificantplaces","numberlocationtransitions","radiusgyration","timeattop1location","timeattop2location","timeattop3location","movingtostaticratio","outlierstimepercent","maxlengthstayatclusters","minlengthstayatclusters","meanlengthstayatclusters","stdlengthstayatclusters","locationentropy","normalizedlocationentropy"]
      DBSCAN_EPS: 10 # meters
      DBSCAN_MINSAMPLES: 5
      THRESHOLD_STATIC : 1 # km/h
      MAXIMUM_GAP_ALLOWED: 300
      MINUTES_DATA_USED: False
      SAMPLING_FREQUENCY: 0
      SRC_FOLDER: "doryab" # inside src/features/phone_locations
      SRC_LANGUAGE: "python"

    BARNETT:
      COMPUTE: False
      FEATURES: ["hometime","disttravelled","rog","maxdiam","maxhomedist","siglocsvisited","avgflightlen","stdflightlen","avgflightdur","stdflightdur","probpause","siglocentropy","circdnrtn","wkenddayrtn"]
      ACCURACY_LIMIT: 51 # meters, drops location coordinates with an accuracy higher than this. This number means there's a 68% probability the true location is within this radius
      TIMEZONE: *timezone
      MINUTES_DATA_USED: False # Use this for quality control purposes, how many minutes of data (location coordinates gruped by minute) were used to compute features
      SRC_FOLDER: "barnett" # inside src/features/phone_locations
      SRC_LANGUAGE: "r"

PHONE_BLUETOOTH:
  TABLE: bluetooth
  PROVIDERS:
    RAPIDS:
      COMPUTE: TRUE
      FEATURES: ["countscans", "uniquedevices", "countscansmostuniquedevice"]
      SRC_FOLDER: "rapids" # inside src/features/phone_bluetooth
      SRC_LANGUAGE: "r"


PHONE_ACTIVITY_RECOGNITION:
  TABLE: 
    ANDROID: plugin_google_activity_recognition
    IOS: plugin_ios_activity_recognition
  EPISODE_THRESHOLD_BETWEEN_ROWS: 5 # minutes. Max time difference for two consecutive rows to be considered within the same battery episode.
  PROVIDERS:
    RAPIDS:
      COMPUTE: False
      FEATURES: ["count", "mostcommonactivity", "countuniqueactivities", "durationstationary", "durationmobile", "durationvehicle"]
      ACTIVITY_CLASSES:
        STATIONARY: ["still", "tilting"]
        MOBILE: ["on_foot", "walking", "running", "on_bicycle"]
        VEHICLE: ["in_vehicle"]
      SRC_FOLDER: "rapids" # inside src/features/phone_activity_recognition
      SRC_LANGUAGE: "python"

PHONE_BATTERY:
  TABLE: battery
  EPISODE_THRESHOLD_BETWEEN_ROWS: 30 # minutes. Max time difference for two consecutive rows to be considered within the same battery episode.
  PROVIDERS:
    RAPIDS:
      COMPUTE: False
      FEATURES: ["countdischarge", "sumdurationdischarge", "countcharge", "sumdurationcharge", "avgconsumptionrate", "maxconsumptionrate"]
      SRC_FOLDER: "rapids" # inside src/features/phone_battery
      SRC_LANGUAGE: "python"

PHONE_SCREEN:
  TABLE: screen
  PROVIDERS:
    RAPIDS:
      COMPUTE: False
      REFERENCE_HOUR_FIRST_USE: 0
      IGNORE_EPISODES_SHORTER_THAN: 0 # in minutes, set to 0 to disable
      IGNORE_EPISODES_LONGER_THAN: 0 # in minutes, set to 0 to disable
      FEATURES: ["countepisode", "sumduration", "maxduration", "minduration", "avgduration", "stdduration", "firstuseafter"] # "episodepersensedminutes" needs to be added later
      EPISODE_TYPES: ["unlock"]
      SRC_FOLDER: "rapids" # inside src/features/phone_screen
      SRC_LANGUAGE: "python"

PHONE_LIGHT:
  TABLE: light
  PROVIDERS:
    RAPIDS:
      COMPUTE: TRUE
      FEATURES: ["count", "maxlux", "minlux", "avglux", "medianlux", "stdlux"]
      SRC_FOLDER: "rapids" # inside src/features/phone_light
      SRC_LANGUAGE: "python"

PHONE_ACCELEROMETER:
  TABLE: accelerometer
  PROVIDERS:
    RAPIDS:
      COMPUTE: False
      FEATURES: ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"]
      SRC_FOLDER: "rapids" # inside src/features/phone_accelerometer
      SRC_LANGUAGE: "python"
    
    PANDA:
      COMPUTE: False
      VALID_SENSED_MINUTES: False
      FEATURES:
        exertional_activity_episode: ["sumduration", "maxduration", "minduration", "avgduration", "medianduration", "stdduration"]
        nonexertional_activity_episode: ["sumduration", "maxduration", "minduration", "avgduration", "medianduration", "stdduration"]
      SRC_FOLDER: "panda" # inside src/features/phone_accelerometer
      SRC_LANGUAGE: "python"

PHONE_APPLICATIONS_FOREGROUND:
  TABLE: applications_foreground
  APPLICATION_CATEGORIES:
    CATALOGUE_SOURCE: FILE # FILE (genres are read from CATALOGUE_FILE) or GOOGLE (genres are scrapped from the Play Store)
    CATALOGUE_FILE: "data/external/stachl_application_genre_catalogue.csv"
    UPDATE_CATALOGUE_FILE: False # if CATALOGUE_SOURCE is equal to FILE, whether or not to update CATALOGUE_FILE, if CATALOGUE_SOURCE is equal to GOOGLE all scraped genres will be saved to CATALOGUE_FILE
    SCRAPE_MISSING_CATEGORIES: False # whether or not to scrape missing genres, only effective if CATALOGUE_SOURCE is equal to FILE. If CATALOGUE_SOURCE is equal to GOOGLE, all genres are scraped anyway
  PROVIDERS:
    RAPIDS:
      COMPUTE: TRUE
      SINGLE_CATEGORIES: ["all", "email"]
      MULTIPLE_CATEGORIES:
        social: ["socialnetworks", "socialmediatools"]
        entertainment: ["entertainment", "gamingstrategy"]
      SINGLE_APPS: ["top1global", "com.facebook.moments"] # There's no entropy for single apps
      EXCLUDED_CATEGORIES: ["systemapp", "tvvideoapps"]
      EXCLUDED_APPS: ["com.fitbit.FitbitMobile", "com.aware.plugin.upmc.cancer"]
      FEATURES: ["count", "timeoffirstuse", "timeoflastuse", "frequencyentropy"]
      SRC_FOLDER: "rapids" # inside src/features/phone_applications_foreground
      SRC_LANGUAGE: "python"

PHONE_WIFI_VISIBLE:
  TABLE: "wifi"
  PROVIDERS:
    RAPIDS:
      COMPUTE: TRUE
      FEATURES: ["countscans", "uniquedevices", "countscansmostuniquedevice"]
      SRC_FOLDER: "rapids" # inside src/features/phone_wifi_visible
      SRC_LANGUAGE: "r"

PHONE_WIFI_CONNECTED:
  TABLE: "sensor_wifi"
  PROVIDERS:
    RAPIDS:
      COMPUTE: TRUE
      FEATURES: ["countscans", "uniquedevices", "countscansmostuniquedevice"]
      SRC_FOLDER: "rapids" # inside src/features/phone_wifi_connected
      SRC_LANGUAGE: "r"

PHONE_CONVERSATION:
  TABLE: 
    ANDROID: plugin_studentlife_audio_android
    IOS: plugin_studentlife_audio
  PROVIDERS:
    RAPIDS:
      COMPUTE: TRUE
      FEATURES: ["minutessilence", "minutesnoise", "minutesvoice", "minutesunknown","sumconversationduration","avgconversationduration",
        "sdconversationduration","minconversationduration","maxconversationduration","timefirstconversation","timelastconversation","noisesumenergy",
        "noiseavgenergy","noisesdenergy","noiseminenergy","noisemaxenergy","voicesumenergy",
        "voiceavgenergy","voicesdenergy","voiceminenergy","voicemaxenergy","silencesensedfraction","noisesensedfraction",
        "voicesensedfraction","unknownsensedfraction","silenceexpectedfraction","noiseexpectedfraction","voiceexpectedfraction",
        "unknownexpectedfraction","countconversation"]
      RECORDING_MINUTES: 1
      PAUSED_MINUTES : 3
      SRC_FOLDER: "rapids" # inside src/features/phone_conversation
      SRC_LANGUAGE: "python"

############## FITBIT ##########################################################
################################################################################

FITBIT_HEARTRATE:
  TABLE_FORMAT: JSON # JSON or CSV
  TABLE:
    JSON: fitbit_heartrate
    CSV:
      SUMMARY: heartrate_summary.csv
      INTRADAY: heartrate_intraday.csv
  PROVIDERS:
    RAPIDS:
      COMPUTE: False
      SUMMARY_FEATURES: ["restinghr"] # calories features' accuracy depend on the accuracy of the participants fitbit profile (e.g. height, weight) use these with care: ["caloriesoutofrange", "caloriesfatburn", "caloriescardio", "caloriespeak"] 
      INTRADAY_FEATURES: ["maxhr", "minhr", "avghr", "medianhr", "modehr", "stdhr", "diffmaxmodehr", "diffminmodehr", "entropyhr", "minutesonoutofrangezone", "minutesonfatburnzone", "minutesoncardiozone", "minutesonpeakzone"]


FITBIT_STEPS:
  TABLE_FORMAT: JSON # JSON or CSV
  TABLE:
    JSON: fitbit_steps
    CSV:
      SUMMARY: steps_summary.csv
      INTRADAY: steps_intraday.csv
  EXCLUDE_SLEEP: # you can exclude sleep periods from the step features computation
    EXCLUDE: False
    TYPE: FIXED # FIXED OR FITBIT_BASED (configure FITBIT_SLEEP section)
    FIXED:
      START: "23:00"
      END: "07:00"

  PROVIDERS:
    RAPIDS:
      COMPUTE: False
      FEATURES:
        ALL_STEPS: ["sumallsteps", "maxallsteps", "minallsteps", "avgallsteps", "stdallsteps"]
        SEDENTARY_BOUT: ["countepisode", "sumduration", "maxduration", "minduration", "avgduration", "stdduration"]
        ACTIVE_BOUT: ["countepisode", "sumduration", "maxduration", "minduration", "avgduration", "stdduration"]
      THRESHOLD_ACTIVE_BOUT: 10 # steps
      INCLUDE_ZERO_STEP_ROWS: False

FITBIT_SLEEP:
  TABLE_FORMAT: JSON # JSON or CSV
  TABLE:
    JSON: fitbit_sleep
    CSV:
      SUMMARY: sleep_summary.csv
      INTRADAY: sleep_intraday.csv
  PROVIDERS:
    RAPIDS:
      COMPUTE: False
      SLEEP_TYPES: ["main", "nap", "all"]
      SUMMARY_FEATURES: ["sumdurationafterwakeup", "sumdurationasleep", "sumdurationawake", "sumdurationtofallasleep", "sumdurationinbed", "avgefficiency", "countepisode"]

FITBIT_CALORIES:
  TABLE_FORMAT: JSON # JSON or CSV
  TABLE:
    JSON: fitbit_calories
    CSV:
      SUMMARY: calories_summary.csv
      INTRADAY: calories_intraday.csv
  PROVIDERS:
    RAPIDS:
      COMPUTE: False
      FEATURES: []

### Visualizations #############################################################
################################################################################

HEATMAP_FEATURES_CORRELATIONS:
  PLOT: False
  MIN_ROWS_RATIO: 0.5
  MIN_VALID_HOURS_PER_DAY: *min_valid_hours_per_day
  MIN_VALID_BINS_PER_HOUR: *min_valid_bins_per_hour
  PHONE_FEATURES: [accelerometer, activity_recognition, applications_foreground, battery, calls_incoming, calls_missed, calls_outgoing, conversation, light, location_doryab, messages_received, messages_sent, screen]
  FITBIT_FEATURES: [fitbit_heartrate, fitbit_step, fitbit_sleep]
  CORR_THRESHOLD: 0.1
  CORR_METHOD: "pearson" # choose from {"pearson", "kendall", "spearman"}

HISTOGRAM_VALID_SENSED_HOURS:
  PLOT: False
  MIN_VALID_HOURS_PER_DAY: *min_valid_hours_per_day
  MIN_VALID_BINS_PER_HOUR: *min_valid_bins_per_hour

HEATMAP_DAYS_BY_SENSORS:
  PLOT: False
  MIN_VALID_HOURS_PER_DAY: *min_valid_hours_per_day
  MIN_VALID_BINS_PER_HOUR: *min_valid_bins_per_hour
  EXPECTED_NUM_OF_DAYS: -1
  DB_TABLES: [accelerometer, applications_foreground, battery, bluetooth, calls, light, locations, messages, screen, wifi, sensor_wifi, plugin_google_activity_recognition, plugin_ios_activity_recognition, plugin_studentlife_audio_android, plugin_studentlife_audio]

HEATMAP_SENSED_BINS:
  PLOT: False
  BIN_SIZE: *bin_size

OVERALL_COMPLIANCE_HEATMAP:
  PLOT: False
  ONLY_SHOW_VALID_DAYS: False
  EXPECTED_NUM_OF_DAYS: -1
  BIN_SIZE: *bin_size
  MIN_VALID_HOURS_PER_DAY: *min_valid_hours_per_day
  MIN_VALID_BINS_PER_HOUR: *min_valid_bins_per_hour

