# See https://www.rapids.science/setup/configuration/#database-credentials
DATABASE_GROUP: &database_group
  MY_GROUP

# See https://www.rapids.science/setup/configuration/#timezone-of-your-study
TIMEZONE: &timezone
  America/New_York

# See https://www.rapids.science/setup/configuration/#participant-files
PIDS: [example01, example02]

# See https://www.rapids.science/setup/configuration/#automatic-creation-of-participant-files
CREATE_PARTICIPANT_FILES:
  SOURCE:
    TYPE: AWARE_DEVICE_TABLE #AWARE_DEVICE_TABLE or CSV_FILE
    DATABASE_GROUP: *database_group
    CSV_FILE_PATH: "data/external/example_participants.csv" # see docs for required format
    TIMEZONE: *timezone
  PHONE_SECTION:
    ADD: TRUE
    DEVICE_ID_COLUMN: device_id # column name
    IGNORED_DEVICE_IDS: []
  FITBIT_SECTION:
    ADD: TRUE
    DEVICE_ID_COLUMN: device_id # column name
    IGNORED_DEVICE_IDS: []

# See https://www.rapids.science/setup/configuration/#time-segments
TIME_SEGMENTS: &time_segments
  TYPE: PERIODIC # FREQUENCY, PERIODIC, EVENT
  FILE: "example_profile/exampleworkflow_timesegments.csv"
  INCLUDE_PAST_PERIODIC_SEGMENTS: FALSE # Only relevant if TYPE=PERIODIC, see docs



########################################################################################################################
#                                                 PHONE                                                                #
########################################################################################################################

# See https://www.rapids.science/setup/configuration/#device-data-source-configuration
PHONE_DATA_CONFIGURATION:
  SOURCE: 
    TYPE: DATABASE
    DATABASE_GROUP: *database_group
    DEVICE_ID_COLUMN: device_id # column name
  TIMEZONE: 
    TYPE: SINGLE # SINGLE or MULTIPLE
    VALUE: *timezone # IF TYPE=SINGLE, see docs

# Sensors ------

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_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: True
      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_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", "gamingknowledge", "gamingcasual", "gamingadventure", "gamingstrategy", "gamingtoolscommunity", "gamingroleplaying", "gamingaction", "gaminglogic", "gamingsports", "gamingsimulation"]
      SINGLE_APPS: ["top1global", "com.facebook.moments", "com.google.android.youtube", "com.twitter.android"] # There's no entropy for single apps
      EXCLUDED_CATEGORIES: ["system_apps"]
      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_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: True
      FEATURES: ["countdischarge", "sumdurationdischarge", "countcharge", "sumdurationcharge", "avgconsumptionrate", "maxconsumptionrate"]
      SRC_FOLDER: "rapids" # inside src/features/phone_battery
      SRC_LANGUAGE: "python"

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

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_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"

PHONE_DATA_YIELD:
  SENSORS: [PHONE_ACCELEROMETER, PHONE_ACTIVITY_RECOGNITION, PHONE_APPLICATIONS_FOREGROUND, PHONE_BATTERY, PHONE_BLUETOOTH, PHONE_CALLS, PHONE_CONVERSATION, PHONE_LIGHT, PHONE_LOCATIONS, PHONE_MESSAGES, PHONE_SCREEN, PHONE_WIFI_CONNECTED, PHONE_WIFI_VISIBLE]
  PROVIDERS:
    RAPIDS:
      COMPUTE: True
      FEATURES: [ratiovalidyieldedminutes, ratiovalidyieldedhours]
      MINUTE_RATIO_THRESHOLD_FOR_VALID_YIELDED_HOURS: 0.5 # 0 to 1 representing the number of minutes with at least
      SRC_LANGUAGE: "r"
      SRC_FOLDER: "rapids" # inside src/features/phone_data_yield

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_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: True
      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_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

PHONE_SCREEN:
  TABLE: screen
  PROVIDERS:
    RAPIDS:
      COMPUTE: True
      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_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_WIFI_VISIBLE:
  TABLE: "wifi"
  PROVIDERS:
    RAPIDS:
      COMPUTE: True
      FEATURES: ["countscans", "uniquedevices", "countscansmostuniquedevice"]
      SRC_FOLDER: "rapids" # inside src/features/phone_wifi_visible
      SRC_LANGUAGE: "r"



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

