Skip to content

Instantly share code, notes, and snippets.

@xlash123
Created May 13, 2019 22:22
Show Gist options
  • Save xlash123/0068db62ed3b88def5057a2b136fecc4 to your computer and use it in GitHub Desktop.
Save xlash123/0068db62ed3b88def5057a2b136fecc4 to your computer and use it in GitHub Desktop.
Focus Grade Estimator
function getLetterGrade(grade){
if(grade>=90) return 'A';
else if(grade>=80) return 'B';
else if(grade>=70) return 'C';
else if(grade>=60) return 'D';
else return 'F';
}
const getById = id => document.getElementById(id);
const table = getById('center_table');
const rows = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
var weightPercentTable = document.getElementsByTagName('tbody')[1].getElementsByTagName('tr')[1];
const isWeighted = !!weightPercentTable;
var weightNamesTable;
var weightScoreTable;
var weightedGradeSlot;
if(isWeighted){
weightPercentTable = weightPercentTable.getElementsByTagName('td');
weightNamesTable = document.getElementsByTagName('tbody')[1].getElementsByTagName('tr')[0].getElementsByTagName('td');
weightScoreTable = document.getElementsByTagName('tbody')[1].getElementsByTagName('tr')[2].getElementsByTagName('td');
weightedGradeSlot = weightScoreTable[weightScoreTable.length-1].getElementsByTagName('b')[0];
}
const gradeDisplay = getById('currentStudentGrade[]');
const roundGrade = grade => Math.round(grade*1000)/1000;
function setGrade(grade, el){
const g = roundGrade(grade);
el.innerText = roundGrade(g) + '% ' + getLetterGrade(g);
}
var weightNames = [];
var weightPercents = [];
if(weightPercentTable){
for(var i=0; i<weightPercentTable.length-1; i++){
const str = weightPercentTable[i].innerText;
weightPercents.push(Number(str.substring(0, str.length-1))/100);
weightNames.push(weightNamesTable[i].innerText);
}
}else weightPercents = [1];
function calculateGrades(){
var totalPoints = Array(weightPercents.length).fill(0);
var totalGrade = Array(weightPercents.length).fill(0);
for(var i=0; i<rows.length; i++){
const cols = rows[i].getElementsByClassName('LO_field');
if(cols.length < 7) continue;
const gradeStr = cols[1].innerText;
const assignmentStr = cols[6].innerText;
const idx = gradeStr.indexOf('/');
const grade = Number(cols[1].getElementsByTagName('input')[0].value);
if(!isNaN(grade)){
const points = Number(gradeStr.substring(idx+1));
var assignmentIdx = 0;
if(isWeighted){
for(var j=0; j<weightNames.length; j++){
if(weightNames[j] === assignmentStr){
assignmentIdx = j;
break;
}
}
}
totalGrade[assignmentIdx] += grade;
totalPoints[assignmentIdx] += points;
setGrade(100*grade/points, cols[2]);
}
}
var weightedGrades = Array(weightPercents.length).fill(0);
for(var i=0; i<totalPoints.length; i++){
weightedGrades[i] = 100*totalGrade[i]/totalPoints[i];
}
var finalGrade = 0;
for(var i=0; i<weightedGrades.length; i++){
if(isWeighted) setGrade(weightedGrades[i], weightScoreTable[i]);
finalGrade += weightPercents[i]*weightedGrades[i];
}
setGrade(finalGrade, gradeDisplay);
if(isWeighted) setGrade(finalGrade, weightedGradeSlot);
}
for(var i=0; i<rows.length; i++){
const cols = rows[i].getElementsByClassName('LO_field');
if(cols.length < 7) continue;
const gradeStr = cols[1].innerText;
const idx = gradeStr.indexOf('/');
cols[1].innerHTML = '<input onchange="calculateGrades()" type="text" size="1" value="' + gradeStr.substring(0, idx-1) + '" /> / ' + gradeStr.substring(idx+1);
}
console.log('Loaded Focus Grade Estimator');
function getLetterGrade(e){return e>=90?"A":e>=80?"B":e>=70?"C":e>=60?"D":"F"}const getById=e=>document.getElementById(e),table=getById("center_table"),rows=table.getElementsByTagName("tbody")[0].getElementsByTagName("tr");var weightPercentTable=document.getElementsByTagName("tbody")[1].getElementsByTagName("tr")[1];const isWeighted=!!weightPercentTable;var weightNamesTable,weightScoreTable,weightedGradeSlot;isWeighted&&(weightPercentTable=weightPercentTable.getElementsByTagName("td"),weightNamesTable=document.getElementsByTagName("tbody")[1].getElementsByTagName("tr")[0].getElementsByTagName("td"),weightScoreTable=document.getElementsByTagName("tbody")[1].getElementsByTagName("tr")[2].getElementsByTagName("td"),weightedGradeSlot=weightScoreTable[weightScoreTable.length-1].getElementsByTagName("b")[0]);const gradeDisplay=getById("currentStudentGrade[]"),roundGrade=e=>Math.round(1e3*e)/1e3;function setGrade(e,t){const a=roundGrade(e);t.innerText=roundGrade(a)+"% "+getLetterGrade(a)}var weightNames=[],weightPercents=[];if(weightPercentTable)for(var i=0;i<weightPercentTable.length-1;i++){const e=weightPercentTable[i].innerText;weightPercents.push(Number(e.substring(0,e.length-1))/100),weightNames.push(weightNamesTable[i].innerText)}else weightPercents=[1];function calculateGrades(){for(var e=Array(weightPercents.length).fill(0),t=Array(weightPercents.length).fill(0),a=0;a<rows.length;a++){const g=rows[a].getElementsByClassName("LO_field");if(g.length<7)continue;const i=g[1].innerText,s=g[6].innerText,l=i.indexOf("/"),d=Number(g[1].getElementsByTagName("input")[0].value);if(!isNaN(d)){const a=Number(i.substring(l+1));var n=0;if(isWeighted)for(var r=0;r<weightNames.length;r++)if(weightNames[r]===s){n=r;break}t[n]+=d,e[n]+=a,setGrade(100*d/a,g[2])}}var g=Array(weightPercents.length).fill(0);for(a=0;a<e.length;a++)g[a]=100*t[a]/e[a];var i=0;for(a=0;a<g.length;a++)isWeighted&&setGrade(g[a],weightScoreTable[a]),i+=weightPercents[a]*g[a];setGrade(i,gradeDisplay),isWeighted&&setGrade(i,weightedGradeSlot)}for(i=0;i<rows.length;i++){const e=rows[i].getElementsByClassName("LO_field");if(e.length<7)continue;const t=e[1].innerText,a=t.indexOf("/");e[1].innerHTML='<input onchange="calculateGrades()" type="text" size="1" value="'+t.substring(0,a-1)+'" /> / '+t.substring(a+1)}console.log("Loaded Focus Grade Estimator");
@xlash123
Copy link
Author

xlash123 commented May 13, 2019

Use with Pinellas County's Focus program to estimate your grades. Simply view the gradebook for one of your classes, press F12, go to console, paste either one of the files in (preferably the estimator.min.js one. You can copy by clicking raw and then doing ctrl+a, ctrl+c), and press enter. Note that you must do this every time you reenter a gradebook.

To use, enter a score into the textbox and press enter. This will recalculate all the grades, calculate the weight, and show the final grade with up to 3 decimal point precision.

Some disclaimers: I am not harvesting your data; that's plain to see in the code. This does not actually affect your grade; it is only a visual change. Do not modify this code with intent to harm because that's not nice; pasting in random codes into your console is not a safe thing to do, so only do so with sources you trust (you can trust me because I posted the source code and I'm an alumni).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment