DreamyWanderer / GPABookmarklet_Maintanence

Maintenance and add features to GPA calculation extension in old HCMUS Portal page. Porting the same extenstion to work with new HCMUS Portal page.
GNU General Public License v3.0
34 stars 1 forks source link

New four-scale point calculation #4

Closed thanguyen165 closed 9 months ago

thanguyen165 commented 9 months ago

According to the academic transcript from the Office of Academic Affairs (OAA), retrieved in October 2023, the function representing the 4.0 scale is a linear function. For example, based on your current calculation method, if the October grade is 8.8, it corresponds to 3.5 on the 4.0 scale, whereas according to the OAA academic transcript, it is 3.9 [ 3.9 = 3.5 + (8.8 - 8.0) * 0.5 ]

Theo bảng điểm từ Phòng đào tạo, lấy vào tháng 10 năm 2023, hàm số biểu diễn thang hệ 4 là hàm tuyến tính. Chẳng hạn như theo cách tính hiện hành của anh, điểm thang 10 là 8.8 thì đổi sang thang hệ 4 là 3.5, trong khi theo bảng điểm thì là 3.9.

Therefore, the code in the file bookmarklet.js (lines 166 - 182) should be adjusted as follows:

Do đó, code trong file bookmarklet.js (dòng 166 - 182) nên được chỉnh lại như sau:

Old code

let supplementaryGrade = [
    { score: 9, letter: "A+", fourRounding: 4.0},
    { score: 8, letter: "A.", fourRounding: 3.5},
    { score: 7, letter: "B+", fourRounding: 3.0},
    { score: 6, letter: "B.", fourRounding: 2.5},
    { score: 5, letter: "C.", fourRounding: 2.0},
    { score: 4, letter: "D+", fourRounding: 1.5},
    { score: 3, letter: "D.", fourRounding: 1.0},
    { score: 0, letter: "F.", fourRounding: 0.0}
];

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;
    }
});

New code

let supplementaryGrade = [
    { score: 9, letter: "A+", fourRounding: 4.0},
    { score: 8, letter: "A.", fourRounding: 3.5},
    { score: 7, letter: "B+", fourRounding: 3.0},
    { score: 6, letter: "B.", fourRounding: 2.5},
    { score: 5, letter: "C.", fourRounding: 2.0},
    { score: 4, letter: "D+", fourRounding: 1.5},
    { score: 3, letter: "D.", fourRounding: 1.0},
    { score: 0, letter: "F.", fourRounding: 0.0}
];

data.forEach(item => {
    if (item.score >= 0) {
        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 = 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;
        }
    }
});
DreamyWanderer commented 9 months ago

Solved!