# See https://www.rapids.science/latest/setup/configuration/#device-data-source-configuration
FITBIT_DATA_CONFIGURATION:
  SOURCE: 
    TYPE: DATABASE # DATABASE or FILES (set each [FITBIT_SENSOR][TABLE] attribute with a table name or a file path accordingly)
    COLUMN_FORMAT: JSON # JSON or PLAIN_TEXT
    DATABASE_GROUP: *database_group
    DEVICE_ID_COLUMN: device_id # column name
  TIMEZONE: 
    TYPE: SINGLE # Fitbit only supports SINGLE timezones
    VALUE: *timezone # see docs
  HIDDEN:
    SINGLE_FITBIT_TABLE: TRUE

FITBIT_HEARTRATE_SUMMARY:
  TABLE: fitbit_data
  PROVIDERS:
    RAPIDS:
      COMPUTE: True
      FEATURES: ["maxrestinghr", "minrestinghr", "avgrestinghr", "medianrestinghr", "moderestinghr", "stdrestinghr", "diffmaxmoderestinghr", "diffminmoderestinghr", "entropyrestinghr"] # calories features' accuracy depend on the accuracy of the participants fitbit profile (e.g. height, weight) use these with care: ["sumcaloriesoutofrange", "maxcaloriesoutofrange", "mincaloriesoutofrange", "avgcaloriesoutofrange", "mediancaloriesoutofrange", "stdcaloriesoutofrange", "entropycaloriesoutofrange", "sumcaloriesfatburn", "maxcaloriesfatburn", "mincaloriesfatburn", "avgcaloriesfatburn", "mediancaloriesfatburn", "stdcaloriesfatburn", "entropycaloriesfatburn", "sumcaloriescardio", "maxcaloriescardio", "mincaloriescardio", "avgcaloriescardio", "mediancaloriescardio", "stdcaloriescardio", "entropycaloriescardio", "sumcaloriespeak", "maxcaloriespeak", "mincaloriespeak", "avgcaloriespeak", "mediancaloriespeak", "stdcaloriespeak", "entropycaloriespeak"]
      SRC_FOLDER: "rapids" # inside src/features/fitbit_heartrate_summary
      SRC_LANGUAGE: "python"

FITBIT_HEARTRATE_INTRADAY:
  TABLE: fitbit_data
  PROVIDERS:
    RAPIDS:
      COMPUTE: True
      FEATURES: ["maxhr", "minhr", "avghr", "medianhr", "modehr", "stdhr", "diffmaxmodehr", "diffminmodehr", "entropyhr", "minutesonoutofrangezone", "minutesonfatburnzone", "minutesoncardiozone", "minutesonpeakzone"]
      SRC_FOLDER: "rapids" # inside src/features/fitbit_heartrate_intraday
      SRC_LANGUAGE: "python"

FITBIT_SLEEP_SUMMARY:
  TABLE: fitbit_data
  SLEEP_EPISODE_TIMESTAMP: end # summary sleep episodes are considered as events based on either the start timestamp or end timestamp.
  PROVIDERS:
    RAPIDS:
      COMPUTE: True
      FEATURES: ["countepisode", "avgefficiency", "sumdurationafterwakeup", "sumdurationasleep", "sumdurationawake", "sumdurationtofallasleep", "sumdurationinbed", "avgdurationafterwakeup", "avgdurationasleep", "avgdurationawake", "avgdurationtofallasleep", "avgdurationinbed"]
      SLEEP_TYPES: ["main", "nap", "all"]
      SRC_FOLDER: "rapids" # inside src/features/fitbit_sleep_summary
      SRC_LANGUAGE: "python"

FITBIT_STEPS_SUMMARY:
  TABLE: fitbit_data
  PROVIDERS:
    RAPIDS:
      COMPUTE: True
      FEATURES: ["maxsumsteps", "minsumsteps", "avgsumsteps", "mediansumsteps", "stdsumsteps"]
      SRC_FOLDER: "rapids" # inside src/features/fitbit_steps_summary
      SRC_LANGUAGE: "python"

FITBIT_STEPS_INTRADAY:
  TABLE: fitbit_data
  PROVIDERS:
    RAPIDS:
      COMPUTE: True
      FEATURES:
        STEPS: ["sum", "max", "min", "avg", "std"]
        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
      SRC_FOLDER: "rapids" # inside src/features/fitbit_steps_intraday
      SRC_LANGUAGE: "python"



########################################################################################################################
#                                                 PLOTS                                                                #
########################################################################################################################

