-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: indexing bayesian average ranking for courses in algolia
- Loading branch information
1 parent
25cb40c
commit bcaa529
Showing
8 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...rprise_catalog/apps/catalog/management/commands/set_global_average_course_rating_value.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from enterprise_catalog.apps.catalog.algolia_utils import set_global_course_review_avg | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = ( | ||
'Fetch ContentMetadata records, read the course review values and save the average to py-cache.' | ||
) | ||
|
||
def handle(self, *args, **options): | ||
""" | ||
Fetch ContentMetadata records, read the course review values and save the average to py-cache. | ||
""" | ||
logger.info("compare_catalog_queries_to_filters queuing task...") | ||
set_global_course_review_avg() |
47 changes: 47 additions & 0 deletions
47
...log/apps/catalog/management/commands/tests/test_set_global_average_course_rating_value.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from unittest import mock | ||
from django.conf import settings | ||
from django.core.management import call_command | ||
from django.test import TestCase | ||
|
||
from enterprise_catalog.apps.api_client.constants import DISCOVERY_AVERAGE_COURSE_REVIEW_CACHE_KEY | ||
from enterprise_catalog.apps.catalog.tests.factories import ContentMetadataFactory | ||
|
||
|
||
class TestSetGlobalAverageCourseRatingValue(TestCase): | ||
command_name = 'set_global_average_course_rating_value' | ||
|
||
@mock.patch('enterprise_catalog.apps.catalog.algolia_utils.cache') | ||
def test_command_averages_course_reviews( | ||
self, mock_cache, | ||
): | ||
""" | ||
Verify that the command sifts over content metadata and calculates the | ||
average review score, setting the value to py-cache. | ||
""" | ||
ContentMetadataFactory( | ||
content_type='course', | ||
json_metadata={'avg_course_rating': 5, 'reviews_count': 20} | ||
) | ||
ContentMetadataFactory( | ||
content_type='course', | ||
json_metadata={'avg_course_rating': 4, 'reviews_count': 10} | ||
) | ||
ContentMetadataFactory(json_metadata={}) | ||
call_command(self.command_name) | ||
expected_total_average = ((5 * 20) + (4 * 10)) / 30 | ||
|
||
mock_cache.set.assert_called_with( | ||
DISCOVERY_AVERAGE_COURSE_REVIEW_CACHE_KEY, | ||
expected_total_average, | ||
settings.DISCOVERY_AVERAGE_COURSE_REVIEW_CACHE_TIMEOUT, | ||
) | ||
|
||
@mock.patch('enterprise_catalog.apps.catalog.algolia_utils.cache') | ||
def test_command_handles_no_course_reviews( | ||
self, mock_cache, | ||
): | ||
""" | ||
Verify that the job will not blow up if there are no reviews to average. | ||
""" | ||
call_command(self.command_name) | ||
mock_cache.set.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters