Skip to content

Commit

Permalink
chore: rename component in data dir
Browse files Browse the repository at this point in the history
  • Loading branch information
atnanahidiw committed Oct 22, 2023
1 parent f7d747b commit 7b212be
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- main
paths:
- data/materials/**
- data/learning_material/**
workflow_dispatch:

jobs:
Expand All @@ -30,7 +30,7 @@ jobs:
- name: Update materials info that are modified
run: |
pip install -r utils/scripts/requirements.txt
python utils/scripts/update_materials_info.py
python utils/scripts/update_learning_material_info.py
env:
FIREBASE_SECRET_KEY_JSON: ${{ secrets.STG_FIREBASE_ADMINSDK_SECRET_KEY_JSON }}
FILES_ADDED_AND_MODIFIED_ON_GIT: ${{ steps.list-files.outputs.modified_files }}
File renamed without changes.
File renamed without changes.
48 changes: 27 additions & 21 deletions utils/scripts/next_weekly_quiz_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,36 @@
"sponsors": {}
}

challengegroup_map = configuration_coll_ref.document("challenge_group").get().to_dict()
for cg_group, cg_val in challengegroup_map.items():
problem_id_list = []

query_ref = problemset_coll_ref.where("challenge_group", "==", cg_group)
for doc in query_ref.stream():
problem_id_list.append(doc.to_dict()["id"])
random.shuffle(problem_id_list)
def generate_next_weekly_quiz():
challengegroup_map = configuration_coll_ref.document("challenge_group").get().to_dict()
for cg_group, cg_val in challengegroup_map.items():
problem_id_list = []

result["tasks"][cg_group] = problem_id_list[:cg_val["weeklyquiz_task_number"]]
result["max_attempts"][cg_group] = cg_val["weeklyquiz_max_attempts"]
result["duration_minute"][cg_group] = cg_val["weeklyquiz_duration_minute"]
query_ref = problemset_coll_ref.where("challenge_group", "==", cg_group)
for doc in query_ref.stream():
problem_id_list.append(doc.to_dict()["id"])
random.shuffle(problem_id_list)

# ToDo: later, make a logic to fill the sponsor(s)
result["sponsors"][cg_group] = None
result["tasks"][cg_group] = problem_id_list[:cg_val["weeklyquiz_task_number"]]
result["max_attempts"][cg_group] = cg_val["weeklyquiz_max_attempts"]
result["duration_minute"][cg_group] = cg_val["weeklyquiz_duration_minute"]

# for history data
_, doc_ref = weeklyquizlist_coll_ref.add(result)
result["id"] = doc_ref.id # generate random id & put it in the `result` for latest data
# ToDo: later, make a logic to fill the sponsor(s)
result["sponsors"][cg_group] = None

# for latest data
to_running = configuration_coll_ref.document("next_weekly_quiz").get().to_dict()
configuration_coll_ref.document("next_weekly_quiz").set(result)
configuration_coll_ref.document("running_weekly_quiz").set(to_running)
# for history data
_, doc_ref = weeklyquizlist_coll_ref.add(result)
result["id"] = doc_ref.id # generate random id & put it in the `result` for latest data

# update global variables
configuration_coll_ref.document("global_variables").set(config_global_variables)
# for latest data
to_running = configuration_coll_ref.document("next_weekly_quiz").get().to_dict()
configuration_coll_ref.document("next_weekly_quiz").set(result)
configuration_coll_ref.document("running_weekly_quiz").set(to_running)

# update global variables
configuration_coll_ref.document("global_variables").set(config_global_variables)


if __name__ == "__main__":
generate_next_weekly_quiz()
23 changes: 23 additions & 0 deletions utils/scripts/update_bebras_task_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json
import os
from firebase_admin import credentials, initialize_app, firestore
from glob import glob

creds = credentials.Certificate(
json.loads(os.environ["FIREBASE_SECRET_KEY_JSON"])
)
initialize_app(creds)

firestore_client = firestore.client()
col_ref = firestore_client.collection("task_set")

file_list = glob("data/bebras_tasks/*/*/*.json")
for file in file_list:
with open(file, "r") as f:
file_ref = file.replace(".json", "").split("/")
name = "_".join(file_ref[-2:])

content = json.load(f)
content["challenge_group"] = file_ref[-2]

col_ref.document(name).set(content)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def update_info(file_list):
col_ref = firestore_client.collection("materials")
col_ref = firestore_client.collection("learning_material")
for file in file_list:
with open(file, "r") as f:
file_ref = file.replace(".json", "").split("/")
Expand All @@ -23,9 +23,9 @@ def update_info(file_list):
if __name__ == "__main__":
updated_files = os.getenv("FILES_ADDED_AND_MODIFIED_ON_GIT")
if updated_files is not None:
# filter which start with `data/materials/` only
file_list = [path for path in updated_files.split("\n") if path.startswith("data/materials/")]
# filter which start with `data/learning_material/` only
file_list = [path for path in updated_files.split("\n") if path.startswith("data/learning_material/")]
else:
file_list = glob("data/materials/*/*.json")
file_list = glob("data/learning_material/*/*.json")

update_info(file_list)

0 comments on commit 7b212be

Please sign in to comment.