Skip to content

Commit ca1ffad

Browse files
Fixed Resource table
1 parent 977c9f1 commit ca1ffad

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

etl/transform.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pandas as pd
2+
import json
23

34
def normalize_json(data: dict) -> dict:
45
"""Flatten json"""
@@ -44,9 +45,16 @@ def process_data(data: tuple) -> tuple:
4445

4546
resources_df = flatten_response(resources, "resources", "survey_id")
4647
full_resources = pd.merge(resources, resources_df, on="survey_id")
48+
49+
# restricted resources
50+
try:
51+
full_resources['restricted'] = full_resources['restricted'].apply(json.loads)
52+
except TypeError:
53+
pass
54+
4755
restricted = pd.json_normalize(full_resources["restricted"])
4856
full_resources = full_resources.join(restricted)
49-
full_resources = full_resources.drop(columns=["resources", "restricted"])
57+
full_resources = full_resources.drop(columns=["resources", "restricted", "restricted-allowed_users", "restricted-level", 'cache_last_updated', 'cache_url', "revision_id"])
5058

5159
return (surveys, full_resources, users)
5260

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ def extract_data(client):
4444
processed_data = process_data(raw_data)
4545
save_to_excel(processed_data)
4646
load_to_db(processed_data)
47-
print("Done")
47+
print("Done")
48+

0 commit comments

Comments
 (0)