Skip to content

Instantly share code, notes, and snippets.

@shivaluma
Last active May 27, 2024 19:33
Show Gist options
  • Save shivaluma/e1f420be1d3cf8e6c6287539e8abcf89 to your computer and use it in GitHub Desktop.
Save shivaluma/e1f420be1d3cf8e6c6287539e8abcf89 to your computer and use it in GitHub Desktop.
Tinh diem trung binh hcmus
// tinh diem trung binh hcmus, vao trang diem va paste vao console.
// khong tinh anh van, quoc phong, the duc va nhung mon rot
var tinchi = document.querySelectorAll("td:nth-child(3)");
var monhoc = document.querySelectorAll("td:nth-child(2)");
var diem = document.querySelectorAll("td:nth-child(6)");
var tongdiem = 0,
tongtinchi = 0;
for (var i = 1; i < tinchi.length; i++) {
if (
monhoc[i].innerText.includes("Thể dục") ||
monhoc[i].innerText.includes("Anh văn") ||
monhoc[i].innerText.includes("Giáo dục") || !Number(diem[i].innerText) || Number(diem[i].innerText) < 5
) {
continue;
}
tongdiem += Number(tinchi[i].innerText) * Number(diem[i].innerText);
tongtinchi += Number(tinchi[i].innerText);
}
console.log("Tong tin chi : " + tongtinchi);
console.log("Diem trung binh : " + tongdiem / tongtinchi);
@bpmthanh
Copy link

bpmthanh commented Aug 22, 2023

// Sắp xếp theo A->Z tiếng việt, học cải thiện hoặc rớt môn thì lấy môn mới nhất
function compareVietnameseStrings(str1, str2) {
var collator = new Intl.Collator("vi", { sensitivity: "base" });
return collator.compare(str1, str2);
}

var tinchi = document.querySelectorAll("td:nth-child(3)");
var monhoc = document.querySelectorAll("td:nth-child(2)");
var diem = document.querySelectorAll("td:nth-child(6)");

var excludedSubjects = ["Thể dục", "Anh văn", "Giáo dục", "Tin học"];

var subjectsData = {};

for (var i = 0; i < tinchi.length; i++) {
var subjectName = monhoc[i].innerText;
var credit = Number(tinchi[i].innerText);
var score = Number(diem[i].innerText);

if (
excludedSubjects.some(excludedSubject => subjectName.includes(excludedSubject)) ||
isNaN(score) ||
score < 5
) {
continue;
}

// Tìm vị trí của dấu "- " đầu tiên
var firstDashIndex = subjectName.indexOf(" - ");

// Cắt tên môn học từ dấu "- " đầu tiên nếu có
var nameWithoutCode = firstDashIndex !== -1 ? subjectName.substring(firstDashIndex + 3) : subjectName;

// Ghi đè dữ liệu môn học cuối cùng nếu đã tồn tại
subjectsData[nameWithoutCode] = { credit, score };
}

// Sắp xếp danh sách môn học theo tên
var sortedSubjects = Object.keys(subjectsData).sort(function(a, b) {
return compareVietnameseStrings(a.toUpperCase(), b.toUpperCase());
});

var totalScore = 0,
totalCredits = 0;

// In ra từng môn học và điểm tương ứng
for (var i = 0; i < sortedSubjects.length; i++) {
var subjectName = sortedSubjects[i];
var credit = subjectsData[subjectName].credit;
var score = subjectsData[subjectName].score;
console.log("Môn: " + subjectName + "\nTín chỉ: " + credit + "\nĐiểm: " + score + "\n");

totalScore += credit * score;
totalCredits += credit;
}

console.log("Tổng tín chỉ: " + totalCredits);
console.log("Điểm trung bình: " + (totalScore / totalCredits).toFixed(3));

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