{"action":"created","comment":{"url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/comments/36130396","id":36130396,"diff_hunk":"@@ -15,4 +15,115 @@ def populate\n   def get_marking_scheme_details\n     redirect_to url_for(controller: 'marking_schemes', action: 'populate')\n   end\n+\n+  def download_csv_grades_report\n+    assignments = Assignment.order(:id)\n+    csv_string = CSV.generate do |csv|\n+      # Populates the entire CSV with headers, students and their marks\n+      populated_csv = populate_students_and_marks(csv)\n+    end\n+    course_name = \"#{COURSE_NAME}\"\n+    course_name_underscore = course_name.squish.downcase.tr(\" \", \"_\")\n+    send_data csv_string, disposition: 'attachment',\n+                          filename: \"#{course_name_underscore}_grades_report.csv\"\n+  end\n+end\n+\n+# ---- HELPER FUNCTIONS FOR DOWNLOAD_CSV_GRADES_REPORT BELOW-----#\n+\n+# Helper function for download_csv_grades_report. Populates the headers in the CSV\n+def populate_header_titles(assignments)\n+  header = ['Username']\n+  assignments.each do |assignment|\n+    header.push(assignment.short_identifier)\n+  end\n+  header.push('Total marks')\n+end\n+\n+# Helper function for populate_students_and_marks. Checks grouping, submission and it's mark for nil.\n+def fill_row_with_marks(grouping, row)\n+  if check_for_nil_fields(grouping)\n+    row.push('')\n+  else\n+    row.push(grouping.current_submission_used.get_latest_result.total_mark/grouping.assignment.total_mark * 100)\n+  end\n+  row\n+end\n+\n+# Helper function for download_csv_grades_report. Loads up the CSV with headers, students and marks.\n+def populate_students_and_marks(csv)\n+  students = Student.all\n+  assignments = Assignment.order(:id)\n+  # Populates the csv header titles here\n+  csv << populate_header_titles(assignments)\n+  students.each do |student|\n+    total_mark = 0\n+    row = []\n+    row.push(student.user_name)\n+    assignments.each do |assignment|\n+      grouping = student.accepted_grouping_for(assignment.id)\n+      # Check for nil fields. If not nil, then fill up the rows!\n+      row = fill_row_with_marks(grouping, row)\n+      total_mark += get_total_marks_for_student(grouping)\n+    end\n+    row.push(total_mark)\n+    csv << row\n+  end\n+  csv\n+end\n+\n+# Return the total marks for that student with its appropriate weights\n+def get_total_marks_for_student(grouping)\n+  current_total_marks = 0\n+  if not check_for_nil_fields(grouping)\n+    # Create Hashmap with Criteria ID as keys and it's weight as values\n+    criteria_id_to_weight = return_criteria_to_weight_for_grouping(grouping)\n+    get_assignment_marks(grouping).each do |mark|\n+      current_total_marks += mark.mark * criteria_id_to_weight[mark.markable_id].to_f\n+    end\n+  end\n+  current_total_marks\n+end\n+\n+# Function that is called to check for nill grouping, submissions and marks\n+def check_for_nil_fields(grouping)\n+  if grouping.nil? || grouping.current_submission_used.nil? ||\n+    (grouping.current_submission_used.get_latest_result.total_mark/grouping.assignment.total_mark * 100).nan?\n+    return true\n+  else \n+    return false\n+  end\n+end\n+\n+# Returns the appropriate criteria for a group assignment\n+def return_criteria_to_weight_for_grouping(grouping)\n+  criteria_id_to_weight = {}\n+  if grouping.assignment.marking_scheme_type == 'rubric'\n+    criteria_id_to_weight = map_criteria_id_to_weight('rubric', \n+      grouping.assignment.rubric_criteria)\n+  elsif grouping.assignment.marking_scheme_type == 'flexible'\n+    criteria_id_to_weight = map_criteria_id_to_weight('flexible', ","path":"app/controllers/course_summaries_controller.rb","position":91,"original_position":91,"commit_id":"b90f8cb0fe34d7813c09e564ae89f8f83420d8a7","original_commit_id":"b90f8cb0fe34d7813c09e564ae89f8f83420d8a7","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Trailing whitespace detected.","created_at":"2015-08-03T20:54:45Z","updated_at":"2015-08-03T20:54:45Z","html_url":"https://github.com/MarkUsProject/Markus/pull/2214#discussion_r36130396","pull_request_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2214","_links":{"self":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/comments/36130396"},"html":{"href":"https://github.com/MarkUsProject/Markus/pull/2214#discussion_r36130396"},"pull_request":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2214"}}},"pull_request":{"url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2214","id":41425737,"html_url":"https://github.com/MarkUsProject/Markus/pull/2214","diff_url":"https://github.com/MarkUsProject/Markus/pull/2214.diff","patch_url":"https://github.com/MarkUsProject/Markus/pull/2214.patch","issue_url":"https://api.github.com/repos/MarkUsProject/Markus/issues/2214","number":2214,"state":"open","locked":false,"title":"Implement summaries csv pat","user":{"login":"PatGuan","id":3442578,"avatar_url":"https://avatars.githubusercontent.com/u/3442578?v=3","gravatar_id":"","url":"https://api.github.com/users/PatGuan","html_url":"https://github.com/PatGuan","followers_url":"https://api.github.com/users/PatGuan/followers","following_url":"https://api.github.com/users/PatGuan/following{/other_user}","gists_url":"https://api.github.com/users/PatGuan/gists{/gist_id}","starred_url":"https://api.github.com/users/PatGuan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PatGuan/subscriptions","organizations_url":"https://api.github.com/users/PatGuan/orgs","repos_url":"https://api.github.com/users/PatGuan/repos","events_url":"https://api.github.com/users/PatGuan/events{/privacy}","received_events_url":"https://api.github.com/users/PatGuan/received_events","type":"User","site_admin":false},"body":"Changed the location of the download CSV report to the summaries (Danny).\r\nRefactored the function download_csv_report. Spreadsheet now displays the total marks in the course with respect to their criterion weights.","created_at":"2015-08-02T22:23:01Z","updated_at":"2015-08-03T20:54:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4028ad4f426a395d1b362bbc62da917b31a86f33","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2214/commits","review_comments_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2214/comments","review_comment_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/MarkUsProject/Markus/issues/2214/comments","statuses_url":"https://api.github.com/repos/MarkUsProject/Markus/statuses/b90f8cb0fe34d7813c09e564ae89f8f83420d8a7","head":{"label":"PatGuan:Implement-SummariesCSVPat","ref":"Implement-SummariesCSVPat","sha":"b90f8cb0fe34d7813c09e564ae89f8f83420d8a7","user":{"login":"PatGuan","id":3442578,"avatar_url":"https://avatars.githubusercontent.com/u/3442578?v=3","gravatar_id":"","url":"https://api.github.com/users/PatGuan","html_url":"https://github.com/PatGuan","followers_url":"https://api.github.com/users/PatGuan/followers","following_url":"https://api.github.com/users/PatGuan/following{/other_user}","gists_url":"https://api.github.com/users/PatGuan/gists{/gist_id}","starred_url":"https://api.github.com/users/PatGuan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PatGuan/subscriptions","organizations_url":"https://api.github.com/users/PatGuan/orgs","repos_url":"https://api.github.com/users/PatGuan/repos","events_url":"https://api.github.com/users/PatGuan/events{/privacy}","received_events_url":"https://api.github.com/users/PatGuan/received_events","type":"User","site_admin":false},"repo":{"id":39363056,"name":"Markus","full_name":"PatGuan/Markus","owner":{"login":"PatGuan","id":3442578,"avatar_url":"https://avatars.githubusercontent.com/u/3442578?v=3","gravatar_id":"","url":"https://api.github.com/users/PatGuan","html_url":"https://github.com/PatGuan","followers_url":"https://api.github.com/users/PatGuan/followers","following_url":"https://api.github.com/users/PatGuan/following{/other_user}","gists_url":"https://api.github.com/users/PatGuan/gists{/gist_id}","starred_url":"https://api.github.com/users/PatGuan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PatGuan/subscriptions","organizations_url":"https://api.github.com/users/PatGuan/orgs","repos_url":"https://api.github.com/users/PatGuan/repos","events_url":"https://api.github.com/users/PatGuan/events{/privacy}","received_events_url":"https://api.github.com/users/PatGuan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/PatGuan/Markus","description":"Git repository of MarkUs","fork":true,"url":"https://api.github.com/repos/PatGuan/Markus","forks_url":"https://api.github.com/repos/PatGuan/Markus/forks","keys_url":"https://api.github.com/repos/PatGuan/Markus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PatGuan/Markus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PatGuan/Markus/teams","hooks_url":"https://api.github.com/repos/PatGuan/Markus/hooks","issue_events_url":"https://api.github.com/repos/PatGuan/Markus/issues/events{/number}","events_url":"https://api.github.com/repos/PatGuan/Markus/events","assignees_url":"https://api.github.com/repos/PatGuan/Markus/assignees{/user}","branches_url":"https://api.github.com/repos/PatGuan/Markus/branches{/branch}","tags_url":"https://api.github.com/repos/PatGuan/Markus/tags","blobs_url":"https://api.github.com/repos/PatGuan/Markus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PatGuan/Markus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PatGuan/Markus/git/refs{/sha}","trees_url":"https://api.github.com/repos/PatGuan/Markus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PatGuan/Markus/statuses/{sha}","languages_url":"https://api.github.com/repos/PatGuan/Markus/languages","stargazers_url":"https://api.github.com/repos/PatGuan/Markus/stargazers","contributors_url":"https://api.github.com/repos/PatGuan/Markus/contributors","subscribers_url":"https://api.github.com/repos/PatGuan/Markus/subscribers","subscription_url":"https://api.github.com/repos/PatGuan/Markus/subscription","commits_url":"https://api.github.com/repos/PatGuan/Markus/commits{/sha}","git_commits_url":"https://api.github.com/repos/PatGuan/Markus/git/commits{/sha}","comments_url":"https://api.github.com/repos/PatGuan/Markus/comments{/number}","issue_comment_url":"https://api.github.com/repos/PatGuan/Markus/issues/comments{/number}","contents_url":"https://api.github.com/repos/PatGuan/Markus/contents/{+path}","compare_url":"https://api.github.com/repos/PatGuan/Markus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PatGuan/Markus/merges","archive_url":"https://api.github.com/repos/PatGuan/Markus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PatGuan/Markus/downloads","issues_url":"https://api.github.com/repos/PatGuan/Markus/issues{/number}","pulls_url":"https://api.github.com/repos/PatGuan/Markus/pulls{/number}","milestones_url":"https://api.github.com/repos/PatGuan/Markus/milestones{/number}","notifications_url":"https://api.github.com/repos/PatGuan/Markus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PatGuan/Markus/labels{/name}","releases_url":"https://api.github.com/repos/PatGuan/Markus/releases{/id}","created_at":"2015-07-20T04:24:33Z","updated_at":"2015-07-20T04:24:36Z","pushed_at":"2015-08-03T20:54:41Z","git_url":"git://github.com/PatGuan/Markus.git","ssh_url":"git@github.com:PatGuan/Markus.git","clone_url":"https://github.com/PatGuan/Markus.git","svn_url":"https://github.com/PatGuan/Markus","homepage":"http://www.markusproject.org","size":23027,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"MarkUsProject:master","ref":"master","sha":"8fde279a320006d8e431e4e02df76e6a20bdff02","user":{"login":"MarkUsProject","id":415874,"avatar_url":"https://avatars.githubusercontent.com/u/415874?v=3","gravatar_id":"","url":"https://api.github.com/users/MarkUsProject","html_url":"https://github.com/MarkUsProject","followers_url":"https://api.github.com/users/MarkUsProject/followers","following_url":"https://api.github.com/users/MarkUsProject/following{/other_user}","gists_url":"https://api.github.com/users/MarkUsProject/gists{/gist_id}","starred_url":"https://api.github.com/users/MarkUsProject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarkUsProject/subscriptions","organizations_url":"https://api.github.com/users/MarkUsProject/orgs","repos_url":"https://api.github.com/users/MarkUsProject/repos","events_url":"https://api.github.com/users/MarkUsProject/events{/privacy}","received_events_url":"https://api.github.com/users/MarkUsProject/received_events","type":"Organization","site_admin":false},"repo":{"id":940538,"name":"Markus","full_name":"MarkUsProject/Markus","owner":{"login":"MarkUsProject","id":415874,"avatar_url":"https://avatars.githubusercontent.com/u/415874?v=3","gravatar_id":"","url":"https://api.github.com/users/MarkUsProject","html_url":"https://github.com/MarkUsProject","followers_url":"https://api.github.com/users/MarkUsProject/followers","following_url":"https://api.github.com/users/MarkUsProject/following{/other_user}","gists_url":"https://api.github.com/users/MarkUsProject/gists{/gist_id}","starred_url":"https://api.github.com/users/MarkUsProject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarkUsProject/subscriptions","organizations_url":"https://api.github.com/users/MarkUsProject/orgs","repos_url":"https://api.github.com/users/MarkUsProject/repos","events_url":"https://api.github.com/users/MarkUsProject/events{/privacy}","received_events_url":"https://api.github.com/users/MarkUsProject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/MarkUsProject/Markus","description":"Git repository of MarkUs","fork":false,"url":"https://api.github.com/repos/MarkUsProject/Markus","forks_url":"https://api.github.com/repos/MarkUsProject/Markus/forks","keys_url":"https://api.github.com/repos/MarkUsProject/Markus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MarkUsProject/Markus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MarkUsProject/Markus/teams","hooks_url":"https://api.github.com/repos/MarkUsProject/Markus/hooks","issue_events_url":"https://api.github.com/repos/MarkUsProject/Markus/issues/events{/number}","events_url":"https://api.github.com/repos/MarkUsProject/Markus/events","assignees_url":"https://api.github.com/repos/MarkUsProject/Markus/assignees{/user}","branches_url":"https://api.github.com/repos/MarkUsProject/Markus/branches{/branch}","tags_url":"https://api.github.com/repos/MarkUsProject/Markus/tags","blobs_url":"https://api.github.com/repos/MarkUsProject/Markus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MarkUsProject/Markus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MarkUsProject/Markus/git/refs{/sha}","trees_url":"https://api.github.com/repos/MarkUsProject/Markus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MarkUsProject/Markus/statuses/{sha}","languages_url":"https://api.github.com/repos/MarkUsProject/Markus/languages","stargazers_url":"https://api.github.com/repos/MarkUsProject/Markus/stargazers","contributors_url":"https://api.github.com/repos/MarkUsProject/Markus/contributors","subscribers_url":"https://api.github.com/repos/MarkUsProject/Markus/subscribers","subscription_url":"https://api.github.com/repos/MarkUsProject/Markus/subscription","commits_url":"https://api.github.com/repos/MarkUsProject/Markus/commits{/sha}","git_commits_url":"https://api.github.com/repos/MarkUsProject/Markus/git/commits{/sha}","comments_url":"https://api.github.com/repos/MarkUsProject/Markus/comments{/number}","issue_comment_url":"https://api.github.com/repos/MarkUsProject/Markus/issues/comments{/number}","contents_url":"https://api.github.com/repos/MarkUsProject/Markus/contents/{+path}","compare_url":"https://api.github.com/repos/MarkUsProject/Markus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MarkUsProject/Markus/merges","archive_url":"https://api.github.com/repos/MarkUsProject/Markus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MarkUsProject/Markus/downloads","issues_url":"https://api.github.com/repos/MarkUsProject/Markus/issues{/number}","pulls_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls{/number}","milestones_url":"https://api.github.com/repos/MarkUsProject/Markus/milestones{/number}","notifications_url":"https://api.github.com/repos/MarkUsProject/Markus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MarkUsProject/Markus/labels{/name}","releases_url":"https://api.github.com/repos/MarkUsProject/Markus/releases{/id}","created_at":"2010-09-26T16:18:08Z","updated_at":"2015-05-11T07:04:07Z","pushed_at":"2015-08-03T20:54:41Z","git_url":"git://github.com/MarkUsProject/Markus.git","ssh_url":"git@github.com:MarkUsProject/Markus.git","clone_url":"https://github.com/MarkUsProject/Markus.git","svn_url":"https://github.com/MarkUsProject/Markus","homepage":"http://www.markusproject.org","size":48762,"stargazers_count":125,"watchers_count":125,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":155,"mirror_url":null,"open_issues_count":85,"forks":155,"open_issues":85,"watchers":125,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2214"},"html":{"href":"https://github.com/MarkUsProject/Markus/pull/2214"},"issue":{"href":"https://api.github.com/repos/MarkUsProject/Markus/issues/2214"},"comments":{"href":"https://api.github.com/repos/MarkUsProject/Markus/issues/2214/comments"},"review_comments":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2214/comments"},"review_comment":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2214/commits"},"statuses":{"href":"https://api.github.com/repos/MarkUsProject/Markus/statuses/b90f8cb0fe34d7813c09e564ae89f8f83420d8a7"}}}}