File size: 1,307 Bytes
2c9fffb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)