anonymous-submission-acl2025's picture
add 17
8a79f2e
from datetime import datetime, timedelta
from lib.utilities import serialize
config_dic = serialize.open_yaml("config.yaml")
experiment_name = config_dic["experiment_name"]
config_user_dict = serialize.open_yaml("config_user.yaml")
"""
Each survey should have the following values in the surveys dictionary:
- Name: the name of the survey, as it will appear in files (it should be identical to the key)
- Start: the datetime the survey is sent to participants
- End: the datetime the survey is closed to participants
- Code: the code that prefixes all survey specific variables that come from the survey
- OldPhase: The phase in the study before the survey was administered (OPTIONAL)
- NewPhase: The phase in the study after the survey was administered (OPTIONAL)
- FirstQuestion: in the raw survey data, all columns that appear to the left of the FirstQuestion will be dropped.
Used to remove unwanted embedded data. Exceptions are made for columns in the study_config.main_cols list
or the study_config.kept_survey_data list
- Last Question: in the raw survey data, all columns that appear to the right of the LastQuestion will be dropped.
Used to remove unwanted embedded data. Exceptions are made for columns in the study_config.main_cols list
or the study_config.kept_survey_data list
- CompleteQuestion: the raw survey column that indicates the user completed the survey, if the user filled in
this question. Typically the last mandatory question in the survey.
- RawEmailCol: the column in the raw qualtrics survey that contains the email address of the participant
- QualtricsID: an ID qualtrics provide for pulling the survey from qualtrics
- QualtricsName: the raw name of the survey when it is first downloaded from qualtrics
"""
main_surveys = ["Recruitment","Baseline","Midline","Endline1","Endline2"]
text_surveys = ["TextSurvey"+str(x) for x in range(1,10)]
filler_surveys = ["Phase"+str(x)+"Start" for x in range(5,15)]
surveys = {
"Recruitment": {
"Name": "Recruitment",
"Start": config_dic["surveys"]["Recruitment"]["Start"],
"End": config_dic["surveys"]["Recruitment"]["End"],
"Code": "R",
"OldPhase": "PreStudy",
"NewPhase": "Phase0",
"FirstQuestion": "Country",
"LastQuestion": "GeneralFeedbackLong",
"CompleteQuestion": "PhoneOffTime12",
"RawEmailCol": "EmailConfirm",
"QualtricsID": "SV_cMGlDlNJGybHned",
"QualtricsName": "Phone Addiction Experiment/ Recruitment", },
"Baseline": {
"Name": "Baseline",
"Start": config_dic["surveys"]["Baseline"]["Start"],
"End": config_dic["surveys"]["Baseline"]["End"],
"Code": "B",
"OldPhase": "Phase0",
"NewPhase": "Phase1",
"FirstQuestion": "QualityCheck",
"LastQuestion": "GeneralFeedbackLong",
"CompleteQuestion":"Source",
"RawEmailCol":"Email",
"QualtricsID": "SV_3EHxo2vK2MVq4U5",
"QualtricsName": "Phone Addiction Experiment/ Baseline",
},
"Midline": {
"Name": "Midline",
"Start": config_dic["surveys"]["Midline"]["Start"],
"End": config_dic["surveys"]["Midline"]["End"],
"Code": "M",
"OldPhase": "Phase1",
"NewPhase": "Phase2",
"FirstQuestion": "Commitment",
"LastQuestion":"GeneralFeedbackLong",
"CompleteQuestion": "PredictUseNext3",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_eQxY6aqS3idzuOp",
"QualtricsName": "Phone Addiction Experiment/ Midline",
},
"Endline1": {
"Name": "Endline1",
"Start": config_dic["surveys"]["Endline1"]["Start"],
"End": config_dic["surveys"]["Endline1"]["End"],
"Code": "E1",
"OldPhase": "Phase2",
"NewPhase": "Phase3",
"FirstQuestion": "WellBeing1",
"LastQuestion":"GeneralFeedbackLong",
"CompleteQuestion": "PredictUseNext3",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_4IqfwzIhTKAj2Id",
"QualtricsName": "Phone Addiction Experiment/ Endline1",},
"Endline2": {
"Name": "Endline2",
"Start": config_dic["surveys"]["Endline2"]["Start"],
"End": config_dic["surveys"]["Endline2"]["End"],
"Code": "E2",
"OldPhase": "Phase3",
"NewPhase": "Phase4",
"FirstQuestion": "WellBeing1",
"LastQuestion": "GeneralFeedbackLong",
"CompleteQuestion": "PDFeedbackScale",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_6St5LOtmKbYCS5D",
"QualtricsName": "Phone Addiction Experiment/ Endline2", },
"Phase5Start": {
"Name": "Phase5Start",
"Start": config_dic["surveys"]["Phase5Start"]["Start"],
"End": config_dic["surveys"]["Phase5Start"]["End"],
"Code": "P5",
"OldPhase": "Phase4",
"NewPhase": "Phase5",
"FirstQuestion": "",
"LastQuestion": "",
"CompleteQuestion": "",
"RawEmailCol": "",
"QualtricsID": "",
"QualtricsName": "", },
"Phase6Start": {
"Name": "Phase6Start",
"Start": config_dic["surveys"]["Phase6Start"]["Start"],
"End": config_dic["surveys"]["Phase6Start"]["End"],
"Code": "P6",
"OldPhase": "Phase5",
"NewPhase": "Phase6",
"FirstQuestion": "",
"LastQuestion": "",
"CompleteQuestion": "",
"RawEmailCol": "",
"QualtricsID": "",
"QualtricsName": "", },
"Phase7Start": {
"Name": "Phase7Start",
"Start": config_dic["surveys"]["Phase7Start"]["Start"],
"End": config_dic["surveys"]["Phase7Start"]["End"],
"Code": "P7",
"OldPhase": "Phase6",
"NewPhase": "Phase7",
"FirstQuestion": "",
"LastQuestion": "",
"CompleteQuestion": "",
"RawEmailCol": "",
"QualtricsID": "",
"QualtricsName": "", },
"Phase8Start": {
"Name": "Phase8Start",
"Start": config_dic["surveys"]["Phase8Start"]["Start"],
"End": config_dic["surveys"]["Phase8Start"]["End"],
"Code": "P8",
"OldPhase": "Phase7",
"NewPhase": "Phase8",
"FirstQuestion": "",
"LastQuestion": "",
"CompleteQuestion": "",
"RawEmailCol": "",
"QualtricsID": "",
"QualtricsName": "", },
"Phase9Start": {
"Name": "Phase9Start",
"Start": config_dic["surveys"]["Phase9Start"]["Start"],
"End": config_dic["surveys"]["Phase9Start"]["End"],
"Code": "P9",
"OldPhase": "Phase8",
"NewPhase": "Phase9",
"FirstQuestion": "",
"LastQuestion": "",
"CompleteQuestion": "",
"RawEmailCol": "",
"QualtricsID": "",
"QualtricsName": "", },
"Phase10Start": {
"Name": "Phase10Start",
"Start": config_dic["surveys"]["Phase10Start"]["Start"],
"End": config_dic["surveys"]["Phase10Start"]["End"],
"Code": "P10",
"OldPhase": "Phase9",
"NewPhase": "Phase10",
"FirstQuestion": "",
"LastQuestion": "",
"CompleteQuestion": "",
"RawEmailCol": "",
"QualtricsID": "",
"QualtricsName": "", },
"Enrollment": {
"Name": "Enrollment",
"Start": config_dic["surveys"]["Enrollment"]["Start"],
"End": config_dic["surveys"]["Enrollment"]["End"],
"Code": "ET",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "Q1",
"LastQuestion": "Q1",
"CompleteQuestion": "AppCode",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_cRXVtKEhyupnrCJ",
"QualtricsName": "PhoneAddiction Enrollment Text"},
"WeeklyText": {
"Name": "WeeklyText",
"Start": config_dic["surveys"]["WeeklyText"]["Start"],
"End": config_dic["surveys"]["WeeklyText"]["End"],
"Code": "WT",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "Q1",
"LastQuestion": "Q9",
"CompleteQuestion": "AppCode",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "",
"QualtricsName": "Phone Addiction Pilot6 - Texts Weekly Addiction Msgs"},
"PDBug": {
"Name": "PDBug",
"Start": config_dic["surveys"]["PDBug"]["Start"],
"End": config_dic["surveys"]["PDBug"]["End"],
"Code": "PD",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "PDBug",
"LastQuestion": "PDBugLong",
"CompleteQuestion": "PDBug",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_8jsnuErKgFLWm2h",
"QualtricsName": "Phone Addiction PDBug"},
"TextSurvey1": {
"Name": "TextSurvey1",
"Start": config_dic["surveys"]["TextSurvey1"]["Start"],
"End": config_dic["surveys"]["TextSurvey1"]["End"],
"Code": "T1",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "AddictionText1",
"LastQuestion": "AddictionText1",
"CompleteQuestion": "AddictionText1",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_1zhnYQqQOfchrDL",
"QualtricsName": "PhoneAddiction Text Survey - 1"},
"TextSurvey2": {
"Name": "TextSurvey1",
"Start": config_dic["surveys"]["TextSurvey2"]["Start"],
"End": config_dic["surveys"]["TextSurvey2"]["End"],
"Code": "T2",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "AddictionText2",
"LastQuestion": "AddictionText2",
"CompleteQuestion": "AddictionText2",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_39qIJ0F4pu0hFCl",
"QualtricsName": "PhoneAddiction Text Survey - 2"},
"TextSurvey3": {
"Name": "TextSurvey3",
"Start": config_dic["surveys"]["TextSurvey3"]["Start"],
"End": config_dic["surveys"]["TextSurvey3"]["End"],
"Code": "T3",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "AddictionText3",
"LastQuestion": "AddictionText3",
"CompleteQuestion": "AddictionText3",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_2bCk47THvm8oN3D",
"QualtricsName": "PhoneAddiction Text Survey - 3"},
"TextSurvey4": {
"Name": "TextSurvey4",
"Start": config_dic["surveys"]["TextSurvey4"]["Start"],
"End": config_dic["surveys"]["TextSurvey4"]["End"],
"Code": "T4",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "AddictionText4",
"LastQuestion": "AddictionText4",
"CompleteQuestion": "AddictionText4",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_9nl3sAj94B5sVrD",
"QualtricsName": "PhoneAddiction Text Survey - 4"},
"TextSurvey5": {
"Name": "TextSurvey5",
"Start": config_dic["surveys"]["TextSurvey5"]["Start"],
"End": config_dic["surveys"]["TextSurvey5"]["End"],
"Code": "T5",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "AddictionText5",
"LastQuestion": "AddictionText5",
"CompleteQuestion": "AddictionText5",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_6GtwyNSpJZ79ptP",
"QualtricsName": "PhoneAddiction Text Survey - 5"},
"TextSurvey6": {
"Name": "TextSurvey6",
"Start": config_dic["surveys"]["TextSurvey6"]["Start"],
"End": config_dic["surveys"]["TextSurvey6"]["End"],
"Code": "T6",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "AddictionText6",
"LastQuestion": "AddictionText6",
"CompleteQuestion": "AddictionText6",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_5gyEVUJovOxg7vT",
"QualtricsName": "PhoneAddiction Text Survey - 6"},
"TextSurvey7": {
"Name": "TextSurvey7",
"Start": config_dic["surveys"]["TextSurvey7"]["Start"],
"End": config_dic["surveys"]["TextSurvey7"]["End"],
"Code": "T7",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "AddictionText7",
"LastQuestion": "AddictionText7",
"CompleteQuestion": "AddictionText7",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_cxctTobi21Mt7OR",
"QualtricsName": "PhoneAddiction Text Survey - 7"},
"TextSurvey8": {
"Name": "TextSurvey8",
"Start": config_dic["surveys"]["TextSurvey8"]["Start"],
"End": config_dic["surveys"]["TextSurvey8"]["End"],
"Code": "T8",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "AddictionText8",
"LastQuestion": "AddictionText8",
"CompleteQuestion": "AddictionText8",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_7824o4AljFSjxyZ",
"QualtricsName": "PhoneAddiction Text Survey - 8"},
"TextSurvey9": {
"Name": "TextSurvey9",
"Start": config_dic["surveys"]["TextSurvey9"]["Start"],
"End": config_dic["surveys"]["TextSurvey9"]["End"],
"Code": "T9",
"OldPhase": "na",
"NewPhase": "na",
"FirstQuestion": "AddictionText9",
"LastQuestion": "AddictionText9",
"CompleteQuestion": "AddictionText9",
"RawEmailCol": "RecipientEmail",
"QualtricsID": "SV_6ydCZmtdAfwAQU5",
"QualtricsName": "PhoneAddiction Text Survey - 9"},
}
phases = {
"Phase0": {
"Label": "Recruitment Phase",
"StartSurvey":surveys["Recruitment"],
"EndSurvey":surveys["Baseline"],
},
"Phase1": {
"Label": "Baseline Phase",
"StartSurvey":surveys["Baseline"],
"EndSurvey":surveys["Midline"],
},
"Phase2": {
"Label": "Treatment Phase",
"StartSurvey": surveys["Midline"],
"EndSurvey": surveys["Endline1"],
},
"Phase3": {
"Label": "Treatment II Phase",
"StartSurvey": surveys["Endline1"],
"EndSurvey": surveys["Endline2"],
},
"Phase4": {
"Label": "Phase 4",
"StartSurvey": surveys["Endline2"],
"EndSurvey": surveys["Phase5Start"],
},
"Phase5": {
"Label": "Phase 5",
"StartSurvey": surveys["Phase5Start"],
"EndSurvey": surveys["Phase6Start"],
},
"Phase6": {
"Label": "Phase 6",
"StartSurvey": surveys["Phase6Start"],
"EndSurvey": surveys["Phase7Start"],
},
"Phase7": {
"Label": "Phase 7",
"StartSurvey": surveys["Phase7Start"],
"EndSurvey": surveys["Phase8Start"],
},
"Phase8": {
"Label": "Phase 8",
"StartSurvey": surveys["Phase8Start"],
"EndSurvey": surveys["Phase9Start"],
},
"Phase9": {
"Label": "Phase 9",
"StartSurvey": surveys["Phase9Start"],
"EndSurvey": surveys["Phase10Start"],
},
}
# first day we collect data
first_pull = config_dic["date_range"]["first_pull"]
# last day we collect data
last_pull = config_dic["date_range"]["last_pull"]
# the first survey master_raw_user will be built upon
initial_master_survey = "Recruitment"
# the survey in which appcodes are initially recorded
appcode_survey = "Recruitment"
# All appcodes in this contact list will be kept in PD data processing. all others will be dropped.
kept_appcode_cl = "BaselineCompletes_KeptAppCodes_4202020.csv"
number_of_kept_appcodes = 4043
# the survey in which participants are randomly assigned to treatment groups
randomize_survey = "Midline"
# used contact lists names (that will override embedded data in the clean master object)
used_contact_lists = {"Baseline": "BaselineContacts_04122020.csv",
"Midline":"MidlineContacts 050220 final.csv",
"Endline1":"Endline1Contacts_20200523.csv",
"Endline2":"Endline2Contacts_20200613.csv"}
#variable name for people assigned to an RSI (Delayed or Intermediate or None)
rsi_assign_var = "BonusTreatment"
# variable name for people that actually have an rsi (note this is phase specific)
rsi_var = "RSIStatus"
#use variable used for benchmark and earnings calc and midline stratification
use_var = "FITSBYUseMinutes"
#apps that make up the fitsby app set
fitsby = ["facebook","instagram","twitter","snapchat","browser","youtube"]
# the number of people that we know completed the initial master survey (we hard code and assert in case anything gets screwed up in the pipeline)
sample_size = 26101
#seed for randomization
seed = 329
#number of cores used when parallelizing
cores = config_user_dict['local']['cores']
# if user hasn't uploaded data since this day, the user is considered inactive. we generate a CL with all inactive users
active_threshold = (datetime.now() - timedelta(3)).date()
#key is associated survey, and value is actual file name; the qualitative feedback files are summarized by Sherry and are
# housed in Confidential
qualitative_feedback_files = {"PDBug":"PDBug_QualitativeFeedback.csv",
"Midline":"Midline_QualitativeFeedback_LimitBug_and_MPLReasoning.csv",
"Endline1":"Endline1_QualitativeFeedback_LimitBug.csv",
"Endline2":"Endline2_QualitativeFeedback_LimitBug.csv"}
# - these columns will not contain a survey prefix attached to them because they have common values across all surveys.
# - they will not be removed as embedded data during survey cleaning
main_cols = [
"FirstName",
"AppCode",
"MainEmail",
"PhoneNumber",
]
## non prefixed columns that get introduced into the main dataset through used CLs or through the cleaning pipeline
# these variables ARE dropped during survey cleaning
embedded_main_cols = [
"OptedOut",
"ActiveStatus",
"Server",
"PhoneModel",
"PlatformVersion",
"AppVersion",
"SawLimitSettingPage",
"HasSetLimit",
"Randomize",
"StratAddictionIndex",
"StratRestrictionIndex",
"Stratifier",
"BonusTreatment",
"EndlineBlockerChange",
"EndlineBlockerMPLRow",
"InitialPaymentPart1",
"InitialPaymentPart2",
"HourlyRate",
"Benchmark",
"HourOrHours",
"PredictReward",
"MaxEarnings",
]
#Survey specific embedded data we want to keep for merge to master
kept_survey_data = ["Complete",
"SurveyStartDatetime",
"SurveyEndDatetime",
"MPLOption",
"RSIStatus",
"BlockerEarnings"
]
"""
The id_cols dictionary dictates which variables to anonymize. For each survey (the key), confidential.py (in lib/data_helpers)
will replace the columns (the values in the id_cols dictionary) with the user's AppCode. If the user doesn't have an
AppCode, then the column value will be replaced with the survey response id from the study_config.initial_master_survey.
Note:
- the list of variables in DeleteAlways key will be deleted from every survey
- confidential.py will do a soft match to the id_cols key. So, if the survey name is RecruitmentFacebook,
confidential key will anonymize columns according to the 'Recruitment' key in id_cols"""
id_cols = {"Recruitment":
["MainEmail",
"FirstName",
"Email",
"Email.1",
"EmailConfirm",
"PhoneNumber",
"PhoneNumberConfirm",
"PhoneNumber.1"
],
"Baseline":
["FriendContact"],
"DeleteAlways":
["LocationLatitude",
"LocationLongitude",
"IPAddress"]}