File size: 19,568 Bytes
8a79f2e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
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"]}
|