2b-agent-80 / get_data.py
dipta007's picture
init
2c9fffb
from google.cloud import firestore
import pandas as pd
# Authenticate to Firestore with the JSON account key.
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: [], step + "_depends_on": [] }
collection = db.collection(step)
# print(collection)
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']]
obj[doc.id][step + "_depends_on"] = doc.to_dict()['beamlak']['dependsOn']
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])
for step in ["step_0", "step_1", "step_2", "step_3", "step_4", "step_all"]:
data[step + "_depends_on"].append(obj[key][step + "_depends_on"])
return data
data = get_data()
df = pd.DataFrame(data)
df.to_csv('./likert.csv', index=False)