Gradescope Grader Stats

Displays per-grader statistics on submissions in Gradescope

  1. /**
  2. * MIT License
  3. *
  4. * Copyright (c) 2024 David Harris
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. */
  25. // ==UserScript==
  26. // @name Gradescope Grader Stats
  27. // @namespace https://greasyfork.org/en/users/238426-drharris
  28. // @description Displays per-grader statistics on submissions in Gradescope
  29. // @version 1.2.5
  30. // @author drharris
  31. // @copyright 2024, drharris (https://greasyfork.org/en/users/238426-drharris)
  32. // @license MIT
  33. // @homepage https://greasyfork.org/en/scripts/423266-sample-userscript-template
  34. // @supportURL https://greasyfork.org/en/scripts/423266-sample-userscript-template/feedback
  35. // @match https://www.gradescope.com/courses/*/questions/*/submissions
  36. // @require https://unpkg.com/mathjs@7.0.0/dist/math.min.js
  37. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
  38. // @require https://cdn.jsdelivr.net/npm/chart.js@3.9.1/dist/chart.min.js
  39. // @grant GM_getValue
  40. // @grant GM_setValue
  41. // @grant GM_deleteValue
  42. // @grant GM_listValues
  43. // @grant GM_addValueChangeListener
  44. // @grant GM_removeValueChangeListener
  45. // @grant GM_addStyle
  46. // @grant GM_registerMenuCommand
  47. // @grant GM_unregisterMenuCommand
  48. // @grant GM_setClipboard
  49. // @grant GM_xmlhttpRequest
  50. // @grant GM_getResourceText
  51. // @grant GM_getResourceURL
  52. // @grant GM_download
  53. // @grant GM_openInTab
  54. // @grant GM_notification
  55. // ==/UserScript==
  56.  
  57. // ==OpenUserScript==
  58. // @author drharris
  59. // @collaborator drharris
  60. // ==/OpenUserScript==
  61.  
  62. /* jshint esversion: 6 */
  63.  
  64.  
  65.  
  66. $(document).ready(function () {
  67. document.gsgsScrollToRow = function(line) {
  68. document.querySelectorAll('#question_submissions_wrapper .dataTable >tbody >tr')[line].scrollIntoView({ behavior: 'smooth', block: 'center'});
  69. return false;
  70. }
  71. var gradeTable = $('#question_submissions_wrapper .dataTable >tbody >tr');
  72. if (!gradeTable) return;
  73. var idxNum = 0;
  74. var idxGrader = $('#question_submissions_wrapper .dataTable >thead >tr th:contains("Last Graded By")').index();
  75. var idxScore = $('#question_submissions_wrapper .dataTable >thead >tr th:contains("Score")').index()
  76. var dict = {};
  77. var dict_range = {};
  78. var uniqueScores = [];
  79. // create TA row style
  80. $("<style type='text/css'>tr.curr_ta td{background-color:#d5f4e6;font-weight:bold;}</style>").appendTo("head");
  81. // parse grade data
  82. gradeTable.each(function (index, tr) {
  83. var grader = tr.childNodes[idxGrader].textContent;
  84. var score = tr.childNodes[idxScore].textContent;
  85. var num = parseInt(tr.childNodes[idxNum].textContent);
  86. if (score.trim() != "")
  87. {
  88. if (!uniqueScores.includes(score)) { uniqueScores.push(score); }
  89. if (!(grader in dict)) { dict[grader] = []; }
  90. if (!(grader in dict_range)) { dict_range[grader] = [num,num]; }
  91. dict[grader].push(score);
  92. if(dict_range[grader][0] > num) dict_range[grader][0] = num;
  93. if(dict_range[grader][1] < num) dict_range[grader][1] = num;
  94. }
  95. });
  96. uniqueScores.sort((a, b) => (parseInt(a) - parseInt(b)));
  97. // build new table
  98. var table = $('<table>').addClass('table').css("margin", "3em auto 0").css("width", "80%").appendTo($('#question_submissions_filter'));
  99. var tr = $('<tr>').appendTo($('<thead>').appendTo(table));
  100. tr.append($('<th>Grader</th><th></th><th>Progress</th><th>Count</th><th>Mean</th><th>Median</th><th>StDev</th><th></th>'));
  101. var tbody = $('<tbody>').addClass('collapse').attr('id', 'gsgsTbody').appendTo(table);
  102. for (var ta in dict) {
  103. if (ta == '') continue;
  104. var grades_nonzero = dict[ta].filter(function(x){return x !== '0.0';});
  105. if(grades_nonzero.length < 1) grades_nonzero = [0.0]; // fix the case where there is only one zero grade.
  106. // make data summary row
  107. var bold = "normal";
  108. var highlight = "";
  109. var row = $('<tr>').addClass('gsgsRow').css("cursor", "pointer").css("height", "32px").appendTo(tbody);
  110. if (ta == bugsnagClient.user['name']) {
  111. row = row.addClass('curr_ta');
  112. }
  113. row.append($('<td>').text(ta));
  114. row.append($('<td>').text(dict_range[ta][0] + " - " + dict_range[ta][1]));
  115. row.append($('<td>').text(dict[ta].length + "/" + (math.abs(dict_range[ta][0] - dict_range[ta][1]) + 1)));
  116. row.append($('<td>').text(dict[ta].length));
  117. row.append($('<td>').text(math.round(math.mean(grades_nonzero), 2)))
  118. row.append($('<td>').text(math.round(math.median(grades_nonzero), 2)))
  119. row.append($('<td>').text(math.round(math.std(grades_nonzero), 2)))
  120. row.append($('<td>').append($("<button type='button' class='btn btn-sm btn-primary' onclick='gsgsScrollToRow(" + dict_range[ta][0] + ");'>").text("↴")));
  121. // make chart row
  122. var detailRow = $('<tr>').addClass('gsgsRowDetail').appendTo(tbody);
  123. var detailCell = $('<td colspan=6></td>').appendTo(detailRow);
  124. var chartContainer = $('<div style="display:inline-block;position:relative;width:100%;height:200px;padding-left:2em;padding-right:2em"></div>').appendTo(detailCell);
  125. let scoreCount = dict[ta].reduce(function ( c, v ) { return ( c[v] ? ++c[v] : (c[v] = 1), c ); }, {});
  126. new Chart($('<canvas></canvas>').appendTo(chartContainer), {
  127. type: 'bar',
  128. data: { labels: uniqueScores, datasets: [ { label:ta, data: scoreCount, backgroundColor: 'rgba(92, 60, 146, 0.5)' } ] },
  129. options: { plugins: { legend: { display: false, } }, responsive: true, maintainAspectRatio:false }
  130. });
  131. detailRow.toggle();
  132. }
  133. // add chart collapse ability
  134. $('tr.gsgsRow').click(function () {
  135. $(this).nextUntil('tr.gsgsRow').slideToggle(100);
  136. });
  137. });