Skip to content

Commit

Permalink
Merge pull request #36 from gogovan/forms
Browse files Browse the repository at this point in the history
Forms
  • Loading branch information
ggx-jacechun authored Jul 3, 2023
2 parents ac0dc16 + 8d32d12 commit f129f8e
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions ggvlib/google/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np



DEFAULT_SCOPES = [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.file",
Expand Down Expand Up @@ -65,23 +66,26 @@ def get_raw_responses_as_df(form_id: str) -> pd.DataFrame:
return_df = pd.DataFrame()
logger.info(f"Getting form responses as df from form {form_id}")
responses = get_raw_responses(form_id)
for row in responses["responses"]:
return_list = list()
return_list.append(row["responseId"])
return_list.append(row["createTime"])
return_list.append(row["lastSubmittedTime"])
return_list.append(row["answers"])
col_names = ["responseId", "createTime", "LastSubmittedTime", "answer"]
for val in row["answers"].values():
for answer in list(val.values())[1].values():
if "value" in list(answer[0].keys()):
col_names.append(val["questionId"])
return_list.append(answer[0]["value"])

return_df = pd.concat([return_df, pd.DataFrame(return_list).T]).reset_index(
drop=True
)
return_df.columns = col_names
if "responses" in responses.keys():
for row in responses["responses"]:
return_list = list()
return_list.append(row["responseId"])
return_list.append(row["createTime"])
return_list.append(row["lastSubmittedTime"])
return_list.append(row["answers"])
col_names = ["responseId", "createTime", "LastSubmittedTime", "answer"]
for val in row["answers"].values():
for answer in list(val.values())[1].values():
if "value" in list(answer[0].keys()):
col_names.append(val["questionId"])
return_list.append(answer[0]["value"])

return_df = pd.concat([return_df, pd.DataFrame(return_list).T]).reset_index(
drop=True
)
return_df.columns = col_names
else:
logger.info(f"There is no responses in form {form_id}")
return return_df


Expand Down Expand Up @@ -156,3 +160,4 @@ def get_responses_as_df(form_id: str) -> pd.DataFrame:
name_dict[id] = name
return_df = response.rename(columns=name_dict)
return return_df

0 comments on commit f129f8e

Please sign in to comment.