Skip to content

Commit

Permalink
tweak calculatin of learning formats
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertrand committed Jul 2, 2024
1 parent 9882f58 commit 411250e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
22 changes: 14 additions & 8 deletions learning_resources/etl/professional_ed.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,20 @@ def parse_format(format_str: str) -> list[str]:
"""
format_str = format_str.strip().lower()
formats = []
if "virtual" in format_str or "online" in format_str:
formats.append(LearningResourceFormat.online.name)
if "campus" in format_str:
formats.append(LearningResourceFormat.in_person.name)
if not formats:
log.warning("Unknown format: %s, defaulting to online", format_str)
formats.append(LearningResourceFormat.online.name)
return formats
is_online = "virtual" in format_str or "online" in format_str
in_person = "campus" in format_str
is_hybrid = is_online and in_person and " and " in format_str
if is_hybrid:
formats.append(LearningResourceFormat.hybrid.name)
else:
if in_person:
formats.append(LearningResourceFormat.in_person.name)
if is_online:
formats.append(LearningResourceFormat.online.name)
if not formats:
log.warning("Unknown format: %s, defaulting to online", format_str)
formats.append(LearningResourceFormat.online.name)
return sorted(formats)


def parse_resource_url(resource_data: dict) -> str:
Expand Down
8 changes: 6 additions & 2 deletions learning_resources/etl/professional_ed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"description": "The featured program summary.",
"full_description": "The full program description.",
"learning_format": ["online", "in_person"],
"learning_format": ["hybrid"],
"published": True,
"topics": [{"name": "Innovation"}],
"runs": [
Expand Down Expand Up @@ -212,9 +212,13 @@ def test_transform(prof_ed_settings, mock_fetch_data):
"Live Virtual OR On Campus",
[LearningResourceFormat.online.name, LearningResourceFormat.in_person.name],
),
(
"Live Virtual And On Campus",
[LearningResourceFormat.hybrid.name],
),
("Unrecognized", [LearningResourceFormat.online.name]),
],
)
def test_parse_format(format_str, expected):
"""Test parse_format function"""
assert professional_ed.parse_format(format_str) == expected
assert sorted(professional_ed.parse_format(format_str)) == sorted(expected)

0 comments on commit 411250e

Please sign in to comment.