Skip to content

Commit

Permalink
Merge pull request #12 from edx/aed/group-by-right
Browse files Browse the repository at this point in the history
Correct the latest_blocks_completed_all_courses query.
  • Loading branch information
iloveagent57 authored Mar 21, 2018
2 parents 78e8aa4 + cb4046f commit 39bddf2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ Unreleased
~~~~~~~~~~
* Add query method for all completions by course

[0.0.10] - 2018-03-20
[0.1.0] - 2018-03-20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Fixes https://openedx.atlassian.net/browse/EDUCATOR-2540

[0.0.11] - 2018-03-20
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Added "subsection-completion/{username}/{course_key}/{subsection_id}" API
Expand Down
2 changes: 1 addition & 1 deletion completion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from __future__ import unicode_literals


__version__ = '0.0.11'
__version__ = '0.1.0'

default_app_config = 'completion.apps.CompletionAppConfig' # pylint: disable=invalid-name
26 changes: 22 additions & 4 deletions completion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,28 @@ def latest_blocks_completed_all_courses(cls, user):

latest_completions_by_course = cls.objects.raw(
'''
SELECT id, course_key, block_key, max(modified) as latest
FROM completion_blockcompletion
WHERE user_id=%s
GROUP BY course_key;
SELECT
cbc.id AS id,
cbc.course_key AS course_key,
cbc.block_key AS block_key,
cbc.modified AS modified
FROM
completion_blockcompletion cbc
JOIN (
SELECT
course_key,
MAX(modified) AS modified
FROM
completion_blockcompletion
WHERE
user_id = %s
GROUP BY
course_key
) latest
ON
cbc.course_key = latest.course_key AND
cbc.modified = latest.modified
;
''',
[user.id]
)
Expand Down
5 changes: 1 addition & 4 deletions completion/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ def setUp(self):
self.block_keys = [
UsageKey.from_string("i4x://edX/MOOC101/video/{}".format(number)) for number in range(5)
]
self.block_keys_two = [
UsageKey.from_string("i4x://edX/MOOC101/video/{}".format(number)) for number in range(5)
]

the_completion_date = datetime.datetime(2050, 1, 1, tzinfo=UTC)
for idx, block_key in enumerate(self.block_keys[:3]):
Expand Down Expand Up @@ -214,7 +211,7 @@ def test_latest_blocks_completed_all_courses(self):
self.assertDictEqual(
models.BlockCompletion.latest_blocks_completed_all_courses(self.user_one),
{
self.course_key_two: [datetime.datetime(2050, 1, 10, tzinfo=UTC), self.block_keys_two[4]],
self.course_key_two: [datetime.datetime(2050, 1, 10, tzinfo=UTC), self.block_keys[4]],
self.course_key_one: [datetime.datetime(2050, 1, 3, tzinfo=UTC), self.block_keys[2]]
}
)

0 comments on commit 39bddf2

Please sign in to comment.