Skip to content

Instantly share code, notes, and snippets.

@BirkhoffLee
Created March 22, 2023 12:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BirkhoffLee/3cc4beb55a2ff368698e385629000a26 to your computer and use it in GitHub Desktop.
Save BirkhoffLee/3cc4beb55a2ff368698e385629000a26 to your computer and use it in GitHub Desktop.
師大 Cumulative GPA 計算機

使用步驟

  1. 把 main.js 存起來
  2. 在同個資料夾跑 npm install xlsx
  3. 在教務系統載成績報表,然後把報表的 path 放進 main.js 裡面(89 行)
  4. $ node main.js
    [
      [ 2, 4.3 ], [ 2, 4 ],   [ 2, 4 ],
      [ 2, 3.7 ], [ 3, 4 ],   [ 3, 4 ],
      [ 3, 3.7 ], [ 1, 4.3 ], [ 3, 1 ],
      [ 2, 4 ],   [ 2, 3.7 ], [ 2, 4 ],
      [ 3, 2.7 ], [ 3, 1.7 ], [ 3, 3 ],
      [ 3, 2 ],   [ 3, 4 ],   [ 2, 4 ],
      [ 2, 2.7 ], [ 2, 0 ],   [ 0, 1.7 ],
      [ 3, 2 ],   [ 3, 2.3 ], [ 3, 2 ],
      [ 3, 3.3 ], [ 2, 3.7 ], [ 2, 3.3 ],
      [ 3, 3.7 ], [ 3, 3.3 ], [ 3, 2.3 ],
      [ 3, 1 ],   [ 2, 4 ],   [ 3, 4 ],
      [ 3, 4 ],   [ 3, 4 ],   [ 3, 4.3 ]
    ]
    Total credits: 90
    Total score: 113.7
    Cumulative GPA: 3.1333333333333333

特別感謝

  • ChatGPT Plus 提供的 GPT-4 模型幫我完成讀取陰間微軟的 .xls 檔案
// Import required modules
const XLSX = require('xlsx');
// Function to read .xls file and process its data
function readXlsFile(filePath) {
// Read the file
const workbook = XLSX.readFile(filePath);
// Get the first worksheet
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
// Convert the worksheet to a JSON array
const jsonData = XLSX.utils.sheet_to_json(worksheet, {header: 1});
// Initialize an empty array to store the rows
const rowsArray = [];
// Iterate through the JSON array and push each row into rowsArray
jsonData.forEach((row) => {
const rowArray = [];
row.forEach((cell) => {
rowArray.push(cell);
});
rowsArray.push(rowArray);
});
// Return the final rows array
return rowsArray;
}
function gradeToRawScore(grade) {
let rawScore = NaN;
switch (grade) {
case 'A+':
rawScore = 4.3;
break;
case 'A':
rawScore = 4.0;
break;
case 'A-':
rawScore = 3.7;
break;
case 'B+':
rawScore = 3.3;
break;
case 'B':
rawScore = 3.0;
break;
case 'B-':
rawScore = 2.7;
break;
case 'C+':
rawScore = 2.3;
break;
case 'C':
rawScore = 2.0;
break;
case 'C-':
rawScore = 1.7;
break;
case 'D':
rawScore = 1.0;
break;
case 'E':
rawScore = 0.0;
break;
default:
throw new Error('Unexpected grade: ' + grade);
}
return rawScore;
}
const filePath = '/Users/birkhoff/Downloads/scoreExport.xls';
const rows = readXlsFile(filePath);
const converted = rows
.slice(1)
.filter(row => row[6] !== 'P' && row[6] !== '停修' && row[7] !== '另計')
.map(row => [parseFloat(row[5]), gradeToRawScore(row[6])]);
console.log(converted)
let totalCredits = 0.0;
let totalScore = 0.0;
let temp = 0.0;
for (const course of converted) {
totalCredits += course[0];
totalScore += course[1];
temp += course[0] * course[1];
}
console.log("Total credits:", totalCredits)
console.log("Total score:", totalScore)
console.log("Cumulative GPA:", temp / totalCredits)
@BirkhoffLee
Copy link
Author

scoreExport.xls 這裡下載

image

@BirkhoffLee
Copy link
Author

英國的 GPA 是 4.0 滿分,師大是 4.3 滿分,所以要用這張圖對照找到自己的百分位,就是成績

CleanShot 2023-03-22 at 20 29 38@2x

對比 The University of Sheffield 的 international equivalent:

image

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