Skip to content

Commit

Permalink
Flatten OCW topics so all of them get mapped to PWT topics when runni…
Browse files Browse the repository at this point in the history
…ng the ETL pipeline (#1343)
  • Loading branch information
jkachel authored Jul 31, 2024
1 parent b621075 commit 470676c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 1 addition & 6 deletions learning_resources/etl/ocw.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,8 @@ def transform_course(course_data: dict) -> dict:
readable_term = f"+{slugify(term)}" if term else ""
readable_year = f"_{course_data.get('year')}" if year else ""
readable_id = f"{course_data[PRIMARY_COURSE_ID]}{readable_term}{readable_year}"
# The json returns basically a tuple of topics with subtopics - we only need
# to care about the subtopic, unless there's not one.
topics = transform_topics(
[
{"name": topic[1] if len(topic) > 1 else topic[0]}
for topic in course_data.get("topics")
],
[{"name": topic} for topics in course_data.get("topics") for topic in topics],
OFFERED_BY["code"],
)
image_src = course_data.get("image_src")
Expand Down
10 changes: 8 additions & 2 deletions learning_resources/etl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def load_offeror_topic_map(offeror_code: str):
mappings = {}

for pmt_mapping in pmt_mappings:
mappings[pmt_mapping.topic_name] = pmt_mapping.topic.name
if pmt_mapping.topic_name not in mappings:
mappings[pmt_mapping.topic_name] = []

mappings[pmt_mapping.topic_name].append(pmt_mapping.topic.name)

return mappings

Expand All @@ -93,7 +96,10 @@ def transform_topics(topics: list, offeror_code: str):

for topic in topics:
if topic["name"] in topic_mappings:
transformed_topics.append({"name": topic_mappings.get(topic["name"])})
[
transformed_topics.append({"name": mapped_topic})
for mapped_topic in topic_mappings.get(topic["name"])
]
else:
base_topic = LearningResourceTopic.objects.filter(
name=topic["name"]
Expand Down

0 comments on commit 470676c

Please sign in to comment.