{"action":"created","comment":{"url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments/68182962","id":68182962,"diff_hunk":"@@ -0,0 +1,77 @@\n+(function($) {\n+  'use strict';\n+  var DOCUMENT_SELECTOR = '.course-assessment-submission-submissions.edit ';\n+  var GRADE_INPUT_SELECTOR = 'input.grade';\n+  var POINTS_AWARDED_SELECTOR = 'input.submission-points-awarded';\n+  var MAXIMUM_GRADE_SELECTOR = '#submission-statistics-maximum-grade';\n+  var TOTAL_GRADE_SELECTOR = '#submission-statistics-total-grade';\n+\n+  /**\n+   * Handles the event when a submission answer is graded or when the grade\n+   * is changed. If the new grade is valid, three items are updated:\n+   * - The grade for the question in the grades summary\n+   * - The total grade in the submissions statistics\n+   * - The experience points awarded\n+   *\n+   * @param {Event} e The event object.\n+   */\n+  function updateGradesAndPoints(event) {\n+    var $changedGradeInput = $(event.target);\n+    var newGrade = $changedGradeInput.val();\n+\n+    if (!$.isNumeric(newGrade)) { return; }\n+\n+    var answerId = $changedGradeInput.data('answer-id');\n+    var newTotalGrade = computeNewTotalGrade();\n+    updateGradesSummary(answerId, newGrade);\n+    updateTotalGrade(newTotalGrade);\n+    updateExperiencePointsAwarded(newTotalGrade);\n+  }\n+\n+  /**\n+   * Sums the grades of individual answers\n+   *\n+   * @return {Number} The new total grade for the submission\n+   */\n+  function computeNewTotalGrade() {\n+    return $(GRADE_INPUT_SELECTOR).toArray().reduce(function(sum, element) {\n+      return sum + Number(element.value);\n+    }, 0);\n+  }\n+\n+  /**\n+   * Updates the grade for a particular answer in the grades summary\n+   *\n+   * @param {Number} answerId The answer's ID\n+   * @param {Number} newGrade The new grade\n+   */\n+  function updateGradesSummary(answerId, newGrade) {\n+    $('#submission-grades-summary-answer-' + answerId + '-grade').html(newGrade);\n+  }\n+\n+  /**\n+   * Updates the total grade in the submissions statistics\n+   *\n+   * @param {Number} newTotalGrade The new total grade\n+   */\n+  function updateTotalGrade(newTotalGrade) {\n+    $(TOTAL_GRADE_SELECTOR).html(newTotalGrade);\n+  }\n+\n+  /**\n+   * Computes and updates the experience points awarded for the submission based on\n+   * the fraction of the maximum grade attained.\n+   *\n+   * @param {Number} newTotalGrade The new total grade\n+   */\n+  function updateExperiencePointsAwarded(newTotalGrade) {\n+    var $pointsAwardedInput = $(POINTS_AWARDED_SELECTOR);\n+    var basePoints = $pointsAwardedInput.data('base-exp');\n+    var maximumGrade = $(MAXIMUM_GRADE_SELECTOR).html();\n+    var newPointsAwarded =\n+      maximumGrade === 0 ? 0 : Math.floor(basePoints * newTotalGrade / maximumGrade);\n+    $pointsAwardedInput.val(newPointsAwarded);\n+  }\n+\n+  $(document).on('change', DOCUMENT_SELECTOR + GRADE_INPUT_SELECTOR, updateGradesAndPoints);\n+})(jQuery);","path":"app/assets/javascripts/course/assessment/submission/submission.js","position":77,"original_position":77,"commit_id":"4e35d93939d9e62a61030b607e37652074427baf","original_commit_id":"4e35d93939d9e62a61030b607e37652074427baf","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"'jQuery' is not defined.","created_at":"2016-06-23T06:47:26Z","updated_at":"2016-06-23T06:47:26Z","html_url":"https://github.com/Coursemology/coursemology2/pull/1124#discussion_r68182962","pull_request_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/1124","_links":{"self":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments/68182962"},"html":{"href":"https://github.com/Coursemology/coursemology2/pull/1124#discussion_r68182962"},"pull_request":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/1124"}}},"pull_request":{"url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/1124","id":74776199,"html_url":"https://github.com/Coursemology/coursemology2/pull/1124","diff_url":"https://github.com/Coursemology/coursemology2/pull/1124.diff","patch_url":"https://github.com/Coursemology/coursemology2/pull/1124.patch","issue_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/1124","number":1124,"state":"open","locked":false,"title":"Automatically compute experience points awarded when grading submission","user":{"login":"kxmbrian","id":6252919,"avatar_url":"https://avatars.githubusercontent.com/u/6252919?v=3","gravatar_id":"","url":"https://api.github.com/users/kxmbrian","html_url":"https://github.com/kxmbrian","followers_url":"https://api.github.com/users/kxmbrian/followers","following_url":"https://api.github.com/users/kxmbrian/following{/other_user}","gists_url":"https://api.github.com/users/kxmbrian/gists{/gist_id}","starred_url":"https://api.github.com/users/kxmbrian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kxmbrian/subscriptions","organizations_url":"https://api.github.com/users/kxmbrian/orgs","repos_url":"https://api.github.com/users/kxmbrian/repos","events_url":"https://api.github.com/users/kxmbrian/events{/privacy}","received_events_url":"https://api.github.com/users/kxmbrian/received_events","type":"User","site_admin":false},"body":"Addresses #688 \r\n\r\nThe exact points awarding scheme might need to be refined, for example, to take into account time-based bonus experience points (#1123).\r\n\r\nThe experience points awarding for auto-graded assessments will be addressed in a separate PR.","created_at":"2016-06-22T12:38:03Z","updated_at":"2016-06-23T06:47:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8d80c66e092244d37a6761d60bdeeffcd5858c77","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/1124/commits","review_comments_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/1124/comments","review_comment_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/1124/comments","statuses_url":"https://api.github.com/repos/Coursemology/coursemology2/statuses/4e35d93939d9e62a61030b607e37652074427baf","head":{"label":"coursemology-collab:kxmbrian/autofill-exp","ref":"kxmbrian/autofill-exp","sha":"4e35d93939d9e62a61030b607e37652074427baf","user":{"login":"coursemology-collab","id":8666458,"avatar_url":"https://avatars.githubusercontent.com/u/8666458?v=3","gravatar_id":"","url":"https://api.github.com/users/coursemology-collab","html_url":"https://github.com/coursemology-collab","followers_url":"https://api.github.com/users/coursemology-collab/followers","following_url":"https://api.github.com/users/coursemology-collab/following{/other_user}","gists_url":"https://api.github.com/users/coursemology-collab/gists{/gist_id}","starred_url":"https://api.github.com/users/coursemology-collab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coursemology-collab/subscriptions","organizations_url":"https://api.github.com/users/coursemology-collab/orgs","repos_url":"https://api.github.com/users/coursemology-collab/repos","events_url":"https://api.github.com/users/coursemology-collab/events{/privacy}","received_events_url":"https://api.github.com/users/coursemology-collab/received_events","type":"Organization","site_admin":false},"repo":{"id":23697674,"name":"coursemology2","full_name":"coursemology-collab/coursemology2","owner":{"login":"coursemology-collab","id":8666458,"avatar_url":"https://avatars.githubusercontent.com/u/8666458?v=3","gravatar_id":"","url":"https://api.github.com/users/coursemology-collab","html_url":"https://github.com/coursemology-collab","followers_url":"https://api.github.com/users/coursemology-collab/followers","following_url":"https://api.github.com/users/coursemology-collab/following{/other_user}","gists_url":"https://api.github.com/users/coursemology-collab/gists{/gist_id}","starred_url":"https://api.github.com/users/coursemology-collab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coursemology-collab/subscriptions","organizations_url":"https://api.github.com/users/coursemology-collab/orgs","repos_url":"https://api.github.com/users/coursemology-collab/repos","events_url":"https://api.github.com/users/coursemology-collab/events{/privacy}","received_events_url":"https://api.github.com/users/coursemology-collab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coursemology-collab/coursemology2","description":"Rails 4 re-write of Coursemology","fork":true,"url":"https://api.github.com/repos/coursemology-collab/coursemology2","forks_url":"https://api.github.com/repos/coursemology-collab/coursemology2/forks","keys_url":"https://api.github.com/repos/coursemology-collab/coursemology2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coursemology-collab/coursemology2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coursemology-collab/coursemology2/teams","hooks_url":"https://api.github.com/repos/coursemology-collab/coursemology2/hooks","issue_events_url":"https://api.github.com/repos/coursemology-collab/coursemology2/issues/events{/number}","events_url":"https://api.github.com/repos/coursemology-collab/coursemology2/events","assignees_url":"https://api.github.com/repos/coursemology-collab/coursemology2/assignees{/user}","branches_url":"https://api.github.com/repos/coursemology-collab/coursemology2/branches{/branch}","tags_url":"https://api.github.com/repos/coursemology-collab/coursemology2/tags","blobs_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/refs{/sha}","trees_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coursemology-collab/coursemology2/statuses/{sha}","languages_url":"https://api.github.com/repos/coursemology-collab/coursemology2/languages","stargazers_url":"https://api.github.com/repos/coursemology-collab/coursemology2/stargazers","contributors_url":"https://api.github.com/repos/coursemology-collab/coursemology2/contributors","subscribers_url":"https://api.github.com/repos/coursemology-collab/coursemology2/subscribers","subscription_url":"https://api.github.com/repos/coursemology-collab/coursemology2/subscription","commits_url":"https://api.github.com/repos/coursemology-collab/coursemology2/commits{/sha}","git_commits_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/commits{/sha}","comments_url":"https://api.github.com/repos/coursemology-collab/coursemology2/comments{/number}","issue_comment_url":"https://api.github.com/repos/coursemology-collab/coursemology2/issues/comments{/number}","contents_url":"https://api.github.com/repos/coursemology-collab/coursemology2/contents/{+path}","compare_url":"https://api.github.com/repos/coursemology-collab/coursemology2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coursemology-collab/coursemology2/merges","archive_url":"https://api.github.com/repos/coursemology-collab/coursemology2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coursemology-collab/coursemology2/downloads","issues_url":"https://api.github.com/repos/coursemology-collab/coursemology2/issues{/number}","pulls_url":"https://api.github.com/repos/coursemology-collab/coursemology2/pulls{/number}","milestones_url":"https://api.github.com/repos/coursemology-collab/coursemology2/milestones{/number}","notifications_url":"https://api.github.com/repos/coursemology-collab/coursemology2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coursemology-collab/coursemology2/labels{/name}","releases_url":"https://api.github.com/repos/coursemology-collab/coursemology2/releases{/id}","deployments_url":"https://api.github.com/repos/coursemology-collab/coursemology2/deployments","created_at":"2014-09-05T09:32:07Z","updated_at":"2016-02-07T09:46:54Z","pushed_at":"2016-06-23T06:47:19Z","git_url":"git://github.com/coursemology-collab/coursemology2.git","ssh_url":"git@github.com:coursemology-collab/coursemology2.git","clone_url":"https://github.com/coursemology-collab/coursemology2.git","svn_url":"https://github.com/coursemology-collab/coursemology2","homepage":null,"size":4104,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":3,"default_branch":"master"}},"base":{"label":"Coursemology:master","ref":"master","sha":"5ac385ce8bad495cb14423336eb78d94e927f45a","user":{"login":"Coursemology","id":4427741,"avatar_url":"https://avatars.githubusercontent.com/u/4427741?v=3","gravatar_id":"","url":"https://api.github.com/users/Coursemology","html_url":"https://github.com/Coursemology","followers_url":"https://api.github.com/users/Coursemology/followers","following_url":"https://api.github.com/users/Coursemology/following{/other_user}","gists_url":"https://api.github.com/users/Coursemology/gists{/gist_id}","starred_url":"https://api.github.com/users/Coursemology/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Coursemology/subscriptions","organizations_url":"https://api.github.com/users/Coursemology/orgs","repos_url":"https://api.github.com/users/Coursemology/repos","events_url":"https://api.github.com/users/Coursemology/events{/privacy}","received_events_url":"https://api.github.com/users/Coursemology/received_events","type":"Organization","site_admin":false},"repo":{"id":22155032,"name":"coursemology2","full_name":"Coursemology/coursemology2","owner":{"login":"Coursemology","id":4427741,"avatar_url":"https://avatars.githubusercontent.com/u/4427741?v=3","gravatar_id":"","url":"https://api.github.com/users/Coursemology","html_url":"https://github.com/Coursemology","followers_url":"https://api.github.com/users/Coursemology/followers","following_url":"https://api.github.com/users/Coursemology/following{/other_user}","gists_url":"https://api.github.com/users/Coursemology/gists{/gist_id}","starred_url":"https://api.github.com/users/Coursemology/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Coursemology/subscriptions","organizations_url":"https://api.github.com/users/Coursemology/orgs","repos_url":"https://api.github.com/users/Coursemology/repos","events_url":"https://api.github.com/users/Coursemology/events{/privacy}","received_events_url":"https://api.github.com/users/Coursemology/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Coursemology/coursemology2","description":"Rails 4 re-write of Coursemology","fork":false,"url":"https://api.github.com/repos/Coursemology/coursemology2","forks_url":"https://api.github.com/repos/Coursemology/coursemology2/forks","keys_url":"https://api.github.com/repos/Coursemology/coursemology2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Coursemology/coursemology2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Coursemology/coursemology2/teams","hooks_url":"https://api.github.com/repos/Coursemology/coursemology2/hooks","issue_events_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/events{/number}","events_url":"https://api.github.com/repos/Coursemology/coursemology2/events","assignees_url":"https://api.github.com/repos/Coursemology/coursemology2/assignees{/user}","branches_url":"https://api.github.com/repos/Coursemology/coursemology2/branches{/branch}","tags_url":"https://api.github.com/repos/Coursemology/coursemology2/tags","blobs_url":"https://api.github.com/repos/Coursemology/coursemology2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Coursemology/coursemology2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Coursemology/coursemology2/git/refs{/sha}","trees_url":"https://api.github.com/repos/Coursemology/coursemology2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Coursemology/coursemology2/statuses/{sha}","languages_url":"https://api.github.com/repos/Coursemology/coursemology2/languages","stargazers_url":"https://api.github.com/repos/Coursemology/coursemology2/stargazers","contributors_url":"https://api.github.com/repos/Coursemology/coursemology2/contributors","subscribers_url":"https://api.github.com/repos/Coursemology/coursemology2/subscribers","subscription_url":"https://api.github.com/repos/Coursemology/coursemology2/subscription","commits_url":"https://api.github.com/repos/Coursemology/coursemology2/commits{/sha}","git_commits_url":"https://api.github.com/repos/Coursemology/coursemology2/git/commits{/sha}","comments_url":"https://api.github.com/repos/Coursemology/coursemology2/comments{/number}","issue_comment_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/comments{/number}","contents_url":"https://api.github.com/repos/Coursemology/coursemology2/contents/{+path}","compare_url":"https://api.github.com/repos/Coursemology/coursemology2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Coursemology/coursemology2/merges","archive_url":"https://api.github.com/repos/Coursemology/coursemology2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Coursemology/coursemology2/downloads","issues_url":"https://api.github.com/repos/Coursemology/coursemology2/issues{/number}","pulls_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls{/number}","milestones_url":"https://api.github.com/repos/Coursemology/coursemology2/milestones{/number}","notifications_url":"https://api.github.com/repos/Coursemology/coursemology2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Coursemology/coursemology2/labels{/name}","releases_url":"https://api.github.com/repos/Coursemology/coursemology2/releases{/id}","deployments_url":"https://api.github.com/repos/Coursemology/coursemology2/deployments","created_at":"2014-07-23T14:57:06Z","updated_at":"2016-05-30T01:30:43Z","pushed_at":"2016-06-23T06:47:20Z","git_url":"git://github.com/Coursemology/coursemology2.git","ssh_url":"git@github.com:Coursemology/coursemology2.git","clone_url":"https://github.com/Coursemology/coursemology2.git","svn_url":"https://github.com/Coursemology/coursemology2","homepage":null,"size":5628,"stargazers_count":24,"watchers_count":24,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":92,"forks":18,"open_issues":92,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/1124"},"html":{"href":"https://github.com/Coursemology/coursemology2/pull/1124"},"issue":{"href":"https://api.github.com/repos/Coursemology/coursemology2/issues/1124"},"comments":{"href":"https://api.github.com/repos/Coursemology/coursemology2/issues/1124/comments"},"review_comments":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/1124/comments"},"review_comment":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/1124/commits"},"statuses":{"href":"https://api.github.com/repos/Coursemology/coursemology2/statuses/4e35d93939d9e62a61030b607e37652074427baf"}}}}
{"actor":{"display_login":"houndci-bot"}}