blob: d401eca377f254dde468ecead992c7b042dac168 [file] [log] [blame]
j7940eec2020-12-28 14:00:41 -06001/**
2 * @file d.tech-specific features, CBL & grade calculation
3 * @author jottocraft
4 *
j6e1a7bf2026-10-13 03:37:04 +00005 * @copyright Copyright (c) jottocraft 2020
j40db0272022-01-14 15:18:29 -08006 * @license MIT
j7940eec2020-12-28 14:00:41 -06007 *
8 * JSDoc documentation for these LMS functions can be found near the end of core.js
9 */
10
j7940eec2020-12-28 14:00:41 -060011//Load Canvas integration
j5e67d8e2022-11-08 22:55:04 -080012jQuery.getScript(window.dtpsBaseURL + "/scripts/lms/canvas.js?upstream=true", function () {
jdc6ea0e2022-04-26 16:03:27 -070013 //Get global dangerous CBL preference
14 const dangerousCBLEnabled = window.localStorage.getItem("pref-dangerousCBL") == "true";
15
16 //This array should be used for checking if CBL should be used
17 //dangerousCBL doesn't need to be checked since it is already checked before classes are added here
18 const consentedCBLCourses = [];
19
j7940eec2020-12-28 14:00:41 -060020 //Add d.tech-specific items to dtpsLMS
21 dtpsLMS.name = "d.tech";
22 dtpsLMS.legalName = "Canvas LMS, Design Tech High School, or Instructure Inc";
j69843082023-08-22 12:26:55 -070023 dtpsLMS.description = "Includes CBL features for Power+. No longer actively maintained.";
j7940eec2020-12-28 14:00:41 -060024 dtpsLMS.logo = "https://i.imgur.com/efGrLq3.png";
j2e1cd832023-02-05 22:03:31 -080025 dtpsLMS.source = "https://gitlab.com/jottocraft/dtps/-/blob/main/scripts/lms/dtech.js";
jdc6ea0e2022-04-26 16:03:27 -070026 dtpsLMS.useRubricGrades = consentedCBLCourses;
27 dtpsLMS.gradeCalculationAllowlist = consentedCBLCourses;
28 dtpsLMS.lmsGradebookAllowlist = consentedCBLCourses;
j7940eec2020-12-28 14:00:41 -060029 dtpsLMS.institutionSpecific = true;
jdc6ea0e2022-04-26 16:03:27 -070030 dtpsLMS.genericGradebook = true;
j7940eec2020-12-28 14:00:41 -060031 dtpsLMS.dtech = true;
32
j7940eec2020-12-28 14:00:41 -060033 //Update assignments
34 //This is for customizing rubric names and colors to match d.tech CBL
jdc6ea0e2022-04-26 16:03:27 -070035 dtpsLMS.updateAssignments = function (rawAssignments, course) {
j7940eec2020-12-28 14:00:41 -060036 return new Promise((resolve, reject) => {
37 var updatedAssignments = rawAssignments.map(assignment => {
jdc6ea0e2022-04-26 16:03:27 -070038 //Skip if CBL is not enabled for this course
39 if (!consentedCBLCourses.includes(course.id)) return assignment;
40
j7940eec2020-12-28 14:00:41 -060041 //Check if assignment has rubric
42 if (assignment.rubric) {
43 //Update assignment rubric
44 assignment.rubric.forEach(rubricItem => {
j7940eec2020-12-28 14:00:41 -060045 if (rubricItem.score !== undefined) {
46 rubricItem.color = dtechRubricColor(rubricItem.score);
47 }
48 });
49 }
50
51 //Return updated assignment to the Array.map function
52 return assignment;
53 });
54
55 resolve(updatedAssignments);
56 })
57 }
58
59 //Update classes
60 dtpsLMS.updateClasses = function (classes) {
61 return new Promise((resolve, reject) => {
62 var tmpNewArray = [];
63 classes.forEach((course, i) => {
j324e5f12021-01-26 13:43:49 -080064 //Add course to list
65 tmpNewArray.push(course);
jdc6ea0e2022-04-26 16:03:27 -070066
67 //Add course to CBL-enabled list
68 if (dangerousCBLEnabled && (fluid.get("pref-enabledCBLFor" + course.id) == "true")) {
69 consentedCBLCourses.push(course.id);
70 }
j7940eec2020-12-28 14:00:41 -060071 });
72 classes = tmpNewArray;
73
j7940eec2020-12-28 14:00:41 -060074 resolve(classes);
75 });
76 }
77
j7940eec2020-12-28 14:00:41 -060078 //Run d.tech grade calculation algorithm (defined below)
79 dtpsLMS.calculateGrade = function (course, assignments) {
jdc6ea0e2022-04-26 16:03:27 -070080 //If the user has not consented to dangerous CBL for this course, don't calculate
81 if (!consentedCBLCourses.includes(course.id)) return;
j7940eec2020-12-28 14:00:41 -060082
jdc6ea0e2022-04-26 16:03:27 -070083 //The unique identifier for the CBL formula
84 const formula = "2020-DASH-LT";
j2566c4e2021-10-01 15:25:49 -070085
j7940eec2020-12-28 14:00:41 -060086 //Run d.tech grade calculation
87 var dtechResults = dtechGradeCalc.run(assignments, formula);
88
89 if (dtechResults) {
90 //Class has a grade
91 return {
j2566c4e2021-10-01 15:25:49 -070092 letter: assignments.find(a => a.error) ? "ERROR" : dtechResults.results.letter,
j7940eec2020-12-28 14:00:41 -060093 dtech: dtechResults //Return dtech results for gradebook
94 };
95 } else {
96 //No grade for this class
97 return;
98 }
99 }
100
101 //Local functions & variables, not part of the dtpsLMS specification ----------------------------------------------
102
j7940eec2020-12-28 14:00:41 -0600103 //Get score color from rubric percentage
104 var dtechRubricColor = function (score) {
105 if (score > 4.0) return "#20D684";
106 if (score == 4.0) return "#41BA35";
107 if (score >= 3.9) return "#50BC39";
108 if (score >= 3.8) return "#5FBD3D";
109 if (score >= 3.7) return "#6EBF40";
110 if (score >= 3.6) return "#7DC044";
111 if (score >= 3.5) return "#8CC248";
112 if (score >= 3.4) return "#9AC44C";
113 if (score >= 3.3) return "#A9C550";
114 if (score >= 3.2) return "#B8C753";
115 if (score >= 3.1) return "#C7C857";
116 if (score >= 3.0) return "#D6CA5B";
117 if (score >= 2.9) return "#D8C35A";
118 if (score >= 2.8) return "#DABB59";
119 if (score >= 2.7) return "#DCB458";
120 if (score >= 2.6) return "#DEAC57";
121 if (score >= 2.5) return "#E1A556";
122 if (score >= 2.4) return "#E39E55";
123 if (score >= 2.3) return "#E59654";
124 if (score >= 2.2) return "#E78F53";
125 if (score >= 2.1) return "#E98752";
126 if (score >= 2.0) return "#EB8051";
127 if (score >= 1.9) return "#E97A50";
128 if (score >= 1.8) return "#E7744F";
129 if (score >= 1.7) return "#E56F4E";
130 if (score >= 1.6) return "#E3694D";
131 if (score >= 1.5) return "#E1634C";
132 if (score >= 1.4) return "#DE5D4A";
133 if (score >= 1.3) return "#DC5749";
134 if (score >= 1.2) return "#DA5248";
135 if (score >= 1.1) return "#D84C47";
136 if (score >= 1.0) return "#D64646";
137 if (score >= 0.0) return "#D72727";
138 if (score < 0.0) return "#BF0000";
139 }
140
141 /**
142 * d.tech CBL grade calculation algorithm
143 *
144 * @property {string[]} letters An array of letters that can be returned from highest -> lowest
145 * @property {object} params Parameters for each type of grade calculation, such as requirements for each criteria
146 */
147 var dtechGradeCalc = {
148 letters: ["A", "A-", "B+", "B", "B-", "C", "I"],
149 params: {
150 /**
j9e29aeb2021-08-21 19:49:12 -0700151 * @description 2020-DASH-LT (from Long-Term CBL Grade Dashboard) grade calculation parameters
j7940eec2020-12-28 14:00:41 -0600152 * @property {{string, number}} percentage Percentage criteria parameters. The key of each item in the object is the letter and the value is the percentage needed to meet the criteria
153 * @property {{string, number}} lowest Lowest average criteria perameters. The key of each item in the object is the letter and the value is the lowest average needed to meet the criteria
154 */
j9e29aeb2021-08-21 19:49:12 -0700155 "2020-DASH-LT": {
j7940eec2020-12-28 14:00:41 -0600156 percentage: {
157 "A": 3.3,
158 "A-": 3.3,
159 "B+": 2.6,
160 "B": 2.6,
161 "B-": 2.6,
162 "C": 2.2,
163 "I": 0
164 },
165 lowest: {
166 "A": 3,
167 "A-": 2.5,
168 "B+": 2.2,
169 "B": 1.8,
170 "B-": 1.5,
171 "C": 1.5,
172 "I": 0
173 }
174 }
175 },
176 /**
177 * A simple average function
178 *
179 * @param {number[]} array Array of numbers to average
180 * @return {number} Average of the numbers in the array
181 */
182 average: function (array) {
183 var sum = 0;
184 array.forEach(item => sum += item);
185 return sum / array.length;
186 },
187 /**
188 * Runs grade calculation. Takes assignments, gets outcome averages, then calls getLetter to get the final letter.
189 * This function returns undefined if there is no grade.
190 *
191 * @param {Assignment[]} assignments Array of assignments to use for grade calculation
j9e29aeb2021-08-21 19:49:12 -0700192 * @param {string} formula Formula to use for grade calculation. Can be one of the following: 2020-DASH-LT
j7940eec2020-12-28 14:00:41 -0600193 * @param {object} outcomesOverride An outcome object to use instead of using assignments. Used for what-if grades.
194 * @return {object} Grade calculation results
195 */
196 run: function (assignments, formula, outcomesOverride) {
j7940eec2020-12-28 14:00:41 -0600197 //Array of grade variations
198 var gradeVariations = [];
199
200 //Outcomes object
201 //This doesn't have to be used by the grade calculation formula. Can be overridden for What-If grades.
202 var outcomes = outcomesOverride || {};
203
j9e29aeb2021-08-21 19:49:12 -0700204 if (formula == "2020-DASH-LT") {
205 //2020-DASH-LT SEMESTER 1 OUTCOME AVERAGE FORMULA (2020-DASH-LT)
j7940eec2020-12-28 14:00:41 -0600206
j9e29aeb2021-08-21 19:49:12 -0700207 // ------- [2020-DASH-LT] Step 1: Get rubric assessments by outcome -------
j7940eec2020-12-28 14:00:41 -0600208
209 if (!outcomesOverride) {
210 assignments.forEach(assignment => {
211 if (assignment.rubric) {
212 //Assignment has a rubric
213
214 assignment.rubric.forEach(rubricItem => {
j4d933ce2022-04-08 21:49:55 +0000215 if (rubricItem.outcome) {
j7940eec2020-12-28 14:00:41 -0600216 //Rubric item is assessed and is linked with an outcome
217
218 if (!outcomes[rubricItem.outcome]) {
219 //Outcome object doesn't exist yet
220 outcomes[rubricItem.outcome] = {
221 scores: []
222 };
223 }
224
225 //Add RubricItem to outcome array
226 outcomes[rubricItem.outcome].scores.push(rubricItem);
227
228 //Save outcome name as rubric title
229 if (rubricItem.title) outcomes[rubricItem.outcome].title = rubricItem.title;
230 }
231 });
232 }
233 });
234 }
235
j9e29aeb2021-08-21 19:49:12 -0700236 // ------- [2020-DASH-LT] Step 2: Calculate outcome averages -------
j7940eec2020-12-28 14:00:41 -0600237
238 //If there are no outcomes, this class doesn't have a grade
239 if (Object.keys(outcomes).length == 0) return;
240
241 //Loop over the values of each item in the outcomes object
242 Object.values(outcomes).forEach(outcome => {
243 //Get array of scores for the outcome, remove null scores
j4d933ce2022-04-08 21:49:55 +0000244 var outcomeNumberScores = outcome.scores.map(RubricItem => RubricItem.score).filter(score => (score !== null) && (score !== undefined));
245
246 if (outcomeNumberScores.length === 0) {
247 outcome.scoreType = "ungraded";
248 outcome.average = null;
249 return;
250 };
j7940eec2020-12-28 14:00:41 -0600251
252 //Calculate outcome average with all outcome scores
j4d933ce2022-04-08 21:49:55 +0000253 var average = this.average(outcomeNumberScores);
j7940eec2020-12-28 14:00:41 -0600254
255 //Get the lowest score
j4d933ce2022-04-08 21:49:55 +0000256 var lowestScore = Math.min(...outcomeNumberScores);
j7940eec2020-12-28 14:00:41 -0600257
258 //Drop the lowest score to see what happens
j4d933ce2022-04-08 21:49:55 +0000259 var droppedArray = outcomeNumberScores.slice(); //copy of outcomeScores array
j7940eec2020-12-28 14:00:41 -0600260 droppedArray.splice(droppedArray.indexOf(lowestScore), 1); //remove lowest score from array
261
262 var droppedAverage = this.average(droppedArray); //calculate average from droppedArray
263
264 //Choose the higher score
265 if (droppedAverage > average) {
266 //The dropped score was higher
267 outcome.scoreType = "dropped";
268 outcome.droppedScore = outcome.scores.map(RubricItem => RubricItem.score).indexOf(lowestScore);
269 outcome.average = droppedAverage;
270 } else {
271 //Calculating with all outcome scores was the same or higher
272 outcome.scoreType = "all";
273 outcome.average = average;
274 delete outcome.droppedScore;
275 }
276 });
277
278
j9e29aeb2021-08-21 19:49:12 -0700279 // ------- [2020-DASH-LT] Step 3: Calculate letter grade variations -------
j7940eec2020-12-28 14:00:41 -0600280
281 //All outcomes variation
j4d933ce2022-04-08 21:49:55 +0000282 var outcomeAvgs = Object.values(outcomes).map(outcome => outcome.average).filter(avg => avg !== null);
j7940eec2020-12-28 14:00:41 -0600283 gradeVariations.push(this.getLetter(outcomeAvgs, formula, "all"));
284
285 }
286
287 //Get the highest grade variation from the results
288 var bestVariation = null;
289 gradeVariations.forEach(variation => {
290 if (!bestVariation || (this.letters.indexOf(variation.letter) < this.letters.indexOf(bestVariation.letter))) {
291 //variation.letter is a higher letter than bestVariation.letter, or there is no best variation yet
292 bestVariation = variation;
293 }
294 });
295
296 //Return grade calculation results
297 return {
298 results: bestVariation, //Results for the best variation
299 formula: formula, //Formula used to calculate this grade
300 outcomes: outcomes //Calculated outcome scores
301 };
302 },
303 /**
304 * Calculates a letter grade from an array of outcome averages. Called by gradeCalc.run.
305 * Gets the best possible letter from each criteria, then the lowest letter from that array.
306 *
307 * @param {number[]} outcomeAvgs Array of outcome averages to use for letter grade calculation
308 * @param {string} formula Formula to use for grade calculation. See gradeCalc.run.
309 * @param {string} [variation] Name of the letter grade variation (e.g. withSS, withoutSS, etc.). Only used for formulas with multiple variations.
310 * @return {object} Letter grade calculation results
311 */
312 getLetter: function (outcomeAvgs, formula, variation) {
313 //Grade calculation results object
314 //This includes any properties that need to be passed to the gradebook. The properties set depend on the formula.
315 var parameters = {};
316
317 //Sort outcome averages highest -> lowest
318 outcomeAvgs.sort((a, b) => b - a);
319
j9e29aeb2021-08-21 19:49:12 -0700320 if (formula == "2020-DASH-LT") {
321 //2020-DASH-LT SEMESTER 1 LETTER GRADE FORMULA (2020-DASH-LT)
j7940eec2020-12-28 14:00:41 -0600322
323 //Array of letters from each criteria
324 var letters = [];
325
j9e29aeb2021-08-21 19:49:12 -0700326 // ------- [2020-DASH-LT] Step 1: Get highest letter for Criteria 1 (percentage of outcomes criteria) -------
j7940eec2020-12-28 14:00:41 -0600327 var percentage = .75;
328 var numOutcomesRequired = Math.floor(outcomeAvgs.length * percentage); //Minimum number of outcomes required
329
330 //Calculate the value 75% of outcomes >= to (number75) and the number of outcomes needed to meet criteria 1
331 if (outcomeAvgs.length == 1) {
332 parameters.number75 = outcomeAvgs[0]; //if there is only 1 outcome, that outcome is number75
333 } else {
334 parameters.number75 = outcomeAvgs[numOutcomesRequired - 1]; //number75 = the outcome 75% through the array (since its sorted)
335 }
336 parameters.number75thresh = numOutcomesRequired; //number75thresh = number of outcomes needed to meet the criteria
337
338 //Get the best letter
339 var bestLetter = null;
340
341 //Test each letter and add the highest to the letters array
342 for (var i = 0; i < this.letters.length; i++) {
343 let letter = this.letters[i];
344
345 if (parameters.number75 >= this.params[formula].percentage[letter]) {
346 //Able to get this letter
347 bestLetter = letter;
348
349 //Stop checking for matches since all letters after this are lower
350 break;
351 }
352 }
353
354 //Add highest criteria 1 letter to the letters array
355 letters.push(bestLetter);
356
j9e29aeb2021-08-21 19:49:12 -0700357 // ------- [2020-DASH-LT] Step 2: Get highest letter for Criteria 2 (lowest outcome criteria) -------
j7940eec2020-12-28 14:00:41 -0600358
359 //Reset best letter
360 var bestLetter = null;
361
362 //Since the array is highest -> lowest, the lowest score is the last item in the array
363 parameters.lowestScore = outcomeAvgs[outcomeAvgs.length - 1];
364
365 //Test each letter and add the highest to the letters array
366 for (var i = 0; i < this.letters.length; i++) {
367 let letter = this.letters[i];
368
369 if (parameters.lowestScore >= this.params[formula].lowest[letter]) {
370 //Able to get this letter
371 bestLetter = letter;
372
373 //Stop checking for matches since all letters after this are lower
374 break;
375 }
376 }
377
378 //Add highest criteria 2 letter to the letters array
379 letters.push(bestLetter);
380 }
381
382 //Get the final letter, the lowest letter from the array
383 var letterIndexes = letters.map(letter => this.letters.indexOf(letter)); //Array of letter indexes in this.letters
384 var lowestLetterIndex = Math.max(...letterIndexes); //Lowest letter = highest index in this.letters
385 var letter = this.letters[lowestLetterIndex]; //Get final letter
386
387 return {
388 letter: letter,
389 parameters: parameters,
390 variation: variation
391 };
392 }
393 };
394
jd4e75d02023-08-22 12:45:59 -0700395 function cssClassForLetterGrade(letter) {
396 return "letter-" + letter.replace("-", "-minus").replace("+", "-plus");
397 }
398
j7940eec2020-12-28 14:00:41 -0600399 dtpsLMS.gradebook = function (course) {
j4d933ce2022-04-08 21:49:55 +0000400 //Add hide ungraded body class if enabled and preference listener
401 if (!dtpsLMS.ungradedListenerAdded) {
402 dtpsLMS.ungradedListenerAdded = true;
403 if (!fluid.get("pref-cblUngradedVisibility")) fluid.set("pref-cblUngradedVisibility", "hide");
404 const ramp = ["hide", "submitted", "upcoming", "all"];
405 function updateUngradedClasses(s) {
406 const p = ramp.indexOf(s);
407 jQuery('body').removeClass('ugShow');
408 jQuery('body').removeClass('ugFilterSubmitted');
409 jQuery('body').removeClass('ugFilterUpcoming');
410
411 if (s == "hide") return;
412 if (p >= 1) jQuery('body').addClass('ugShow');
413 if (p == 3) return;
414
415 if (p >= 1) jQuery('body').addClass('ugFilterSubmitted');
416 if (p == 2) jQuery('body').addClass('ugFilterUpcoming');
417 }
418 document.addEventListener("pref-cblUngradedVisibility", function (e) {
419 updateUngradedClasses(e.detail);
420 });
421 updateUngradedClasses(fluid.get("pref-cblUngradedVisibility"));
422 }
423
j7940eec2020-12-28 14:00:41 -0600424 return new Promise((resolve, reject) => {
425 if (course.gradeCalculation && course.gradeCalculation.dtech) {
426 //RENDERER: RENDER GRADE CALCULATION SUMMARY ------------------------------------
j9e29aeb2021-08-21 19:49:12 -0700427 if (course.gradeCalculation.dtech.formula == "2020-DASH-LT") {
j2566c4e2021-10-01 15:25:49 -0700428 var erroredAssignments = course.assignments.filter(a => a.error);
j7940eec2020-12-28 14:00:41 -0600429 var gradeCalcSummary = /*html*/`
j2566c4e2021-10-01 15:25:49 -0700430 <div id="gradeSummary" style="--size: 250px; margin: 0px 20px; --classColor: ${course.color};" class="grid flex">
431 ${erroredAssignments.length ? /*html*/`
432 <div style="color: #f2392c;" class="block status letterGrade card">
433 <h2 class="main">${course.gradeCalculation.dtech.results.letter}</h2>
434 <h5 class="bottom"><i class="fluid-icon">error</i> Data incomplete</h5>
435 </div>
436 ` : /*html*/`
437 <div style="background-color: var(--classColor); color: white;" class="block status letterGrade card">
438 <h2 class="main">${course.letter}</h2>
439 ${course.previousLetter ? `<h5 class="previousGrade">Previous grade: ${course.previousLetter}</h5>` : ""}
440 <h5 class="bottom"><i class="fluid-icon">grade</i> Grade</h5>
441 </div>
442 `}
443 <div class="block status number75">
444 <h2 class="main numFont">${course.gradeCalculation.dtech.results.parameters.number75.toFixed(2)}</h2>
445 <h5 class="bottom"><i class="fluid-icon">functions</i> 75% of outcomes (rounded down, ${course.gradeCalculation.dtech.results.parameters.number75thresh}) ≥</h5>
446 </div>
447 <div class="block status lowestScore">
448 <h2 class="main numFont">${course.gradeCalculation.dtech.results.parameters.lowestScore.toFixed(2)}</h2>
449 <h5 class="bottom"><i class="fluid-icon">leaderboard</i> Lowest outcome</h5>
450 </div>
j7940eec2020-12-28 14:00:41 -0600451 </div>
452
j2566c4e2021-10-01 15:25:49 -0700453 <div style="--classColor: ${course.color};${dtps.gradebookExpanded ? "" : "display: none;"}" id="classGradeMore">
454 <br />
455 <table class="table">
456 <thead>
457 <tr>
458 <th>&nbsp;&nbsp;Final Letter</th>
459 <th>75% (rounded down) of outcomes are ≥</th>
460 <th>No outcomes below</th>
461 </tr>
462 </thead>
463
464 <tbody>
465 ${dtechGradeCalc.letters.map(letter => {
466 return /*html*/`
jd4e75d02023-08-22 12:45:59 -0700467 <tr class="${cssClassForLetterGrade(letter)} ${course.letter == letter ? `active` : ``}">
j2566c4e2021-10-01 15:25:49 -0700468 <td>&nbsp;&nbsp;${letter}</td>
469 <td>${dtechGradeCalc.params[course.gradeCalculation.dtech.formula].percentage[letter]}</td>
470 <td>${dtechGradeCalc.params[course.gradeCalculation.dtech.formula].lowest[letter]}</td>
471 </tr>
472 `
473 }).join("")}
474 </tbody>
475 </table>
476 </div>
477
478 <div onclick="$('#classGradeMore').toggle(); if ($('#classGradeMore').is(':visible')) {$(this).children('i').text('keyboard_arrow_up'); $(this).children('span').text('Show less'); dtps.gradebookExpanded = true;} else {$(this).children('i').text('keyboard_arrow_down'); $(this).children('span').text('Show more'); dtps.gradebookExpanded = false;}" class="gradeSummaryShowHide">
479 ${dtps.gradebookExpanded ? `<i class="fluid-icon">keyboard_arrow_up</i> <span>Show less</span>` : `<i class="fluid-icon">keyboard_arrow_down</i> <span>Show more</span>`}
480 </div>
481
j4d933ce2022-04-08 21:49:55 +0000482 <br /><br /><br />
483
484 <div style="margin: 0px 20px; display: flex; flex-direction: row; align-items: center;">
485 <p style="margin-right: 10px;"><i style="font-size: 26px;" class="fluid-icon">filter_alt</i></p>
486 <div>
487 <div style="margin: 0px;" class="btns row small pref-cblUngradedVisibility">
488 <button onclick="fluid.set('pref-cblUngradedVisibility', 'hide')" class="btn hide">Graded only</button>
489 <button onclick="fluid.set('pref-cblUngradedVisibility', 'submitted')" class="btn submitted">Graded & submitted</button>
490 <button onclick="fluid.set('pref-cblUngradedVisibility', 'upcoming')" class="btn upcoming">Graded, submitted & upcoming</button>
491 <button onclick="fluid.set('pref-cblUngradedVisibility', 'all')" class="btn all">All</button>
492 </div>
493 </div>
494 </div>
495
j2566c4e2021-10-01 15:25:49 -0700496 ${erroredAssignments.length ? /*html*/`
497 <div style="margin: 20px;">
498 <h5>Incomplete Data</h5>
499 <p>
500 Power+ encountered an error when fetching data for the following ${erroredAssignments.length} assignment(s): ${erroredAssignments.map(a => `<a style="cursor: pointer;" onclick="${`dtps.assignment('` + a.id + `', ` + a.class + `)`}">${a.title}</a>`).join(", ")}.
501 Since this appears to be an issue with Canvas that is also affecting the d.tech CBL grade dashboard, Power+ is still calculating your grade for this class with the errored data omitted.
502 If you have any questions or information regarding this issue, please email me at <a href="mailto:[email protected]">hello@jottocraft.com</a>.
503 </p>
504 </div>
505 ` : ``}
506 `;
j7940eec2020-12-28 14:00:41 -0600507 } else {
508 var gradeCalcSummary = ""; //no grade calculation for this class
509 }
510
511 //RENDERER: RENDER EACH OUTCOME ------------------------------------
512 var outcomeHTML = []; //array of outcome html to be rendered
513 var dividerAdded = false; //used for determining if the unassessed outcome divided has been added
514 Object.keys(course.gradeCalculation.dtech.outcomes).sort(function (a, b) {
515 var keyA = course.gradeCalculation.dtech.outcomes[a].average,//sort by score lowest -> highest
516 keyB = course.gradeCalculation.dtech.outcomes[b].average;
517 if (keyA == undefined) { keyA = 999999 - course.gradeCalculation.dtech.outcomes[a].scores.length; } //put outcomes with no assessments at the bottom
518 if (keyB == undefined) { keyB = 999999 - course.gradeCalculation.dtech.outcomes[b].scores.length; }
519 // Compare the 2 scores
520 if (keyA > keyB) return 1;
521 if (keyA < keyB) return -1;
522 return 0;
523 }).forEach((outcomeID) => {
524 var outcome = course.gradeCalculation.dtech.outcomes[outcomeID];
525
526 var divider = !dividerAdded && !outcome.scores.length; //render divider
527 if (divider) dividerAdded = true; //remember that divider is already rendered
528
529 outcomeHTML.push(/*html*/`
530 ${divider ? `<h5 style="font-weight: bold;margin: 75px 75px 10px 75px;">Unassesed outcomes</h5>` : ""}
531
532 <div style="border-radius: 20px;padding: 22px; padding-bottom: 20px;" class="card outcomeResults outcome-${outcomeID}">
j4d933ce2022-04-08 21:49:55 +0000533 <h5 style="max-width: calc(100% - 50px); font-size: 24px; margin: 0px; margin-bottom: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">${outcome.title}</h5>
j7940eec2020-12-28 14:00:41 -0600534
j4d933ce2022-04-08 21:49:55 +0000535 <div id="outcomeScore${outcomeID}" class="numFont" style="position: absolute; top: 20px; right: 20px; font-size: 26px; font-weight: bold; display: inline-block; color: ${dtechRubricColor(outcome.average)}">${outcome.average === null ? "" : outcome.average.toFixed(2)}</div>
j7940eec2020-12-28 14:00:41 -0600536
537 <div class="assessments">
538 ${outcome.scores.length == 0 ? `
539 <p style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 6px 0px; color: var(--secText);">This outcome has not been assessed yet</p>
540 ` :
541 outcome.scores.map((assessment, aIndex) => {
542 return /*html*/`
j4d933ce2022-04-08 21:49:55 +0000543 <div class="assessmentWrapper ${assessment.score === null || assessment.score === undefined ? "ungraded" : ""} ${new Date(assessment.assignmentDue) > new Date() ? "ugUpcoming" : ""} ${assessment.assignmentSubmitted ? "ugSubmitted" : ""} ${aIndex == outcome.droppedScore ? "dropped" : ""}" id="outcome${assessment.outcome}assessment${aIndex}" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 6px 0px;">
544 <div style="color: ${assessment.color};" aIndex="${aIndex}" outcomeID="${outcomeID}" class="editableScore" ${dtps.remoteConfig.allowWhatIfGrades ? `contenteditable` : ""}>${assessment.score ?? ""}</div>
j7940eec2020-12-28 14:00:41 -0600545 <span class="assessmentTitle" style="cursor: pointer;" onclick="dtps.assignment('${assessment.assignmentID}', ${course.num});">${assessment.assignmentTitle}</span>
546 </div>
547 `;
548 }).join("")
549 }
550 </div>
551
552 ${dtps.remoteConfig.allowWhatIfGrades ? /*html*/`
553 <p class="addWhatIf" outcomeID="${outcomeID}" style="font-size: 14px; color: var(--secText); margin: 0px; margin-top: 16px; cursor: pointer;">
554 <i style="cursor: pointer; vertical-align: middle; font-size: 16px;" class="fluid-icon down">add_box</i>
555 Add a What-If grade
556 </p>
557 ` : ""}
558 </div>
559 `);
560 })
561
j7940eec2020-12-28 14:00:41 -0600562 //RESOLVE WITH HTML
jb39e6d92021-01-30 20:34:04 -0800563 resolve(gradeCalcSummary + `<br />` + outcomeHTML.join(""));
j7940eec2020-12-28 14:00:41 -0600564 } else {
565 resolve();
566 }
567 });
568 }
569
570 //Enable What-If grades
571 var scrollListenerAdded = false;
572 dtpsLMS.gradebookDidRender = function (course) {
j4d933ce2022-04-08 21:49:55 +0000573 fluid.init();
574
j7940eec2020-12-28 14:00:41 -0600575 //Add event listeners for every editable score in the gradebook
576 $(".card.outcomeResults .assessments .editableScore").toArray().forEach(ele => {
577 listenForWhatIf(ele, course);
578 });
579
580 //Add event listeners for the "Add a What-If grade" buttons
581 $("p.addWhatIf").click(function () {
582 addWhatIf(course, $(this).attr("outcomeID"));
583 });
584
585 //Keep the grade summary on top
586 if (!scrollListenerAdded) {
587 scrollListenerAdded = true;
588 var gradeSummary = document.getElementById("gradeSummary");
589 var sticky = gradeSummary.offsetTop - parseFloat($("body").css("padding-top")) - 10;
590 window.onscroll = function () {
591 if ((window.pageYOffset >= sticky) && ((dtps.classes[dtps.selectedClass]) && (dtps.selectedContent == "grades"))) {
592 $(".classContent").addClass("fixedGradeSummary");
593 } else {
594 $(".classContent").removeClass("fixedGradeSummary");
595 }
596 };
597 }
598 }
599
600 //Adds a What-If grade listener to the provided element
601 var listenForWhatIf = function (ele, course) {
602 ele.addEventListener("input", function () {
603 //Prepare what-if grades if it's not already prepared
604 initWhatIf(course);
605
606 //Get new outcome score
607 var typedScore = Number($(ele).text());
608
609 //Check if score is valid
610 if ($(ele).text() && ($(ele).text().length < 4) && !isNaN(typedScore) && (typedScore >= 0) && (typedScore <= 4)) {
611 //Valid outcome score, update color to match
612 $(ele).css("color", dtechRubricColor(typedScore));
613
614 //Check if score is modified
615 var isWhatIf = course.gradeCalculation.dtech.whatIfOutcomes[Number($(ele).attr("outcomeID"))].scores[Number($(ele).attr("aIndex"))].whatIfGrade;
616 if (isWhatIf || (typedScore !== course.gradeCalculation.dtech.outcomes[Number($(ele).attr("outcomeID"))].scores[Number($(ele).attr("aIndex"))].score)) {
617 $(ele).addClass("modified");
618 } else {
619 $(ele).removeClass("modified");
620 }
621
622 //Update score in the what-if outcomes
623 course.gradeCalculation.dtech.whatIfOutcomes[Number($(ele).attr("outcomeID"))].scores[Number($(ele).attr("aIndex"))].score = typedScore;
624
625 //Calculate what-if grade
626 calcWhatIf(course);
627 } else {
628 //Invalid outcome score, gray out and calculate without this score
629 $(ele).css("color", "var(--secText)");
630 $(ele).addClass("modified");
631
632 //Update score in the what-if outcomes
633 course.gradeCalculation.dtech.whatIfOutcomes[Number($(ele).attr("outcomeID"))].scores[Number($(ele).attr("aIndex"))].score = null;
634
635 //Calculate what-if grade
636 calcWhatIf(course);
637 }
638
639 }, false);
640
641 ele.addEventListener("focus", function () {
642 $(ele).addClass("focused");
643 }, false);
644
645 ele.addEventListener("blur", function () {
646 if ($(ele).hasClass("whatIf") && ($(ele).text() == "")) {
647 $(ele).parent().remove();
648 course.gradeCalculation.dtech.whatIfOutcomes[Number($(ele).attr("outcomeID"))].scores[Number($(ele).attr("aIndex"))].score = null;
649 } else {
650 $(ele).removeClass("focused");
651 }
652 }, false);
653
654 ele.addEventListener("keydown", function (e) {
655 function placeCaretAtEnd(el) {
656 el.focus();
657 if (typeof window.getSelection != "undefined"
658 && typeof document.createRange != "undefined") {
659 var range = document.createRange();
660 range.selectNodeContents(el);
661 range.collapse(false);
662 var sel = window.getSelection();
663 sel.removeAllRanges();
664 sel.addRange(range);
665 } else if (typeof document.body.createTextRange != "undefined") {
666 var textRange = document.body.createTextRange();
667 textRange.moveToElementText(el);
668 textRange.collapse(false);
669 textRange.select();
670 }
671 }
672
673 if (e.key == "ArrowDown") {
674 e.preventDefault();
675 var scores = $(".editableScore").toArray();
676 if (scores[scores.indexOf(ele) + 1]) {
677 placeCaretAtEnd(scores[scores.indexOf(ele) + 1]);
678 }
679 } else if (e.key == "ArrowUp") {
680 e.preventDefault();
681 var scores = $(".editableScore").toArray();
682 if (scores[scores.indexOf(ele) - 1]) {
683 placeCaretAtEnd(scores[scores.indexOf(ele) - 1]);
684 }
685 }
686 }, false);
687 }
688
689 //Copies outcomes for modification, shows what-if UI
690 var initWhatIf = function (course) {
691 if (!$("#gradeSummary").hasClass("whatIf")) {
692 //Initialize what-if grades
693
694 //Copy outcomes for modification
695 course.gradeCalculation.dtech.whatIfOutcomes = JSON.parse(JSON.stringify(course.gradeCalculation.dtech.outcomes));
696
697 //Show what-if mode for grade summary
698 $("#gradeSummary .block.card").css("background-color", "");
699 $("#gradeSummary .block.card").css("color", "var(--classColor)");
700 $("#gradeSummary .block.card h5.bottom").html(`<i class="fluid-icon">analytics</i> What-If Grade`);
701 $("#gradeSummary .block.card .previousGrade").remove();
702 $("#gradeSummary .block.card h2.main").after(`<h5 onclick="fluid.screen();" class="showActualGrades">Show actual grades</h5>`);
703
704 $("#gradeSummary").addClass("whatIf");
705 $("#classGradeMore").addClass("whatIf");
706 }
707 }
708
709 //Calculates what-if grade and updates the UI based on the results
710 var calcWhatIf = function (course) {
711 if (course.gradeCalculation.dtech.whatIfOutcomes) {
712 //Class has what-if outcomes
713
714 //Run grade calculation with modified outcomes object
715 var results = dtechGradeCalc.run(course.assignments, course.gradeCalculation.dtech.formula, course.gradeCalculation.dtech.whatIfOutcomes);
716
717 //Update whatIfOutcomes object with new scores
718 course.gradeCalculation.dtech.whatIfOutcomes = results.outcomes;
719
720 //Update what-if results card with the grade calculation results
721 $("#gradeSummary .block.letterGrade h2.main").html(results.results.letter);
722 $("#gradeSummary .block.number75 h2.main").html(results.results.parameters.number75.toFixed(2));
723 $("#gradeSummary .block.lowestScore h2.main").html(results.results.parameters.lowestScore.toFixed(2));
724 $("#classGradeMore .table tr").removeClass("active");
jd4e75d02023-08-22 12:45:59 -0700725 $("#classGradeMore .table tr." + cssClassForLetterGrade(results.results.letter)).addClass("active");
j7940eec2020-12-28 14:00:41 -0600726
727 //Remove dropped state
728 $(".card.outcomeResults .dropped").removeClass("dropped");
729
730 Object.keys(course.gradeCalculation.dtech.whatIfOutcomes).forEach(outcomeID => {
731 var outcome = course.gradeCalculation.dtech.whatIfOutcomes[outcomeID];
732
733 //Update outcome average
734 if (outcome.average !== undefined) {
j4d933ce2022-04-08 21:49:55 +0000735 $("#outcomeScore" + outcomeID).html(outcome.average?.toFixed(2) ?? "");
j7940eec2020-12-28 14:00:41 -0600736 $("#outcomeScore" + outcomeID).css("color", dtechRubricColor(outcome.average));
737 }
738
739 //Add dropped state if the score is dropped
740 if (outcome.droppedScore !== undefined) {
741 $("#outcome" + outcomeID + "assessment" + outcome.droppedScore).addClass("dropped");
742 }
743 })
744 }
745 }
746
747 //Adds a new score to an outcome
748 var addWhatIf = function (course, outcomeID) {
749 //Prepare what-if grades if it's not already prepared
750 initWhatIf(course);
751
752 //Get new assessment index
753 var aIndex = course.gradeCalculation.dtech.whatIfOutcomes[outcomeID].scores.length;
754
755 //Add new assessment to the outcome
756 course.gradeCalculation.dtech.whatIfOutcomes[outcomeID].scores.push({ //most of the stuff in this object is optional but I'm adding it anyways
757 id: "whatIf" + aIndex, //if changing this, update the id for the rendered what-if grade assessment as well
758 score: null,
759 value: 4,
760 whatIfGrade: true,
761 outcome: outcomeID,
762 color: "var(--secText)",
763 assignmentTitle: "What-If Grade",
764 description: "A What-If grade",
765 title: course.gradeCalculation.dtech.whatIfOutcomes[outcomeID].title,
766 assignmentID: null
767 });
768
769 //Add a new What-If assessment to the UI
770 $(".card.outcomeResults.outcome-" + outcomeID + " .assessments").append(/*html*/`
771 <div class="assessmentWrapper" id="outcome${outcomeID}assessment${aIndex}" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 6px 0px;">
772 <div style="color: var(--secText);" aIndex="${aIndex}" outcomeID="${outcomeID}" class="editableScore modified whatIf" contenteditable></div>
773 <span class="assessmentTitle">What-If Grade</span>
774 </div>
775 `);
776
777 //Add an event listener for the new score
778 listenForWhatIf($(`#outcome${outcomeID}assessment${aIndex} .editableScore`)[0], course);
779 }
j4d933ce2022-04-08 21:49:55 +0000780});