HISTOGRAM_PHONE_DATA_YIELD:
  PLOT: True

HEATMAP_SENSORS_PER_MINUTE_PER_TIME_SEGMENT:
  PLOT: True

HEATMAP_SENSOR_ROW_COUNT_PER_TIME_SEGMENT:
  PLOT: True
  SENSORS: [PHONE_ACCELEROMETER, PHONE_ACTIVITY_RECOGNITION, PHONE_APPLICATIONS_FOREGROUND, PHONE_BATTERY, PHONE_BLUETOOTH, PHONE_CALLS, PHONE_CONVERSATION, PHONE_LIGHT, PHONE_LOCATIONS, PHONE_MESSAGES, PHONE_SCREEN, PHONE_WIFI_CONNECTED, PHONE_WIFI_VISIBLE]

HEATMAP_PHONE_DATA_YIELD_PER_PARTICIPANT_PER_TIME_SEGMENT:
  PLOT: True

HEATMAP_FEATURE_CORRELATION_MATRIX:
  PLOT: TRUE
  MIN_ROWS_RATIO: 0.5
  CORR_THRESHOLD: 0.1
  CORR_METHOD: "pearson" # choose from {"pearson", "kendall", "spearman"}



########################################################################################################################
#                                              Analysis Workflow Example                                               #
########################################################################################################################

PARAMS_FOR_ANALYSIS:
  CATEGORICAL_OPERATORS: [mostcommon]

  DEMOGRAPHIC:
    TABLE: participant_info
    FEATURES: [age, gender, inpatientdays]
    CATEGORICAL_FEATURES: [gender]
    SOURCE:
      DATABASE_GROUP: *database_group
      TIMEZONE: *timezone
  
  TARGET:
    TABLE: participant_target
    SOURCE:
      DATABASE_GROUP: *database_group
      TIMEZONE: *timezone

  # Cleaning Parameters
  COLS_NAN_THRESHOLD: 0.3
  COLS_VAR_THRESHOLD: True
  ROWS_NAN_THRESHOLD: 0.3
  DATA_YIELDED_HOURS_RATIO_THRESHOLD: 0.75
  
  MODEL_NAMES: [LogReg, kNN , SVM, DT, RF, GB, XGBoost, LightGBM]
  CV_METHODS: [LeaveOneOut]
  RESULT_COMPONENTS: [fold_predictions, fold_metrics, overall_results, fold_feature_importances]

  MODEL_SCALER:
    LogReg: [notnormalized, minmaxscaler, standardscaler, robustscaler]
    kNN: [minmaxscaler, standardscaler, robustscaler]
    SVM:  [minmaxscaler, standardscaler, robustscaler]
    DT: [notnormalized]
    RF: [notnormalized]
    GB: [notnormalized]
    XGBoost: [notnormalized]
    LightGBM: [notnormalized]

  MODEL_HYPERPARAMS:
    LogReg:
      {"clf__C": [0.01, 0.1, 1, 10, 100], "clf__solver": ["newton-cg", "lbfgs", "liblinear", "saga"], "clf__penalty": ["l2"]}
    kNN:
      {"clf__n_neighbors": [3, 5, 7], "clf__weights": ["uniform", "distance"], "clf__metric": ["euclidean", "manhattan", "minkowski"]}
    SVM:
      {"clf__C": [0.01, 0.1, 1, 10, 100], "clf__gamma": ["scale", "auto"], "clf__kernel": ["rbf", "poly", "sigmoid"]}
    DT:
      {"clf__criterion": ["gini", "entropy"], "clf__max_depth": [null, 3, 7, 15], "clf__max_features": [null, "auto", "sqrt", "log2"]}
    RF:
      {"clf__n_estimators": [10, 100, 200],"clf__max_depth": [null, 3, 7, 15]}
    GB:
      {"clf__learning_rate": [0.01, 0.1, 1], "clf__n_estimators": [10, 100, 200], "clf__subsample": [0.5, 0.7, 1.0], "clf__max_depth": [null, 3, 5, 7]}
    XGBoost:
      {"clf__learning_rate": [0.01, 0.1, 1], "clf__n_estimators": [10, 100, 200], "clf__max_depth": [3, 5, 7]}
    LightGBM:
      {"clf__learning_rate": [0.01, 0.1, 1], "clf__n_estimators": [10, 100, 200], "clf__num_leaves": [3, 5, 7], "clf__colsample_bytree": [0.6, 0.8, 1]}
