|
from google.cloud import firestore |
|
import pandas as pd |
|
|
|
|
|
db = firestore.Client.from_service_account_json("./firebase.json") |
|
|
|
scale = { |
|
"Strongly disagree": 1, |
|
"Disagree": 2, |
|
"Neutral": 3, |
|
"Agree": 4, |
|
"Strongly agree": 5, |
|
} |
|
|
|
def get_data(): |
|
data = { |
|
'id': [] |
|
} |
|
obj = {} |
|
for step in ["step_0", "step_1", "step_2", "step_3", "step_4", "step_all"]: |
|
data = { **data, step: [] } |
|
collection = db.collection(step) |
|
|
|
docs = collection.stream() |
|
for doc in docs: |
|
if doc.id not in obj: |
|
obj[doc.id] = {} |
|
obj[doc.id][step] = scale[doc.to_dict()['beamlak']['scale']] |
|
|
|
|
|
for key in obj: |
|
data['id'].append(key) |
|
for step in ["step_0", "step_1", "step_2", "step_3", "step_4", "step_all"]: |
|
data[step].append(obj[key][step]) |
|
return data |
|
|
|
data = get_data() |
|
df = pd.DataFrame(data) |
|
df.to_csv('./likert.csv', index=False) |
|
|