GitHub PullRequestReviewCommentEvent at 2014-12-23 22:37:53
Repository: edx-analytics-dashboard
Actor: dsjen
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/comments/22239219","id":22239219,"diff_hunk":"@@ -108,6 +109,149 @@ def parse_api_datetime(s):\n     def strip_time(s):\n         return s[:-7]\n \n+    @staticmethod\n+    def _sum_counts(data):\n+        return sum([datum['count'] for datum in data])\n+\n+    @staticmethod\n+    def _calculate_percent(count, total):\n+        return count / float(total) if total > 0 else 0.0\n+\n+    @staticmethod\n+    def _tryint(s):\n+        try:\n+            return int(s)\n+        except ValueError:\n+            return s\n+\n+    @staticmethod\n+    def _alphanum_key(s):\n+        \"\"\"\n+        Turn a string into a list of string and number chunks.\n+        \"z23a\" -> [\"z\", 23, \"a\"]\n+        \"\"\"\n+        return [BasePresenter._tryint(c) for c in re.split('([0-9]+)', s)]\n+\n+    @staticmethod\n+    def _natural_sort(l, field):\n+        \"\"\" Natural sort from Ned Batchelor - http://nedbatchelder.com/blog/200712.html#e20071211T054956 \"\"\"\n+        l.sort(key=lambda x: BasePresenter._alphanum_key(x[field]))\n+\n+\n+class CoursePerformancePresenter(BasePresenter):\n+    \"\"\"\n+    Presenter for the performance page.\n+    \"\"\"\n+\n+    # answer field for numeric values returned from API\n+    NUMERIC_ANSWER_FIELD = 'answer_value_numeric'\n+    # answer field for text values returned from API\n+    TEXT_ANSWER_FIELD = 'answer_value_text'\n+    # limit for the number of bars to display in the answer distribution chart\n+    CHART_LIMIT = 12\n+\n+    def get_answer_distribution(self, module_id, problem_part_id):\n+        \"\"\"\n+        Retrieve answer distributions for a particular module/problem and problem part.\n+        \"\"\"\n+\n+        modules = self.client.modules(self.course_id, module_id)\n+\n+        api_response = modules.answer_distribution()\n+        questions = self._build_questions(api_response)\n+        active_question = [i for i in questions if i['part_id'] == problem_part_id][0]['question']\n+\n+        answer_distributions = self._build_answer_distribution(api_response, problem_part_id)\n+        problem_part_description = self._build_problem_description(problem_part_id, questions)\n+\n+        # check for randomness\n+        is_random = self._is_answer_distribution_random(answer_distributions)\n+        answer_distribution_limited = None\n+        if not is_random:\n+            # only display the top in the chart\n+            answer_distribution_limited = answer_distributions[:self.CHART_LIMIT]\n+\n+        answer_type = self._get_answer_type(answer_distributions)\n+        last_updated = self.parse_api_datetime(answer_distributions[0]['created'])\n+\n+        return last_updated, questions, active_question, answer_distributions, answer_distribution_limited, is_random, \\\n+            answer_type, problem_part_description\n+\n+    def _build_problem_description(self, problem_part_id, questions):\n+        \"\"\" Returns the displayable problem name. \"\"\"\n+        problem = [i for i in questions if i['part_id'] == problem_part_id][0]","path":"analytics_dashboard/courses/presenters.py","position":54,"original_position":82,"commit_id":"f804d485e7239ffe94242a4dec5e43e0f354518c","original_commit_id":"4a8805fd94eff0b0a716bdb667ce04f4e5ae6f5d","user":{"login":"dsjen","id":5265058,"avatar_url":"https://avatars.githubusercontent.com/u/5265058?v=3","gravatar_id":"","url":"https://api.github.com/users/dsjen","html_url":"https://github.com/dsjen","followers_url":"https://api.github.com/users/dsjen/followers","following_url":"https://api.github.com/users/dsjen/following{/other_user}","gists_url":"https://api.github.com/users/dsjen/gists{/gist_id}","starred_url":"https://api.github.com/users/dsjen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsjen/subscriptions","organizations_url":"https://api.github.com/users/dsjen/orgs","repos_url":"https://api.github.com/users/dsjen/repos","events_url":"https://api.github.com/users/dsjen/events{/privacy}","received_events_url":"https://api.github.com/users/dsjen/received_events","type":"User","site_admin":false},"body":"Yes, I think you're right that we should check to ensure that the ID is available.  What do you think about throwing a 404 instead?  The ID could be perfectly valid, but unknown to us at the moment.\r\n\r\nAlso, updated `i` to `q`.","created_at":"2014-12-23T22:37:53Z","updated_at":"2014-12-23T22:37:53Z","html_url":"https://github.com/edx/edx-analytics-dashboard/pull/217#discussion_r22239219","pull_request_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/217","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/comments/22239219"},"html":{"href":"https://github.com/edx/edx-analytics-dashboard/pull/217#discussion_r22239219"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/217"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/217","id":26479811,"html_url":"https://github.com/edx/edx-analytics-dashboard/pull/217","diff_url":"https://github.com/edx/edx-analytics-dashboard/pull/217.diff","patch_url":"https://github.com/edx/edx-analytics-dashboard/pull/217.patch","issue_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues/217","number":217,"state":"open","locked":false,"title":"Added answer distribution page.","user":{"login":"dsjen","id":5265058,"avatar_url":"https://avatars.githubusercontent.com/u/5265058?v=3","gravatar_id":"","url":"https://api.github.com/users/dsjen","html_url":"https://github.com/dsjen","followers_url":"https://api.github.com/users/dsjen/followers","following_url":"https://api.github.com/users/dsjen/following{/other_user}","gists_url":"https://api.github.com/users/dsjen/gists{/gist_id}","starred_url":"https://api.github.com/users/dsjen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsjen/subscriptions","organizations_url":"https://api.github.com/users/dsjen/orgs","repos_url":"https://api.github.com/users/dsjen/repos","events_url":"https://api.github.com/users/dsjen/events{/privacy}","received_events_url":"https://api.github.com/users/dsjen/received_events","type":"User","site_admin":false},"body":"This PR adds a per problem part answer distributions, which displays a chart and table of student responses.  It doesn't include navigation to get to this page (future PR when course structure for performance sections are incorporated).  Most of the copy is as specified by @lamagnifica with pending updates recorded in AN-4243 to be completed in a later PR.  The help link will be updated in a later PR too and recorded in AN-4242.\r\n\r\n![answer-dist](https://cloud.githubusercontent.com/assets/5265058/5530599/e0df1174-89ef-11e4-9e3c-1f11c32366f1.png)\r\n\r\n@rocha @clintonb ","created_at":"2014-12-22T20:44:36Z","updated_at":"2014-12-23T22:37:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b2fb8d32583158fd550d420ecae7fb950932f0f1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/217/commits","review_comments_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/217/comments","review_comment_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/comments/{number}","comments_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues/217/comments","statuses_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/statuses/f804d485e7239ffe94242a4dec5e43e0f354518c","head":{"label":"edx:dsjen/answer-distribution","ref":"dsjen/answer-distribution","sha":"f804d485e7239ffe94242a4dec5e43e0f354518c","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":20941273,"name":"edx-analytics-dashboard","full_name":"edx/edx-analytics-dashboard","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-analytics-dashboard","description":"Dashboard to display course analytics to course teams","fork":false,"url":"https://api.github.com/repos/edx/edx-analytics-dashboard","forks_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/forks","keys_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/teams","hooks_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/events","assignees_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/tags","blobs_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/languages","stargazers_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/subscription","commits_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues/comments/{number}","contents_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/merges","archive_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/downloads","issues_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/releases{/id}","created_at":"2014-06-17T22:14:33Z","updated_at":"2014-12-23T14:45:40Z","pushed_at":"2014-12-23T22:14:22Z","git_url":"git://github.com/edx/edx-analytics-dashboard.git","ssh_url":"git@github.com:edx/edx-analytics-dashboard.git","clone_url":"https://github.com/edx/edx-analytics-dashboard.git","svn_url":"https://github.com/edx/edx-analytics-dashboard","homepage":null,"size":6831,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":3,"forks":14,"open_issues":3,"watchers":10,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"be19831fbe7b2ba203430f61d2b010eaf6d9ccf0","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":20941273,"name":"edx-analytics-dashboard","full_name":"edx/edx-analytics-dashboard","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-analytics-dashboard","description":"Dashboard to display course analytics to course teams","fork":false,"url":"https://api.github.com/repos/edx/edx-analytics-dashboard","forks_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/forks","keys_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/teams","hooks_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/events","assignees_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/tags","blobs_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/languages","stargazers_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/subscription","commits_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues/comments/{number}","contents_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/merges","archive_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/downloads","issues_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-analytics-dashboard/releases{/id}","created_at":"2014-06-17T22:14:33Z","updated_at":"2014-12-23T14:45:40Z","pushed_at":"2014-12-23T22:14:22Z","git_url":"git://github.com/edx/edx-analytics-dashboard.git","ssh_url":"git@github.com:edx/edx-analytics-dashboard.git","clone_url":"https://github.com/edx/edx-analytics-dashboard.git","svn_url":"https://github.com/edx/edx-analytics-dashboard","homepage":null,"size":6831,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":3,"forks":14,"open_issues":3,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/217"},"html":{"href":"https://github.com/edx/edx-analytics-dashboard/pull/217"},"issue":{"href":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues/217"},"comments":{"href":"https://api.github.com/repos/edx/edx-analytics-dashboard/issues/217/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/217/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-analytics-dashboard/pulls/217/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-analytics-dashboard/statuses/f804d485e7239ffe94242a4dec5e43e0f354518c"}}}}