Gradescope Grader Stats

Displays per-grader statistics on submissions in Gradescope

目前为 2022-09-11 提交的版本,查看 最新版本

  1. /**
  2. * MIT License
  3. *
  4. * Copyright (c) 2021 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.1.1
  30. // @author drharris
  31. // @copyright 2022, 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. $(document).ready(function () {
  65. if (!$('#question_submissions_wrapper .dataTable >tbody >tr')) return;
  66. var dict = {};
  67. var uniqueScores = [];
  68. // parse grade data
  69. $('#question_submissions_wrapper .dataTable >tbody >tr').each(function (index, tr) {
  70. var grader = tr.childNodes[2].textContent;
  71. var score = tr.childNodes[4].textContent;
  72. if (!uniqueScores.includes(score)) { uniqueScores.push(score); }
  73. if (!(grader in dict)) { dict[grader] = []; }
  74. dict[grader].push(score);
  75. });
  76. uniqueScores.sort((a, b) => (parseInt(a) - parseInt(b)));
  77. // build new table
  78. var table = $('<table>').addClass('table').css("margin", "3em auto 0").css("width", "80%").appendTo($('#question_submissions_filter'));
  79. var tr = $('<tr>').appendTo($('<thead>').appendTo(table));
  80. tr.append($('<th>Grader</th><th>Count</th><th>Mean</th><th>Median</th><th>StDev</th>'));
  81. var tbody = $('<tbody>').addClass('collapse').attr('id', 'gsgsTbody').appendTo(table);
  82. for (var ta in dict) {
  83. if (ta == '') continue;
  84. var grades_nonzero = dict[ta].filter(function(x){return x !== '0.0';});
  85. // make data summary row
  86. var row = $('<tr>').addClass('gsgsRow').css("cursor", "pointer").css("height", "32px").appendTo(tbody);
  87. row.append($('<td>').text(ta))
  88. row.append($('<td>').text(dict[ta].length));
  89. row.append($('<td>').text(math.round(math.mean(grades_nonzero), 2)))
  90. row.append($('<td>').text(math.round(math.median(grades_nonzero), 2)))
  91. row.append($('<td>').text(math.round(math.std(grades_nonzero), 2)))
  92. // make chart row
  93. var detailRow = $('<tr>').addClass('gsgsRowDetail').appendTo(tbody);
  94. var detailCell = $('<td colspan=5></td>').appendTo(detailRow);
  95. var chartContainer = $('<div style="display:inline-block;position:relative;width:100%;height:200px;padding-left:2em;padding-right:2em"></div>').appendTo(detailCell);
  96. let scoreCount = dict[ta].reduce(function ( c, v ) { return ( c[v] ? ++c[v] : (c[v] = 1), c ); }, {});
  97. new Chart($('<canvas></canvas>').appendTo(chartContainer), {
  98. type: 'bar',
  99. data: { labels: uniqueScores, datasets: [ { label:ta, data: scoreCount, backgroundColor: 'rgba(92, 60, 146, 0.5)' } ] },
  100. options: { plugins: { legend: { display: false, } }, responsive: true, maintainAspectRatio:false }
  101. });
  102. detailRow.toggle();
  103. }
  104. // add chart collapse ability
  105. $('tr.gsgsRow').click(function () {
  106. $(this).nextUntil('tr.gsgsRow').slideToggle(100);
  107. });
  108. });