Skip to content

Commit

Permalink
feat: [WS-4468] add new field for algolia experiment (#4285)
Browse files Browse the repository at this point in the history
  • Loading branch information
bseverino authored Mar 15, 2024
1 parent 59915e4 commit 37c7b47
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 6 deletions.
54 changes: 53 additions & 1 deletion course_discovery/apps/course_metadata/algolia_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def delegate_attributes(cls):
search_fields = ['partner_names', 'partner_keys', 'product_title', 'product_source', 'primary_description',
'secondary_description', 'tertiary_description']
facet_fields = ['availability_level', 'subject_names', 'levels', 'active_languages', 'staff_slugs',
'product_allowed_in', 'product_blocked_in', 'learning_type']
'product_allowed_in', 'product_blocked_in', 'learning_type', 'learning_type_exp']
ranking_fields = ['availability_rank', 'product_recent_enrollment_count', 'promoted_in_spanish_index',
'product_value_per_click_usa', 'product_value_per_click_international',
'product_value_per_lead_usa', 'product_value_per_lead_international']
Expand Down Expand Up @@ -294,6 +294,33 @@ def program_types(self):
def learning_type(self):
return [self.product_type, *self.program_types]

@property
def learning_type_exp(self):
"""
Temporary field used as a variant of `learning_type` for an experiment. If the experiment is successful,
this will replace `learning_type`.
"""
if self.type.slug == CourseType.EXECUTIVE_EDUCATION_2U:
return [_('Certificate courses')]

processed_program_types = []
for program_type in self.program_types:
if program_type in [
'Certificate',
'License',
'Professional Certificate',
'XSeries'
]:
processed_program_types.append(_('Certificate courses'))
elif program_type in ['Bachelors', 'Doctorate', 'Masters']:
processed_program_types.append(_('Degrees'))
elif program_type in ['MicroBachelors', 'MicroMasters']:
processed_program_types.append(_('Paths to degrees'))
else:
processed_program_types.append(program_type)

return [self.product_type, *processed_program_types]

@property
def product_card_image_url(self):
if self.image:
Expand Down Expand Up @@ -538,6 +565,31 @@ def learning_type(self):
return [self.type.name_t]
return []

@property
def learning_type_exp(self):
"""
Temporary field used as a variant of `learning_type` for an experiment. If the experiment is successful,
this will replace `learning_type`.
"""
if self.type:
if self.type.slug in [
ProgramType.CERTIFICATE,
ProgramType.LICENSE,
ProgramType.PROFESSIONAL_CERTIFICATE,
ProgramType.XSERIES
]:
return [_('Certificate courses')]
if self.type.slug in [
ProgramType.BACHELORS,
ProgramType.DOCTORATE,
ProgramType.MASTERS
]:
return [_('Degrees')]
if self.type.slug in [ProgramType.MICROBACHELORS, ProgramType.MICROMASTERS]:
return [_('Paths to degrees')]
return [self.type.name_t]
return []

@property
def tags(self):
topics = [topic.name for topic in self.topics]
Expand Down
8 changes: 4 additions & 4 deletions course_discovery/apps/course_metadata/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class EnglishProductIndex(BaseProductIndex):
('active_languages', 'language'), ('product_type', 'product'), ('program_types', 'program_type'),
('staff_slugs', 'staff'), ('product_allowed_in', 'allowed_in'),
('product_blocked_in', 'blocked_in'), 'subscription_eligible',
'subscription_prices', 'learning_type',)
'subscription_prices', 'learning_type', 'learning_type_exp',)
ranking_fields = ('availability_rank', ('product_recent_enrollment_count', 'recent_enrollment_count'),
('product_value_per_click_usa', 'value_per_click_usa'),
('product_value_per_click_international', 'value_per_click_international'),
Expand Down Expand Up @@ -116,7 +116,7 @@ class EnglishProductIndex(BaseProductIndex):
'partner', 'availability', 'subject', 'level', 'language', 'product', 'program_type',
'filterOnly(staff)', 'filterOnly(allowed_in)', 'filterOnly(blocked_in)', 'skills.skill',
'skills.category', 'skills.subcategory', 'tags', 'subscription_eligible', 'subscription_prices',
'learning_type',
'learning_type', 'learning_type_exp',
],
'customRanking': ['asc(availability_rank)', 'desc(recent_enrollment_count)']
}
Expand All @@ -133,7 +133,7 @@ class SpanishProductIndex(BaseProductIndex):
('active_languages', 'language'), ('product_type', 'product'), ('program_types', 'program_type'),
('staff_slugs', 'staff'), ('product_allowed_in', 'allowed_in'),
('product_blocked_in', 'blocked_in'), 'subscription_eligible',
'subscription_prices', 'learning_type',)
'subscription_prices', 'learning_type', 'learning_type_exp',)
ranking_fields = ('availability_rank', ('product_recent_enrollment_count', 'recent_enrollment_count'),
('product_value_per_click_usa', 'value_per_click_usa'),
('product_value_per_click_international', 'value_per_click_international'),
Expand Down Expand Up @@ -171,7 +171,7 @@ class SpanishProductIndex(BaseProductIndex):
'partner', 'availability', 'subject', 'level', 'language', 'product', 'program_type',
'filterOnly(staff)', 'filterOnly(allowed_in)', 'filterOnly(blocked_in)',
'skills.skill', 'skills.category', 'skills.subcategory', 'tags', 'subscription_eligible',
'subscription_prices', 'learning_type',
'subscription_prices', 'learning_type', 'learning_type_exp',
],
'customRanking': ['desc(promoted_in_spanish_index)', 'asc(availability_rank)', 'desc(recent_enrollment_count)']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from course_discovery.apps.core.tests.factories import PartnerFactory, SiteFactory
from course_discovery.apps.course_metadata.algolia_models import AlgoliaProxyCourse, AlgoliaProxyProgram
from course_discovery.apps.course_metadata.choices import ExternalProductStatus, ProgramStatus
from course_discovery.apps.course_metadata.models import CourseRunStatus, CourseType, ProductValue
from course_discovery.apps.course_metadata.models import CourseRunStatus, CourseType, ProductValue, ProgramType
from course_discovery.apps.course_metadata.tests.factories import (
AdditionalMetadataFactory, CourseFactory, CourseRunFactory, CourseTypeFactory, DegreeAdditionalMetadataFactory,
DegreeFactory, GeoLocationFactory, LevelTypeFactory, OrganizationFactory, ProductMetaFactory, ProgramFactory,
Expand Down Expand Up @@ -523,6 +523,20 @@ def test_learning_type_open_course(self, has_program):
else:
assert course.learning_type == ['Course']

@ddt.data(
(ProgramType.PROFESSIONAL_CERTIFICATE, 'Certificate courses'),
(ProgramType.MASTERS, 'Degrees'),
(ProgramType.MICROBACHELORS, 'Paths to degrees'),
)
@ddt.unpack
def test_learning_type_exp_open_course(self, program_type_slug, learning_type):
course_type = CourseTypeFactory()
course = AlgoliaProxyCourseFactory(partner=self.__class__.edxPartner, type=course_type)
program_type = ProgramType.objects.get(slug=program_type_slug)
program = AlgoliaProxyProgramFactory(partner=self.__class__.edxPartner, type=program_type)
course.programs.set([program])
assert course.learning_type_exp == ['Course', learning_type]

@ddt.data(
(CourseType.EXECUTIVE_EDUCATION_2U, 'Executive Education'),
(CourseType.BOOTCAMP_2U, 'Boot Camp'),
Expand All @@ -533,6 +547,16 @@ def test_learning_type_non_open_course(self, course_type_slug, expected_result):
course.type = CourseTypeFactory(slug=course_type_slug)
assert course.learning_type == [expected_result]

@ddt.data(
(CourseType.EXECUTIVE_EDUCATION_2U, 'Certificate courses'),
(CourseType.BOOTCAMP_2U, 'Boot Camp'),
)
@ddt.unpack
def test_learning_type_exp_non_open_course(self, course_type_slug, expected_result):
course = AlgoliaProxyCourseFactory(partner=self.__class__.edxPartner)
course.type = CourseTypeFactory(slug=course_type_slug)
assert course.learning_type_exp == [expected_result]


@ddt.ddt
@pytest.mark.django_db
Expand Down Expand Up @@ -849,3 +873,14 @@ def test_learning_type(self):
program_type = ProgramTypeFactory()
program = AlgoliaProxyProgramFactory(partner=self.__class__.edxPartner, type=program_type)
assert program.learning_type == [program_type.name_t]

@ddt.data(
(ProgramType.PROFESSIONAL_CERTIFICATE, 'Certificate courses'),
(ProgramType.MASTERS, 'Degrees'),
(ProgramType.MICROBACHELORS, 'Paths to degrees'),
)
@ddt.unpack
def test_learning_type_exp(self, program_type_slug, learning_type):
program_type = ProgramType.objects.get(slug=program_type_slug)
program = AlgoliaProxyProgramFactory(partner=self.__class__.edxPartner, type=program_type)
assert program.learning_type_exp == [learning_type]

0 comments on commit 37c7b47

Please sign in to comment.