Skip to content

Commit

Permalink
Adding participant demographic data from qualtrix response to raw com…
Browse files Browse the repository at this point in the history
…pletions spreadsheet
  • Loading branch information
nathan-moore-97 committed Sep 15, 2023
1 parent 1245266 commit 83cb619
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
32 changes: 30 additions & 2 deletions gdrive/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,39 @@ def delete_file(id: str) -> None:
service.files().delete(fileId=id, supportsAllDrives=True).execute()


def upload_participant(first, last, email, responseId, time, date):
def upload_participant(
first,
last,
email,
responseId,
time,
date,
ethnicity,
race,
gender,
age,
income,
skin_tone,
):
"""
Append participant data to spreadsheet
"""
values = [[first, last, first + " " + last, email, responseId, time, date]]
values = [
[
first,
last,
first + " " + last,
email,
responseId,
time,
date,
ethnicity,
race,
gender,
income,
skin_tone,
]
]

body = {"values": values}
result = (
Expand Down
13 changes: 13 additions & 0 deletions gdrive/export_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ async def survey_upload_response_task(request):

log.info("Response found, beginning export.")

# By the time we get here, we can count on the response containing the demographic data
# as it is included in the Completed flow responses. Responses without complete status
# throws exception in get_qualtrics_response
survey_resp = response["response"]

if request.participant:
participant = request.participant
client.upload_participant(
Expand All @@ -80,6 +85,14 @@ async def survey_upload_response_task(request):
request.responseId,
participant.time,
participant.date,
survey_resp["ethnicity"],
", ".join(
survey_resp["race"]
), # Can have more than one value in a list
survey_resp["gender"],
survey_resp["age"],
survey_resp["income"],
survey_resp["skin_tone"],
)

# call function that queries ES for all analytics entries (flow interactionId) with responseId
Expand Down
10 changes: 9 additions & 1 deletion gdrive/export_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,12 @@ def get_qualtrics_response(surveyId: str, responseId: str):
raise error.ExportError(
f"No survey response found for responseId: {responseId}"
)
return r.json()

resp = r.json()

if resp["status"] != "Complete":
raise error.ExportError(
f"Cannot upload incomplete survery response to raw completions spreadsheet: {responseId}"
)

return resp

0 comments on commit 83cb619

Please sign in to comment.