{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/33384869","id":33384869,"diff_hunk":"@@ -831,16 +841,110 @@ def assign_choice_names(self):\n             if not choice.get('id'):\n                 choice.set(\"id\", chr(ord(\"A\") + index))\n \n+    def grade_via_edc(self, all_choices, student_answer, student_non_answers):\n+        \"\"\"\n+        Calculates partial credit on the EDC scheme.\n+        For each correctly selected or correctly blank choice, score 1 point.\n+        Divide by total number of choices.\n+        Returns a CorrectMap.\n+        \"\"\"\n+\n+        edc_max_grade = len(all_choices)\n+        edc_current_grade = 0\n+\n+        good_answers = sum([1 for answer in student_answer if answer in self.correct_choices])\n+        good_non_answers = sum([1 for blank in student_non_answers if blank in self.incorrect_choices])\n+        edc_current_grade = good_answers + good_non_answers\n+\n+        return_grade = round(self.get_max_score() * float(edc_current_grade) / float(edc_max_grade), 2)\n+\n+        if edc_current_grade > 0:\n+            return CorrectMap(self.answer_id, correctness='partially-correct', npoints=return_grade)\n+        else:\n+            return CorrectMap(self.answer_id, correctness='incorrect', npoints=0)\n+\n+    def grade_via_halves(self, all_choices, student_answer, student_non_answers):\n+        \"\"\"\n+        Calculates partial credit on the Halves scheme.\n+        If no errors, full credit.\n+        If one error, half credit as long as there are 3+ choices\n+        If two errors, 1/4 credit as long as there are 5+ choices\n+        (If not enough choices, no credit.)\n+        Returns a CorrectMap\n+        \"\"\"\n+\n+        halves_error_count = 0\n+\n+        incorrect_answers = sum([1 for answer in student_answer if answer in self.incorrect_choices])\n+        missed_answers = sum([1 for blank in student_non_answers if blank in self.correct_choices])\n+        halves_error_count = incorrect_answers + missed_answers\n+\n+        if halves_error_count == 0:\n+            return_grade = self.get_max_score()\n+            return CorrectMap(self.answer_id, correctness='correct', npoints=return_grade)\n+        elif halves_error_count == 1 and len(all_choices) > 2:\n+            return_grade = round(self.get_max_score() / 2.0, 2)\n+            return CorrectMap(self.answer_id, correctness='partially-correct', npoints=return_grade)\n+        elif halves_error_count == 2 and len(all_choices) > 4:\n+            return_grade = round(self.get_max_score() / 4.0, 2)\n+            return CorrectMap(self.answer_id, correctness='partially-correct', npoints=return_grade)\n+        else:\n+            return CorrectMap(self.answer_id, 'incorrect')\n+\n     def get_score(self, student_answers):\n \n+        # Setting up answer lists:\n+        #  all_choices: the full list of checkboxes\n+        #  student_answer: what the student actually chose (note no \"s\")\n+        #  student_non_answer: what they didn't choose\n+        #  self.correct_choices: boxes that should be checked\n+        #  self.incorrect_choices: boxes that should NOT be checked\n+\n+        all_choices = self.correct_choices.union(self.incorrect_choices)\n+\n         student_answer = student_answers.get(self.answer_id, [])\n \n         if not isinstance(student_answer, list):\n             student_answer = [student_answer]\n \n+        # \"None apply\" should really be a valid choice for \"check all that apply\",\n+        # but it throws an error if all the checks are blank.\n         no_empty_answer = student_answer != []\n+\n         student_answer = set(student_answer)\n \n+        student_non_answers = all_choices - student_answer\n+\n+        if not no_empty_answer:\n+            return CorrectMap(self.answer_id, 'incorrect')\n+\n+        # This below checks to see whether we're using an alternate grading scheme.\n+        #  Set partial_credit=\"false\" (or remove it) to require an exact answer for any credit.\n+        #  Set partial_credit=\"EDC\" to count each choice for equal points (Every Decision Counts).\n+        #  Set partial_credit=\"halves\" to take half credit off for each error.\n+\n+        tree = self.xml\n+        problem_xml = tree.xpath('.')","path":"common/lib/capa/capa/responsetypes.py","position":112,"original_position":112,"commit_id":"8af119c5968b9476fb4d52dc11dc0dddb021b034","original_commit_id":"8af119c5968b9476fb4d52dc11dc0dddb021b034","user":{"login":"Colin-Fredericks","id":1929508,"avatar_url":"https://avatars.githubusercontent.com/u/1929508?v=3","gravatar_id":"","url":"https://api.github.com/users/Colin-Fredericks","html_url":"https://github.com/Colin-Fredericks","followers_url":"https://api.github.com/users/Colin-Fredericks/followers","following_url":"https://api.github.com/users/Colin-Fredericks/following{/other_user}","gists_url":"https://api.github.com/users/Colin-Fredericks/gists{/gist_id}","starred_url":"https://api.github.com/users/Colin-Fredericks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Colin-Fredericks/subscriptions","organizations_url":"https://api.github.com/users/Colin-Fredericks/orgs","repos_url":"https://api.github.com/users/Colin-Fredericks/repos","events_url":"https://api.github.com/users/Colin-Fredericks/events{/privacy}","received_events_url":"https://api.github.com/users/Colin-Fredericks/received_events","type":"User","site_admin":false},"body":"Moving into LoncapaResponse class; will compactify there.","created_at":"2015-06-26T18:55:16Z","updated_at":"2015-06-26T18:55:16Z","html_url":"https://github.com/edx/edx-platform/pull/8574#discussion_r33384869","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/8574","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/33384869"},"html":{"href":"https://github.com/edx/edx-platform/pull/8574#discussion_r33384869"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/8574"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/8574","id":38046866,"html_url":"https://github.com/edx/edx-platform/pull/8574","diff_url":"https://github.com/edx/edx-platform/pull/8574.diff","patch_url":"https://github.com/edx/edx-platform/pull/8574.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/8574","number":8574,"state":"open","locked":false,"title":"OSPR-535 Partial Credit","user":{"login":"Colin-Fredericks","id":1929508,"avatar_url":"https://avatars.githubusercontent.com/u/1929508?v=3","gravatar_id":"","url":"https://api.github.com/users/Colin-Fredericks","html_url":"https://github.com/Colin-Fredericks","followers_url":"https://api.github.com/users/Colin-Fredericks/followers","following_url":"https://api.github.com/users/Colin-Fredericks/following{/other_user}","gists_url":"https://api.github.com/users/Colin-Fredericks/gists{/gist_id}","starred_url":"https://api.github.com/users/Colin-Fredericks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Colin-Fredericks/subscriptions","organizations_url":"https://api.github.com/users/Colin-Fredericks/orgs","repos_url":"https://api.github.com/users/Colin-Fredericks/repos","events_url":"https://api.github.com/users/Colin-Fredericks/events{/privacy}","received_events_url":"https://api.github.com/users/Colin-Fredericks/received_events","type":"User","site_admin":false},"body":"This enables partial credit as discussed here:\r\nhttps://openedx.atlassian.net/browse/OSPR-535\r\nand further detailed here:\r\nhttps://docs.google.com/document/d/12CZwqG5WdQreFoZMiIxezQMh5KDtjHy7xEWKwJ71F9w/edit?usp=sharing\r\n\r\n","created_at":"2015-06-18T20:04:25Z","updated_at":"2015-06-26T18:55:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b38eb8d2805ffbfdaca11a68737c7a7230a36f7c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/8574/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/8574/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/8574/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/8af119c5968b9476fb4d52dc11dc0dddb021b034","head":{"label":"Colin-Fredericks:master","ref":"master","sha":"8af119c5968b9476fb4d52dc11dc0dddb021b034","user":{"login":"Colin-Fredericks","id":1929508,"avatar_url":"https://avatars.githubusercontent.com/u/1929508?v=3","gravatar_id":"","url":"https://api.github.com/users/Colin-Fredericks","html_url":"https://github.com/Colin-Fredericks","followers_url":"https://api.github.com/users/Colin-Fredericks/followers","following_url":"https://api.github.com/users/Colin-Fredericks/following{/other_user}","gists_url":"https://api.github.com/users/Colin-Fredericks/gists{/gist_id}","starred_url":"https://api.github.com/users/Colin-Fredericks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Colin-Fredericks/subscriptions","organizations_url":"https://api.github.com/users/Colin-Fredericks/orgs","repos_url":"https://api.github.com/users/Colin-Fredericks/repos","events_url":"https://api.github.com/users/Colin-Fredericks/events{/privacy}","received_events_url":"https://api.github.com/users/Colin-Fredericks/received_events","type":"User","site_admin":false},"repo":{"id":36953987,"name":"edx-platform","full_name":"Colin-Fredericks/edx-platform","owner":{"login":"Colin-Fredericks","id":1929508,"avatar_url":"https://avatars.githubusercontent.com/u/1929508?v=3","gravatar_id":"","url":"https://api.github.com/users/Colin-Fredericks","html_url":"https://github.com/Colin-Fredericks","followers_url":"https://api.github.com/users/Colin-Fredericks/followers","following_url":"https://api.github.com/users/Colin-Fredericks/following{/other_user}","gists_url":"https://api.github.com/users/Colin-Fredericks/gists{/gist_id}","starred_url":"https://api.github.com/users/Colin-Fredericks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Colin-Fredericks/subscriptions","organizations_url":"https://api.github.com/users/Colin-Fredericks/orgs","repos_url":"https://api.github.com/users/Colin-Fredericks/repos","events_url":"https://api.github.com/users/Colin-Fredericks/events{/privacy}","received_events_url":"https://api.github.com/users/Colin-Fredericks/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Colin-Fredericks/edx-platform","description":"Open edX, the edX platform that powers http://edx.org","fork":true,"url":"https://api.github.com/repos/Colin-Fredericks/edx-platform","forks_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/forks","keys_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/teams","hooks_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/events","assignees_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/tags","blobs_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/languages","stargazers_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/subscription","commits_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/merges","archive_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/downloads","issues_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/Colin-Fredericks/edx-platform/releases{/id}","created_at":"2015-06-05T20:30:12Z","updated_at":"2015-06-05T20:30:40Z","pushed_at":"2015-06-24T18:29:00Z","git_url":"git://github.com/Colin-Fredericks/edx-platform.git","ssh_url":"git@github.com:Colin-Fredericks/edx-platform.git","clone_url":"https://github.com/Colin-Fredericks/edx-platform.git","svn_url":"https://github.com/Colin-Fredericks/edx-platform","homepage":"http://openedx.org/","size":495114,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"9e7852352a9098f8e12a527da556325b47042b52","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":10391073,"name":"edx-platform","full_name":"edx/edx-platform","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-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-06-25T20:28:29Z","pushed_at":"2015-06-26T18:52:53Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":2065475,"stargazers_count":2007,"watchers_count":2007,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1153,"mirror_url":null,"open_issues_count":160,"forks":1153,"open_issues":160,"watchers":2007,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/8574"},"html":{"href":"https://github.com/edx/edx-platform/pull/8574"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/8574"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/8574/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/8574/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/8574/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/8af119c5968b9476fb4d52dc11dc0dddb021b034"}}}}