Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion learning_resources/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class PrivacyLevel(ExtendedEnum):
unlisted = "unlisted"


semester_mapping = {"1T": "spring", "2T": "summer", "3T": "fall"}
semester_mapping = {"1T": "Spring", "2T": "Summer", "3T": "Fall"}


class LearningResourceRelationTypes(TextChoices):
Expand Down
229 changes: 115 additions & 114 deletions learning_resources/data/oll_metadata.csv

Large diffs are not rendered by default.

28 changes: 25 additions & 3 deletions learning_resources/etl/oll.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import requests
from django.conf import settings
from django.utils.text import slugify

from learning_resources.constants import (
Availability,
Expand All @@ -28,6 +29,25 @@
]


def parse_readable_id(course_data: dict, run: dict) -> str:
"""
Parse the course readable_id

Args:
course_data (dict): course data
run (dict): run data

Returns:
str: course readable_id

"""
if course_data["Offered by"] == "OCW":
semester = run.get("semester") or ""
year = run.get("year") or ""
return f"{course_data["OLL Course"]}+{slugify(semester)}_{year}"
return f"MITx+{course_data["OLL Course"]}"


def extract(sheets_id: str or None = None) -> str:
"""
Extract OLL learning_resources
Expand Down Expand Up @@ -82,7 +102,8 @@ def parse_topics(course_data: dict) -> list[dict]:
{"name": topic.replace("Educational Policy", "Education Policy")}
for topic in [
course_data["MITxO Primary Child"],
course_data["MITxO Secondary Child "],
# Sheet/csv column title has trailing space
course_data["MITxO Adopted Secondary Child "],
]
if topic
]
Expand Down Expand Up @@ -136,9 +157,10 @@ def transform_course(course_data: dict) -> dict:
dict: normalized course data

"""
runs = transform_run(course_data)
return {
"title": course_data["title"],
"readable_id": f"MITx+{course_data["OLL Course"]}",
"readable_id": parse_readable_id(course_data, runs[0]),
"url": course_data["url"],
"description": course_data["description"],
"full_description": course_data["description"],
Expand All @@ -155,7 +177,7 @@ def transform_course(course_data: dict) -> dict:
course_data["OLL Course"], is_ocw=False
),
},
"runs": transform_run(course_data),
"runs": runs,
"image": transform_image(course_data),
"prices": [Decimal(0.00)],
"etl_source": ETLSource.oll.name,
Expand Down
10 changes: 5 additions & 5 deletions learning_resources/etl/oll_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ def test_oll_transform(mocker, oll_course_data):

assert results[0] == {
"title": "Introduction to Probability and Statistics",
"readable_id": "MITx+18.05",
"readable_id": "18.05+summer_2022",
"url": "https://openlearninglibrary.mit.edu/courses/course-v1:MITx+18.05r_10+2022_Summer/about",
"description": mocker.ANY,
"full_description": mocker.ANY,
"offered_by": {"code": "ocw"},
"platform": "oll",
"published": True,
"topics": [{"name": "Mathematics"}],
"topics": [{"name": "Mathematics"}, {"name": "Data Science"}],
"course": {
"course_numbers": [
{
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_oll_transform(mocker, oll_course_data):
{"full_name": "Jennifer French Kamrin"},
],
"availability": "Archived",
"semester": "summer",
"semester": "Summer",
"year": 2022,
}
],
Expand All @@ -91,7 +91,7 @@ def test_oll_transform(mocker, oll_course_data):
"offered_by": {"code": "mitx"},
"platform": "oll",
"published": True,
"topics": [{"name": "Education Policy"}],
"topics": [{"name": "Education Policy"}, {"name": "Digital Learning"}],
"course": {
"course_numbers": [
{
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_oll_transform(mocker, oll_course_data):
{"full_name": "Elizabeth Huttner-Loan"},
],
"availability": "Archived",
"semester": "spring",
"semester": "Spring",
"year": 2019,
}
],
Expand Down
2 changes: 1 addition & 1 deletion learning_resources/etl/openedx_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_transform_course( # noqa: PLR0913
"last_modified": any_instance_of(datetime),
"level": ["intermediate"],
"prices": ["0.00", "150.00"],
"semester": "spring",
"semester": "Spring",
"description": "short_description",
"start_date": expected_dt,
"title": "The Analytics Edge",
Expand Down
2 changes: 1 addition & 1 deletion learning_resources/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_year_and_semester(course_run):
)
if match:
year = int(match.group(1))
semester = match.group(2).lower()
semester = match.group(2)
else:
semester = None
year = course_run.get("start")[:4] if course_run.get("start") else None
Expand Down