{"action":"created","comment":{"url":"https://api.github.com/repos/learningequality/ka-lite/pulls/comments/30936615","id":30936615,"diff_hunk":"@@ -116,50 +117,49 @@ def get_next_recommendations(user):\n # in the same user group - also ordered by empirical count (more people moving onto this -> higher in the\n # list). \"Immediately\" means the very next exercise after the most recent one the given user has accessed.\n #\n+# This function checks if the exercises returned have been accessed already, and only returns those that\n+# have not been.\n+#\n # A group is defined as a collection of students within the same facility and group (as defined in models)\n def get_group_recommendations(user):\n-    user = ExerciseLog.objects.filter(id__lte=1)[0].user        #random person, can delete after                                  \n-    most_recent_exercise = get_most_recent_exercises(user)[0]   #get most recently accessed exercise\n-    user_list = get_users_in_group('Student', user.group, user.facility) #may need to debug\n+ \n+    recent_exercises = get_most_recent_exercises(user)\n     \n-    counts = [{'temp':0}]  #array of dictionaries to keep track of counts of subsequent exercises\n+    user_list = FacilityUser.objects.filter(group=user.group)\n \n-    '''     NEEDS DEBUGGING     '''\n-    for student in user_list:\n-        student_exercises = get_most_recent_exercises(student)\n-        \n-        #if this student has taken/attempted this exercise\n-        if most_recent_exercise in student_exercises and len(student_exercises) > 0:\n-            next = student_exercises[0] #start at the most recent one - this will act like a prev pointer\n-\n-            #loop through all exercises, keeping track of previous \n-            for exercise in student_exercises:\n-              \n-                #a match, and not the first one (which would imply that there is no next)\n-                if(exercise == most_recent_exercise and exercise != next):\n-                    \n-                    found = False #boolean flag\n-                    \n-                    for c in counts:\n-                        #if a match\n-                        if next.exercise_id in c:\n-                            c[next.exercise_id] += 1\n-                            found = True\n+    if recent_exercises:\n \n-                    #if exercise not found, then make a new object with it with count = 1 \n-                    if not found:\n-                        counts.append({next.exercise_id : 1})\n+        #If the user has recently engaged with exercises, use these exercises as the basis for filtering\n+        user_exercises = ExerciseLog.objects.filter(user__in=user_list).order_by(\"-latest_activity_timestamp\").extra(select={'null_complete': \"completion_timestamp is null\"}, order_by=[\"-null_complete\", \"-completion_timestamp\"])\n+    \n+        exercise_counts = {}\n \n-                    #break #stops inner for loop logic\n+        for user in user_list:\n+            user_logs = user_exercises.filter(user=user)\n+            for i, log in enumerate(user_logs):\n+                if i > 0:","path":"kalite/topic_tools/content_recommendation.py","position":232,"original_position":232,"commit_id":"8f54bbb1f0ef723c6a4de3853a3b5d4032ee87c1","original_commit_id":"8f54bbb1f0ef723c6a4de3853a3b5d4032ee87c1","user":{"login":"aronasorman","id":191955,"avatar_url":"https://avatars.githubusercontent.com/u/191955?v=3","gravatar_id":"","url":"https://api.github.com/users/aronasorman","html_url":"https://github.com/aronasorman","followers_url":"https://api.github.com/users/aronasorman/followers","following_url":"https://api.github.com/users/aronasorman/following{/other_user}","gists_url":"https://api.github.com/users/aronasorman/gists{/gist_id}","starred_url":"https://api.github.com/users/aronasorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aronasorman/subscriptions","organizations_url":"https://api.github.com/users/aronasorman/orgs","repos_url":"https://api.github.com/users/aronasorman/repos","events_url":"https://api.github.com/users/aronasorman/events{/privacy}","received_events_url":"https://api.github.com/users/aronasorman/received_events","type":"User","site_admin":false},"body":"`if i:`","created_at":"2015-05-22T22:55:49Z","updated_at":"2015-05-22T22:55:49Z","html_url":"https://github.com/learningequality/ka-lite/pull/3688#discussion_r30936615","pull_request_url":"https://api.github.com/repos/learningequality/ka-lite/pulls/3688","_links":{"self":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/comments/30936615"},"html":{"href":"https://github.com/learningequality/ka-lite/pull/3688#discussion_r30936615"},"pull_request":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/3688"}}},"pull_request":{"url":"https://api.github.com/repos/learningequality/ka-lite/pulls/3688","id":35886181,"html_url":"https://github.com/learningequality/ka-lite/pull/3688","diff_url":"https://github.com/learningequality/ka-lite/pull/3688.diff","patch_url":"https://github.com/learningequality/ka-lite/pull/3688.patch","issue_url":"https://api.github.com/repos/learningequality/ka-lite/issues/3688","number":3688,"state":"open","locked":false,"title":"Content Recommender for the Home Page","user":{"login":"howdyitshelena","id":2066060,"avatar_url":"https://avatars.githubusercontent.com/u/2066060?v=3","gravatar_id":"","url":"https://api.github.com/users/howdyitshelena","html_url":"https://github.com/howdyitshelena","followers_url":"https://api.github.com/users/howdyitshelena/followers","following_url":"https://api.github.com/users/howdyitshelena/following{/other_user}","gists_url":"https://api.github.com/users/howdyitshelena/gists{/gist_id}","starred_url":"https://api.github.com/users/howdyitshelena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howdyitshelena/subscriptions","organizations_url":"https://api.github.com/users/howdyitshelena/orgs","repos_url":"https://api.github.com/users/howdyitshelena/repos","events_url":"https://api.github.com/users/howdyitshelena/events{/privacy}","received_events_url":"https://api.github.com/users/howdyitshelena/received_events","type":"User","site_admin":false},"body":"Team members: @rtibbles, @almgong, @DXCanas, @sialan \r\n\r\nFirst pass at #3368 --\r\n\r\nSummary of changes:\r\nFor student users, there is now a content recommender on the home page with the following cards:\r\n     - Resume (resumes the last visited lesson)\r\n     - Next Steps (shows the next lessons in the topics the student has learned from)\r\n     - Explore (shows suggested topics based off of currently in progress topics and random topics)\r\n\r\nOn the front-end, the cards are standalone, and may be added to any Backbone view. Using Bootstrap, the cards will fit and stretch to any view.\r\n\r\nOn the back-end, there is now an API queryable structure, which used the present structure of the topic tree, different distance metrics, as well as using the metadata that is encoded in the topic tree already in different ways.","created_at":"2015-05-20T23:18:34Z","updated_at":"2015-05-22T22:55:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"46abbca516fa26a02c70d650f7ebdc54f96217b8","assignee":{"login":"aronasorman","id":191955,"avatar_url":"https://avatars.githubusercontent.com/u/191955?v=3","gravatar_id":"","url":"https://api.github.com/users/aronasorman","html_url":"https://github.com/aronasorman","followers_url":"https://api.github.com/users/aronasorman/followers","following_url":"https://api.github.com/users/aronasorman/following{/other_user}","gists_url":"https://api.github.com/users/aronasorman/gists{/gist_id}","starred_url":"https://api.github.com/users/aronasorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aronasorman/subscriptions","organizations_url":"https://api.github.com/users/aronasorman/orgs","repos_url":"https://api.github.com/users/aronasorman/repos","events_url":"https://api.github.com/users/aronasorman/events{/privacy}","received_events_url":"https://api.github.com/users/aronasorman/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/learningequality/ka-lite/milestones/41","html_url":"https://github.com/learningequality/ka-lite/milestones/0.14.0","labels_url":"https://api.github.com/repos/learningequality/ka-lite/milestones/41/labels","id":795036,"number":41,"title":"0.14.0","description":"","creator":{"login":"aronasorman","id":191955,"avatar_url":"https://avatars.githubusercontent.com/u/191955?v=3","gravatar_id":"","url":"https://api.github.com/users/aronasorman","html_url":"https://github.com/aronasorman","followers_url":"https://api.github.com/users/aronasorman/followers","following_url":"https://api.github.com/users/aronasorman/following{/other_user}","gists_url":"https://api.github.com/users/aronasorman/gists{/gist_id}","starred_url":"https://api.github.com/users/aronasorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aronasorman/subscriptions","organizations_url":"https://api.github.com/users/aronasorman/orgs","repos_url":"https://api.github.com/users/aronasorman/repos","events_url":"https://api.github.com/users/aronasorman/events{/privacy}","received_events_url":"https://api.github.com/users/aronasorman/received_events","type":"User","site_admin":false},"open_issues":98,"closed_issues":155,"state":"open","created_at":"2014-09-18T21:53:07Z","updated_at":"2015-05-22T21:35:27Z","due_on":"2015-07-01T07:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/learningequality/ka-lite/pulls/3688/commits","review_comments_url":"https://api.github.com/repos/learningequality/ka-lite/pulls/3688/comments","review_comment_url":"https://api.github.com/repos/learningequality/ka-lite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/learningequality/ka-lite/issues/3688/comments","statuses_url":"https://api.github.com/repos/learningequality/ka-lite/statuses/8f54bbb1f0ef723c6a4de3853a3b5d4032ee87c1","head":{"label":"howdyitshelena:contentrec","ref":"contentrec","sha":"8f54bbb1f0ef723c6a4de3853a3b5d4032ee87c1","user":{"login":"howdyitshelena","id":2066060,"avatar_url":"https://avatars.githubusercontent.com/u/2066060?v=3","gravatar_id":"","url":"https://api.github.com/users/howdyitshelena","html_url":"https://github.com/howdyitshelena","followers_url":"https://api.github.com/users/howdyitshelena/followers","following_url":"https://api.github.com/users/howdyitshelena/following{/other_user}","gists_url":"https://api.github.com/users/howdyitshelena/gists{/gist_id}","starred_url":"https://api.github.com/users/howdyitshelena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howdyitshelena/subscriptions","organizations_url":"https://api.github.com/users/howdyitshelena/orgs","repos_url":"https://api.github.com/users/howdyitshelena/repos","events_url":"https://api.github.com/users/howdyitshelena/events{/privacy}","received_events_url":"https://api.github.com/users/howdyitshelena/received_events","type":"User","site_admin":false},"repo":{"id":25376365,"name":"ka-lite","full_name":"howdyitshelena/ka-lite","owner":{"login":"howdyitshelena","id":2066060,"avatar_url":"https://avatars.githubusercontent.com/u/2066060?v=3","gravatar_id":"","url":"https://api.github.com/users/howdyitshelena","html_url":"https://github.com/howdyitshelena","followers_url":"https://api.github.com/users/howdyitshelena/followers","following_url":"https://api.github.com/users/howdyitshelena/following{/other_user}","gists_url":"https://api.github.com/users/howdyitshelena/gists{/gist_id}","starred_url":"https://api.github.com/users/howdyitshelena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howdyitshelena/subscriptions","organizations_url":"https://api.github.com/users/howdyitshelena/orgs","repos_url":"https://api.github.com/users/howdyitshelena/repos","events_url":"https://api.github.com/users/howdyitshelena/events{/privacy}","received_events_url":"https://api.github.com/users/howdyitshelena/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/howdyitshelena/ka-lite","description":"KA Lite: lightweight web server for serving core Khan Academy content (videos and exercises) without needing internet connectivity","fork":true,"url":"https://api.github.com/repos/howdyitshelena/ka-lite","forks_url":"https://api.github.com/repos/howdyitshelena/ka-lite/forks","keys_url":"https://api.github.com/repos/howdyitshelena/ka-lite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/howdyitshelena/ka-lite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/howdyitshelena/ka-lite/teams","hooks_url":"https://api.github.com/repos/howdyitshelena/ka-lite/hooks","issue_events_url":"https://api.github.com/repos/howdyitshelena/ka-lite/issues/events{/number}","events_url":"https://api.github.com/repos/howdyitshelena/ka-lite/events","assignees_url":"https://api.github.com/repos/howdyitshelena/ka-lite/assignees{/user}","branches_url":"https://api.github.com/repos/howdyitshelena/ka-lite/branches{/branch}","tags_url":"https://api.github.com/repos/howdyitshelena/ka-lite/tags","blobs_url":"https://api.github.com/repos/howdyitshelena/ka-lite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/howdyitshelena/ka-lite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/howdyitshelena/ka-lite/git/refs{/sha}","trees_url":"https://api.github.com/repos/howdyitshelena/ka-lite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/howdyitshelena/ka-lite/statuses/{sha}","languages_url":"https://api.github.com/repos/howdyitshelena/ka-lite/languages","stargazers_url":"https://api.github.com/repos/howdyitshelena/ka-lite/stargazers","contributors_url":"https://api.github.com/repos/howdyitshelena/ka-lite/contributors","subscribers_url":"https://api.github.com/repos/howdyitshelena/ka-lite/subscribers","subscription_url":"https://api.github.com/repos/howdyitshelena/ka-lite/subscription","commits_url":"https://api.github.com/repos/howdyitshelena/ka-lite/commits{/sha}","git_commits_url":"https://api.github.com/repos/howdyitshelena/ka-lite/git/commits{/sha}","comments_url":"https://api.github.com/repos/howdyitshelena/ka-lite/comments{/number}","issue_comment_url":"https://api.github.com/repos/howdyitshelena/ka-lite/issues/comments{/number}","contents_url":"https://api.github.com/repos/howdyitshelena/ka-lite/contents/{+path}","compare_url":"https://api.github.com/repos/howdyitshelena/ka-lite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/howdyitshelena/ka-lite/merges","archive_url":"https://api.github.com/repos/howdyitshelena/ka-lite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/howdyitshelena/ka-lite/downloads","issues_url":"https://api.github.com/repos/howdyitshelena/ka-lite/issues{/number}","pulls_url":"https://api.github.com/repos/howdyitshelena/ka-lite/pulls{/number}","milestones_url":"https://api.github.com/repos/howdyitshelena/ka-lite/milestones{/number}","notifications_url":"https://api.github.com/repos/howdyitshelena/ka-lite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/howdyitshelena/ka-lite/labels{/name}","releases_url":"https://api.github.com/repos/howdyitshelena/ka-lite/releases{/id}","created_at":"2014-10-17T20:43:23Z","updated_at":"2014-10-14T04:05:25Z","pushed_at":"2015-05-22T22:16:24Z","git_url":"git://github.com/howdyitshelena/ka-lite.git","ssh_url":"git@github.com:howdyitshelena/ka-lite.git","clone_url":"https://github.com/howdyitshelena/ka-lite.git","svn_url":"https://github.com/howdyitshelena/ka-lite","homepage":"https://learningequality.org/ka-lite/","size":146162,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"learningequality:develop","ref":"develop","sha":"d869c667dd4999c265052bdcb5f358cf09b85d1f","user":{"login":"learningequality","id":3926525,"avatar_url":"https://avatars.githubusercontent.com/u/3926525?v=3","gravatar_id":"","url":"https://api.github.com/users/learningequality","html_url":"https://github.com/learningequality","followers_url":"https://api.github.com/users/learningequality/followers","following_url":"https://api.github.com/users/learningequality/following{/other_user}","gists_url":"https://api.github.com/users/learningequality/gists{/gist_id}","starred_url":"https://api.github.com/users/learningequality/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/learningequality/subscriptions","organizations_url":"https://api.github.com/users/learningequality/orgs","repos_url":"https://api.github.com/users/learningequality/repos","events_url":"https://api.github.com/users/learningequality/events{/privacy}","received_events_url":"https://api.github.com/users/learningequality/received_events","type":"Organization","site_admin":false},"repo":{"id":5741125,"name":"ka-lite","full_name":"learningequality/ka-lite","owner":{"login":"learningequality","id":3926525,"avatar_url":"https://avatars.githubusercontent.com/u/3926525?v=3","gravatar_id":"","url":"https://api.github.com/users/learningequality","html_url":"https://github.com/learningequality","followers_url":"https://api.github.com/users/learningequality/followers","following_url":"https://api.github.com/users/learningequality/following{/other_user}","gists_url":"https://api.github.com/users/learningequality/gists{/gist_id}","starred_url":"https://api.github.com/users/learningequality/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/learningequality/subscriptions","organizations_url":"https://api.github.com/users/learningequality/orgs","repos_url":"https://api.github.com/users/learningequality/repos","events_url":"https://api.github.com/users/learningequality/events{/privacy}","received_events_url":"https://api.github.com/users/learningequality/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/learningequality/ka-lite","description":"KA Lite: lightweight web server for serving core Khan Academy content (videos and exercises) without needing internet connectivity","fork":false,"url":"https://api.github.com/repos/learningequality/ka-lite","forks_url":"https://api.github.com/repos/learningequality/ka-lite/forks","keys_url":"https://api.github.com/repos/learningequality/ka-lite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/learningequality/ka-lite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/learningequality/ka-lite/teams","hooks_url":"https://api.github.com/repos/learningequality/ka-lite/hooks","issue_events_url":"https://api.github.com/repos/learningequality/ka-lite/issues/events{/number}","events_url":"https://api.github.com/repos/learningequality/ka-lite/events","assignees_url":"https://api.github.com/repos/learningequality/ka-lite/assignees{/user}","branches_url":"https://api.github.com/repos/learningequality/ka-lite/branches{/branch}","tags_url":"https://api.github.com/repos/learningequality/ka-lite/tags","blobs_url":"https://api.github.com/repos/learningequality/ka-lite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/learningequality/ka-lite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/learningequality/ka-lite/git/refs{/sha}","trees_url":"https://api.github.com/repos/learningequality/ka-lite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/learningequality/ka-lite/statuses/{sha}","languages_url":"https://api.github.com/repos/learningequality/ka-lite/languages","stargazers_url":"https://api.github.com/repos/learningequality/ka-lite/stargazers","contributors_url":"https://api.github.com/repos/learningequality/ka-lite/contributors","subscribers_url":"https://api.github.com/repos/learningequality/ka-lite/subscribers","subscription_url":"https://api.github.com/repos/learningequality/ka-lite/subscription","commits_url":"https://api.github.com/repos/learningequality/ka-lite/commits{/sha}","git_commits_url":"https://api.github.com/repos/learningequality/ka-lite/git/commits{/sha}","comments_url":"https://api.github.com/repos/learningequality/ka-lite/comments{/number}","issue_comment_url":"https://api.github.com/repos/learningequality/ka-lite/issues/comments{/number}","contents_url":"https://api.github.com/repos/learningequality/ka-lite/contents/{+path}","compare_url":"https://api.github.com/repos/learningequality/ka-lite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/learningequality/ka-lite/merges","archive_url":"https://api.github.com/repos/learningequality/ka-lite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/learningequality/ka-lite/downloads","issues_url":"https://api.github.com/repos/learningequality/ka-lite/issues{/number}","pulls_url":"https://api.github.com/repos/learningequality/ka-lite/pulls{/number}","milestones_url":"https://api.github.com/repos/learningequality/ka-lite/milestones{/number}","notifications_url":"https://api.github.com/repos/learningequality/ka-lite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/learningequality/ka-lite/labels{/name}","releases_url":"https://api.github.com/repos/learningequality/ka-lite/releases{/id}","created_at":"2012-09-09T20:01:40Z","updated_at":"2015-05-21T00:20:55Z","pushed_at":"2015-05-22T22:16:24Z","git_url":"git://github.com/learningequality/ka-lite.git","ssh_url":"git@github.com:learningequality/ka-lite.git","clone_url":"https://github.com/learningequality/ka-lite.git","svn_url":"https://github.com/learningequality/ka-lite","homepage":"https://learningequality.org/ka-lite/","size":227447,"stargazers_count":210,"watchers_count":210,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":245,"mirror_url":null,"open_issues_count":240,"forks":245,"open_issues":240,"watchers":210,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/3688"},"html":{"href":"https://github.com/learningequality/ka-lite/pull/3688"},"issue":{"href":"https://api.github.com/repos/learningequality/ka-lite/issues/3688"},"comments":{"href":"https://api.github.com/repos/learningequality/ka-lite/issues/3688/comments"},"review_comments":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/3688/comments"},"review_comment":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/3688/commits"},"statuses":{"href":"https://api.github.com/repos/learningequality/ka-lite/statuses/8f54bbb1f0ef723c6a4de3853a3b5d4032ee87c1"}}}}