Skip to content

Commit

Permalink
Merge pull request #3 from DreamyWanderer/master
Browse files Browse the repository at this point in the history
Fix Issue "New four-scale point calculation"
  • Loading branch information
dtrung98 authored Jan 18, 2024
2 parents ba8f8e4 + 54d73d6 commit 61a1d00
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Add a feature to Hcmus Portal, calculate and show your GPA

*Thanks [Lê Trung Sơn](https://www.facebook.com/trungson.le.142) for confirming the correctness of the Bookmarklet! Thanks **[vkhuy's repository](https://github.com/vkhuy/GPABookmarklet)** for [this finding](#thcsBug).*
*Thanks **[vkhuy's repository](https://github.com/vkhuy/GPABookmarklet)** for [this finding](#thcsBug). Thanks [Nguyen Quang Thang](https://github.com/thanguyen165) for the 4.0 grade system calculation implementation!*

## What is this?

Expand Down
12 changes: 6 additions & 6 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>README</title>
<title>Changelog</title>
<style>
html {
color: #1a1a1a;
Expand Down Expand Up @@ -177,11 +177,11 @@
<h1 id="hcmus-gpa-calculator-bookmarklet-v-2.0.0">HCMUS GPA Calculator
Bookmarklet (v 2.0.0)</h1>
<p>Add a feature to Hcmus Portal, calculate and show your GPA</p>
<p><em>Thanks <a href="https://www.facebook.com/trungson.le.142">
Trung Sơn</a> for confirming the correctness of the Bookmarklet! Thanks
<strong><a href="https://github.com/vkhuy/GPABookmarklet">vkhuy’s
repository</a></strong> for <a href="#thcsBug">this
finding</a>.</em></p>
<p><em>Thanks <strong><a
href="https://github.com/vkhuy/GPABookmarklet">vkhuy’s
repository</a></strong> for <a href="#thcsBug">this finding</a>. Thanks
<a href="https://github.com/thanguyen165">Nguyen Quang Thang</a> for the
4.0 grade system calculation implementation!</em></p>
<h2 id="what-is-this">What is this?</h2>
<p>This is a <a
href="https://github.com/DreamyWanderer/GPABookmarklet_Maintanence">forked
Expand Down
28 changes: 18 additions & 10 deletions bookmarklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,14 @@ javascript: (async function gpa() {
row.include = false;
row.whyExclude += "Điểm nhỏ hơn 5, chưa qua môn. ";
}
else {
let include = true;
{
for (let j = 0; j < exceptCourses.length; j++) {
if (row.course.includes(exceptCourses[j])) {
include = false;
row.include = false;
row.whyExclude += "Học phần không tính trong GPA. ";
break;
}
};
row.include = include;
}

for (let j = 0; j < data.length; j++) {
Expand Down Expand Up @@ -176,8 +174,20 @@ javascript: (async function gpa() {

data.forEach(item => {
if (item.score >= 0) {
item.letter = supplementaryGrade.find(grade => item.score >= grade.score).letter;
item.fourRounding = supplementaryGrade.find(grade => item.score >= grade.score).fourRounding;
const lowerGrade = supplementaryGrade.find(grade => item.score >= grade.score);
const upperGrade = supplementaryGrade.find(grade => item.score < grade.score);

if (lowerGrade && upperGrade) {
const scoreDiff = upperGrade.score - lowerGrade.score;
const ratio = (item.score - lowerGrade.score) / scoreDiff;

item.letter = lowerGrade.letter;
item.fourRounding = toFixed(lowerGrade.fourRounding + ratio * (upperGrade.fourRounding - lowerGrade.fourRounding));
} else {
// Handle edge cases where item.score is higher than the highest score
item.letter = "A+";
item.fourRounding = 4.0;
}
}
});

Expand Down Expand Up @@ -323,8 +333,7 @@ javascript: (async function gpa() {
$(gpaTableHead).append(gpaHeadCol2);

$(gpaTableBody).append('<tr class="odd"><td class="left ">Điểm trung bình tích lũy (GPA)</td><td class="center gpa" id="calGPA"><b>' + toFixed(this.gpa) + '</b></td></tr>');
$(gpaTableBody).append('<tr class="odd"><td class="left ">Điểm trung bình tích lũy (GPA) hệ 4</td><td class="center gpa" id="calGPA"><b>' + toFixed( (this.gpa * 4 / 10)) + '</b></td></tr>');
$(gpaTableBody).append('<tr class="odd"><td class="left ">Điểm trung bình tích lũy (GPA) hệ 4 (theo STSV)</td><td class="center gpa" id="calGPA"><b>' + toFixed(this.fourGPA) + '</b></td></tr>');
$(gpaTableBody).append('<tr class="odd"><td class="left ">Điểm trung bình tích lũy (GPA) hệ 4</td><td class="center gpa" id="calGPA"><b>' + toFixed(this.fourGPA) + '</b></td></tr>');
$(gpaTableBody).append('<tr class="odd"><td class="left ">Điểm trung bình học tập</td><td class="center gpa" id="calGPA">' + toFixed(this.notPassGPA) + '</td></tr>');
$(gpaTableBody).append('<tr class="even"><td class="left">Tổng tín chỉ đã tích luỹ</td><td class="center gpa" id="calSumCredit">' + this.totalCredits + ' tín chỉ</td></tr>');
$(gpaTableBody).append('<tr class="odd"><td class="left">Tổng điểm đã tích lũy</td><td class="center gpa" id="sumScore">' + this.totalScores + '</td></tr>');
Expand Down Expand Up @@ -369,8 +378,7 @@ javascript: (async function gpa() {
});

csv += "Điểm trung bình tích lũy (GPA): " + this.cal.gpa + "\n";
csv += "Điểm trung bình tích lũy (GPA) hệ 4: " + (this.cal.gpa * 4 / 10) + "\n";
csv += "Điểm trung bình tích lũy (GPA) hệ 4 (theo STSV): " + this.cal.fourGPA + "\n";
csv += "Điểm trung bình tích lũy (GPA) hệ 4: " + this.cal.fourGPA + "\n";
csv += "Điểm trung bình học tập: " + this.cal.notPassGPA + "\n";
csv += "Số tín chỉ tích lũy: " + this.cal.totalCredits + "\n";
csv += "Tổng điểm tích lũy: " + this.cal.totalScores + "\n";
Expand Down
2 changes: 1 addition & 1 deletion index.html

Large diffs are not rendered by default.

0 comments on commit 61a1d00

Please sign in to comment.