{"action":"created","comment":{"url":"https://api.github.com/repos/SFII/scq/pulls/comments/55858478","id":55858478,"diff_hunk":"@@ -80,11 +81,67 @@ def setUpClass():\n     def test_survey_responses(self):\n         self.respond_to_surveys()\n         results = Survey().get_results('test_survey')\n+        formatted_results = Survey().get_formatted_results('test_survey')\n+        # logging.info(formatted_results)\n         for question_response_id in self.question_response_ids:\n             question_response = QuestionResponse().get_item(question_response_id)\n             question_id = question_response['question_id']\n             response_data = question_response['response_data']\n             self.assertIn(response_data, results[question_id])\n+        for question_id, value in list(results.items()):\n+            for formatted_result_data in formatted_results:\n+                if formatted_result_data['id'] != question_id:\n+                    continue\n+                else:\n+                    self.assertEqual(len(value), len(formatted_result_data['results']))\n+                    self.assertEqual(sorted(value), sorted(formatted_result_data['results']))\n+                    response_format = formatted_result_data['response_format']\n+                    if response_format == Question().RESPONSE_FREE:\n+                        self._test_formatted_response_free(formatted_result_data)\n+                    elif response_format == Question().RESPONSE_RATING:\n+                        self._test_formatted_response_rating(formatted_result_data)\n+                    elif response_format == Question().RESPONSE_TRUE_OR_FALSE:\n+                        self._test_formatted_response_true_or_false(formatted_result_data)\n+                    elif response_format == Question().RESPONSE_MULTIPLE_CHOICE:\n+                        self._test_formatted_response_multiple_choice(formatted_result_data)\n+                    else:\n+                        self.fail(\"unknown response format: {0}\".format(response_format))\n+                    break\n+        return\n+\n+    def test_survey_results_api(self):\n+        formatted_results = Survey().get_formatted_results('test_survey')\n+        with mock.patch.object(BaseHandler, 'get_current_user') as m:\n+            m.return_value = self.user_ids[0]\n+            response = self.fetch('/api/results/test_survey', method=\"GET\")\n+        self.assertEqual(response.code, 200)\n+        self.assertEqual(result, formatted_results)\n+        logging.info(result)\n+\n+    def _test_formatted_response_free(self, formatted_result_data):\n+        self.assertEqual(formatted_result_data['bar_data'], [])\n+        self.assertEqual(formatted_result_data['pie_data'], [])\n+        return\n+\n+    def _test_formatted_response_rating(self, formatted_result_data):\n+        bar_data = formatted_result_data['bar_data']\n+        series_data = bar_data['series'][0]\n+        self.assertNotEqual(bar_data, [])\n+        self.assertEqual(sorted(bar_data['labels']), sorted([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))\n+        self.assertEqual(len(bar_data['labels']),\n+            len(series_data),\n+            \"length of {0} does not match length of {1}\".format(bar_data['labels'], series_data))\n+        self.assertEqual(formatted_result_data['pie_data'], [])\n+        return\n+\n+    def _test_formatted_response_true_or_false(self, formatted_result_data):\n+        self.assertEqual(formatted_result_data['bar_data'], [])\n+        self.assertNotEqual(formatted_result_data['pie_data'], [])\n+        return\n+\n+    def _test_formatted_response_multiple_choice(self, formatted_result_data):","path":"test/test_survey_results.py","position":81,"original_position":81,"commit_id":"3dc4eb35eb75ad5fab23017b2b9690abd84aff9a","original_commit_id":"3dc4eb35eb75ad5fab23017b2b9690abd84aff9a","user":{"login":"untra","id":3855429,"avatar_url":"https://avatars.githubusercontent.com/u/3855429?v=3","gravatar_id":"","url":"https://api.github.com/users/untra","html_url":"https://github.com/untra","followers_url":"https://api.github.com/users/untra/followers","following_url":"https://api.github.com/users/untra/following{/other_user}","gists_url":"https://api.github.com/users/untra/gists{/gist_id}","starred_url":"https://api.github.com/users/untra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/untra/subscriptions","organizations_url":"https://api.github.com/users/untra/orgs","repos_url":"https://api.github.com/users/untra/repos","events_url":"https://api.github.com/users/untra/events{/privacy}","received_events_url":"https://api.github.com/users/untra/received_events","type":"User","site_admin":false},"body":"Multiple choice is still only pick 1. There is no double voting on multiple chocie questions","created_at":"2016-03-11T17:12:49Z","updated_at":"2016-03-11T17:12:49Z","html_url":"https://github.com/SFII/scq/pull/153#discussion_r55858478","pull_request_url":"https://api.github.com/repos/SFII/scq/pulls/153","_links":{"self":{"href":"https://api.github.com/repos/SFII/scq/pulls/comments/55858478"},"html":{"href":"https://github.com/SFII/scq/pull/153#discussion_r55858478"},"pull_request":{"href":"https://api.github.com/repos/SFII/scq/pulls/153"}}},"pull_request":{"url":"https://api.github.com/repos/SFII/scq/pulls/153","id":62027613,"html_url":"https://github.com/SFII/scq/pull/153","diff_url":"https://github.com/SFII/scq/pull/153.diff","patch_url":"https://github.com/SFII/scq/pull/153.patch","issue_url":"https://api.github.com/repos/SFII/scq/issues/153","number":153,"state":"open","locked":false,"title":"Feature/expanded survey results","user":{"login":"untra","id":3855429,"avatar_url":"https://avatars.githubusercontent.com/u/3855429?v=3","gravatar_id":"","url":"https://api.github.com/users/untra","html_url":"https://github.com/untra","followers_url":"https://api.github.com/users/untra/followers","following_url":"https://api.github.com/users/untra/following{/other_user}","gists_url":"https://api.github.com/users/untra/gists{/gist_id}","starred_url":"https://api.github.com/users/untra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/untra/subscriptions","organizations_url":"https://api.github.com/users/untra/orgs","repos_url":"https://api.github.com/users/untra/repos","events_url":"https://api.github.com/users/untra/events{/privacy}","received_events_url":"https://api.github.com/users/untra/received_events","type":"User","site_admin":false},"body":"Added in a new endpoint: GET `api/results/<survey_id>`\r\n\r\nThis returns a formatted set of survey results, with embedded objects ready to be inserted into chartists bars and pies.\r\n\r\n```json\r\n[  \r\n   {  \r\n      \"bar_data\":{  \r\n         \"series\":[  \r\n            [  \r\n               0,\r\n               0,\r\n               1,\r\n               1,\r\n               0,\r\n               1,\r\n               1,\r\n               1,\r\n               0,\r\n               0\r\n            ]\r\n         ],\r\n         \"labels\":[  \r\n            1,\r\n            2,\r\n            3,\r\n            4,\r\n            5,\r\n            6,\r\n            7,\r\n            8,\r\n            9,\r\n            10\r\n         ]\r\n      },\r\n      \"pie_data\":[  \r\n\r\n      ],\r\n      \"options\":[  \r\n\r\n      ],\r\n      \"title\":\"rating\",\r\n      \"id\":\"3c5c245c-9d5e-48b0-b79d-5e69003ebe5e\",\r\n      \"results\":[  \r\n         4,\r\n         8,\r\n         3,\r\n         6,\r\n         7\r\n      ],\r\n      \"total_responses\":5,\r\n      \"response_format\":\"rating\"\r\n   },\r\n   {  \r\n      \"bar_data\":{  \r\n         \"series\":[  \r\n            0\r\n         ],\r\n         \"labels\":[  \r\n            \"alpha\",\r\n            \"delta\",\r\n            \"gamma\"\r\n         ]\r\n      },\r\n      \"pie_data\":[  \r\n         {  \r\n            \"value\":2,\r\n            \"name\":\"alpha\"\r\n         },\r\n         {  \r\n            \"value\":1,\r\n            \"name\":\"delta\"\r\n         },\r\n         {  \r\n            \"value\":2,\r\n            \"name\":\"gamma\"\r\n         }\r\n      ],\r\n      \"options\":[  \r\n         \"alpha\",\r\n         \"beta\",\r\n         \"gamma\",\r\n         \"delta\"\r\n      ],\r\n      \"title\":\"multiple choice\",\r\n      \"id\":\"60b534dc-77f5-4964-b2b5-1fd0f69b53f0\",\r\n      \"results\":[  \r\n         \"alpha\",\r\n         \"gamma\",\r\n         \"alpha\",\r\n         \"gamma\",\r\n         \"delta\"\r\n      ],\r\n      \"total_responses\":5,\r\n      \"response_format\":\"multipleChoice\"\r\n   },\r\n   {  \r\n      \"bar_data\":[  \r\n\r\n      ],\r\n      \"pie_data\":[  \r\n\r\n      ],\r\n      \"options\":[  \r\n\r\n      ],\r\n      \"title\":\"free response\",\r\n      \"id\":\"81f3f49a-0fe7-4571-884c-056f488614e0\",\r\n      \"results\":[  \r\n         \"sed existimo te, sicut nostrum Triarium, minus ab eo delectari, quod ista Platonis, Aristoteli, Theophrasti orationis ornamenta neglexerit.\",\r\n         \"Non eram nescius, Brute, cum, quae summis ingeniis exquisitaque doctrina philosophi Graeco sermone tractavissent, ea Latinis litteris mandaremus, fore ut hic noster labor in varias reprehensiones incurreret.\",\r\n         \"quis enim tam inimicus paene nomini Romano est, qui Ennii Medeam aut Antiopam Pacuvii spernat aut reiciat, quod se isdem Euripidis fabulis delectari dicat, Latinas litteras oderit?\",\r\n         \"Scaevolam M.que Manilium, ab iisque M.\",\r\n         \"Ego autem quem timeam lectorem, cum ad te ne Graecis quidem cedentem in philosophia audeam scribere? quamquam a te ipso id quidem facio provocatus gratissimo mihi libro, quem ad me de virtute misisti.\"\r\n      ],\r\n      \"total_responses\":5,\r\n      \"response_format\":\"freeResponse\"\r\n   },\r\n   {  \r\n      \"bar_data\":[  \r\n\r\n      ],\r\n      \"pie_data\":[  \r\n         {  \r\n            \"value\":5,\r\n            \"name\":\"false\"\r\n         }\r\n      ],\r\n      \"options\":[  \r\n         true,\r\n         false\r\n      ],\r\n      \"title\":\"true or false\",\r\n      \"id\":\"ba692758-148c-4339-b26b-6d9653eb20ac\",\r\n      \"results\":[  \r\n         false,\r\n         false,\r\n         false,\r\n         false,\r\n         false\r\n      ],\r\n      \"total_responses\":5,\r\n      \"response_format\":\"trueOrFalse\"\r\n   }\r\n]\r\n```","created_at":"2016-03-08T05:46:41Z","updated_at":"2016-03-11T17:12:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c61ac50f7c52e3ac92d92bdf12fb7dda357b0b0c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SFII/scq/pulls/153/commits","review_comments_url":"https://api.github.com/repos/SFII/scq/pulls/153/comments","review_comment_url":"https://api.github.com/repos/SFII/scq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SFII/scq/issues/153/comments","statuses_url":"https://api.github.com/repos/SFII/scq/statuses/3dc4eb35eb75ad5fab23017b2b9690abd84aff9a","head":{"label":"untra:feature/expanded_survey_results","ref":"feature/expanded_survey_results","sha":"3dc4eb35eb75ad5fab23017b2b9690abd84aff9a","user":{"login":"untra","id":3855429,"avatar_url":"https://avatars.githubusercontent.com/u/3855429?v=3","gravatar_id":"","url":"https://api.github.com/users/untra","html_url":"https://github.com/untra","followers_url":"https://api.github.com/users/untra/followers","following_url":"https://api.github.com/users/untra/following{/other_user}","gists_url":"https://api.github.com/users/untra/gists{/gist_id}","starred_url":"https://api.github.com/users/untra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/untra/subscriptions","organizations_url":"https://api.github.com/users/untra/orgs","repos_url":"https://api.github.com/users/untra/repos","events_url":"https://api.github.com/users/untra/events{/privacy}","received_events_url":"https://api.github.com/users/untra/received_events","type":"User","site_admin":false},"repo":{"id":42826467,"name":"scq","full_name":"untra/scq","owner":{"login":"untra","id":3855429,"avatar_url":"https://avatars.githubusercontent.com/u/3855429?v=3","gravatar_id":"","url":"https://api.github.com/users/untra","html_url":"https://github.com/untra","followers_url":"https://api.github.com/users/untra/followers","following_url":"https://api.github.com/users/untra/following{/other_user}","gists_url":"https://api.github.com/users/untra/gists{/gist_id}","starred_url":"https://api.github.com/users/untra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/untra/subscriptions","organizations_url":"https://api.github.com/users/untra/orgs","repos_url":"https://api.github.com/users/untra/repos","events_url":"https://api.github.com/users/untra/events{/privacy}","received_events_url":"https://api.github.com/users/untra/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/untra/scq","description":"Our main repo for the SCQ senior project.","fork":true,"url":"https://api.github.com/repos/untra/scq","forks_url":"https://api.github.com/repos/untra/scq/forks","keys_url":"https://api.github.com/repos/untra/scq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/untra/scq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/untra/scq/teams","hooks_url":"https://api.github.com/repos/untra/scq/hooks","issue_events_url":"https://api.github.com/repos/untra/scq/issues/events{/number}","events_url":"https://api.github.com/repos/untra/scq/events","assignees_url":"https://api.github.com/repos/untra/scq/assignees{/user}","branches_url":"https://api.github.com/repos/untra/scq/branches{/branch}","tags_url":"https://api.github.com/repos/untra/scq/tags","blobs_url":"https://api.github.com/repos/untra/scq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/untra/scq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/untra/scq/git/refs{/sha}","trees_url":"https://api.github.com/repos/untra/scq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/untra/scq/statuses/{sha}","languages_url":"https://api.github.com/repos/untra/scq/languages","stargazers_url":"https://api.github.com/repos/untra/scq/stargazers","contributors_url":"https://api.github.com/repos/untra/scq/contributors","subscribers_url":"https://api.github.com/repos/untra/scq/subscribers","subscription_url":"https://api.github.com/repos/untra/scq/subscription","commits_url":"https://api.github.com/repos/untra/scq/commits{/sha}","git_commits_url":"https://api.github.com/repos/untra/scq/git/commits{/sha}","comments_url":"https://api.github.com/repos/untra/scq/comments{/number}","issue_comment_url":"https://api.github.com/repos/untra/scq/issues/comments{/number}","contents_url":"https://api.github.com/repos/untra/scq/contents/{+path}","compare_url":"https://api.github.com/repos/untra/scq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/untra/scq/merges","archive_url":"https://api.github.com/repos/untra/scq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/untra/scq/downloads","issues_url":"https://api.github.com/repos/untra/scq/issues{/number}","pulls_url":"https://api.github.com/repos/untra/scq/pulls{/number}","milestones_url":"https://api.github.com/repos/untra/scq/milestones{/number}","notifications_url":"https://api.github.com/repos/untra/scq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/untra/scq/labels{/name}","releases_url":"https://api.github.com/repos/untra/scq/releases{/id}","deployments_url":"https://api.github.com/repos/untra/scq/deployments","created_at":"2015-09-20T19:33:54Z","updated_at":"2016-01-21T01:31:09Z","pushed_at":"2016-03-08T05:43:01Z","git_url":"git://github.com/untra/scq.git","ssh_url":"git@github.com:untra/scq.git","clone_url":"https://github.com/untra/scq.git","svn_url":"https://github.com/untra/scq","homepage":null,"size":2084,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"SFII:master","ref":"master","sha":"ed67e78ae897c35482e4e963e26c72b15e3a535b","user":{"login":"SFII","id":14222942,"avatar_url":"https://avatars.githubusercontent.com/u/14222942?v=3","gravatar_id":"","url":"https://api.github.com/users/SFII","html_url":"https://github.com/SFII","followers_url":"https://api.github.com/users/SFII/followers","following_url":"https://api.github.com/users/SFII/following{/other_user}","gists_url":"https://api.github.com/users/SFII/gists{/gist_id}","starred_url":"https://api.github.com/users/SFII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SFII/subscriptions","organizations_url":"https://api.github.com/users/SFII/orgs","repos_url":"https://api.github.com/users/SFII/repos","events_url":"https://api.github.com/users/SFII/events{/privacy}","received_events_url":"https://api.github.com/users/SFII/received_events","type":"Organization","site_admin":false},"repo":{"id":42687292,"name":"scq","full_name":"SFII/scq","owner":{"login":"SFII","id":14222942,"avatar_url":"https://avatars.githubusercontent.com/u/14222942?v=3","gravatar_id":"","url":"https://api.github.com/users/SFII","html_url":"https://github.com/SFII","followers_url":"https://api.github.com/users/SFII/followers","following_url":"https://api.github.com/users/SFII/following{/other_user}","gists_url":"https://api.github.com/users/SFII/gists{/gist_id}","starred_url":"https://api.github.com/users/SFII/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SFII/subscriptions","organizations_url":"https://api.github.com/users/SFII/orgs","repos_url":"https://api.github.com/users/SFII/repos","events_url":"https://api.github.com/users/SFII/events{/privacy}","received_events_url":"https://api.github.com/users/SFII/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SFII/scq","description":"Our main repo for the SCQ senior project.","fork":false,"url":"https://api.github.com/repos/SFII/scq","forks_url":"https://api.github.com/repos/SFII/scq/forks","keys_url":"https://api.github.com/repos/SFII/scq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SFII/scq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SFII/scq/teams","hooks_url":"https://api.github.com/repos/SFII/scq/hooks","issue_events_url":"https://api.github.com/repos/SFII/scq/issues/events{/number}","events_url":"https://api.github.com/repos/SFII/scq/events","assignees_url":"https://api.github.com/repos/SFII/scq/assignees{/user}","branches_url":"https://api.github.com/repos/SFII/scq/branches{/branch}","tags_url":"https://api.github.com/repos/SFII/scq/tags","blobs_url":"https://api.github.com/repos/SFII/scq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SFII/scq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SFII/scq/git/refs{/sha}","trees_url":"https://api.github.com/repos/SFII/scq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SFII/scq/statuses/{sha}","languages_url":"https://api.github.com/repos/SFII/scq/languages","stargazers_url":"https://api.github.com/repos/SFII/scq/stargazers","contributors_url":"https://api.github.com/repos/SFII/scq/contributors","subscribers_url":"https://api.github.com/repos/SFII/scq/subscribers","subscription_url":"https://api.github.com/repos/SFII/scq/subscription","commits_url":"https://api.github.com/repos/SFII/scq/commits{/sha}","git_commits_url":"https://api.github.com/repos/SFII/scq/git/commits{/sha}","comments_url":"https://api.github.com/repos/SFII/scq/comments{/number}","issue_comment_url":"https://api.github.com/repos/SFII/scq/issues/comments{/number}","contents_url":"https://api.github.com/repos/SFII/scq/contents/{+path}","compare_url":"https://api.github.com/repos/SFII/scq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SFII/scq/merges","archive_url":"https://api.github.com/repos/SFII/scq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SFII/scq/downloads","issues_url":"https://api.github.com/repos/SFII/scq/issues{/number}","pulls_url":"https://api.github.com/repos/SFII/scq/pulls{/number}","milestones_url":"https://api.github.com/repos/SFII/scq/milestones{/number}","notifications_url":"https://api.github.com/repos/SFII/scq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SFII/scq/labels{/name}","releases_url":"https://api.github.com/repos/SFII/scq/releases{/id}","deployments_url":"https://api.github.com/repos/SFII/scq/deployments","created_at":"2015-09-17T23:24:27Z","updated_at":"2016-03-05T09:35:32Z","pushed_at":"2016-03-09T23:49:47Z","git_url":"git://github.com/SFII/scq.git","ssh_url":"git@github.com:SFII/scq.git","clone_url":"https://github.com/SFII/scq.git","svn_url":"https://github.com/SFII/scq","homepage":null,"size":2167,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":21,"forks":7,"open_issues":21,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SFII/scq/pulls/153"},"html":{"href":"https://github.com/SFII/scq/pull/153"},"issue":{"href":"https://api.github.com/repos/SFII/scq/issues/153"},"comments":{"href":"https://api.github.com/repos/SFII/scq/issues/153/comments"},"review_comments":{"href":"https://api.github.com/repos/SFII/scq/pulls/153/comments"},"review_comment":{"href":"https://api.github.com/repos/SFII/scq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SFII/scq/pulls/153/commits"},"statuses":{"href":"https://api.github.com/repos/SFII/scq/statuses/3dc4eb35eb75ad5fab23017b2b9690abd84aff9a"}}}}