Last active
February 19, 2022 05:46
-
-
Save hungngocphat01/5890700bdf67a5e827336651ebb210b7 to your computer and use it in GitHub Desktop.
Script tính điểm TB tích lũy trên portal HCMUS. Cần chọn "Tất cả" ở trường Năm học trước khi chạy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Lay diem | |
| let rows = document.querySelectorAll('#tbDiemThiGK > tbody > tr') | |
| rows = Array.from(rows).map(row => Array.from(row.querySelectorAll('td')).map( | |
| cell => cell.innerHTML.trim() | |
| )); | |
| // Transform, loai bo mon trung | |
| const dataRows = []; | |
| for (const row of rows) { | |
| const mon = { ten: row[1], tinchi: Number.parseInt(row[2]), diem: Number.parseFloat(row[5]) }; | |
| if (mon.ten.includes('Anh văn') || | |
| mon.ten.includes('quốc phòng') || | |
| mon.ten.includes('Thể dục') || | |
| !mon.diem || mon.diem < 5) | |
| continue; | |
| // Cap nhat lai diem cho mon neu da ton tai va cao hon (hoc cai thien) | |
| let found = false; | |
| for (const dr of dataRows) { | |
| if (dr.ten == mon.ten && mon.diem > dr.diem) { | |
| dr.diem = mon.diem; | |
| found = true; | |
| break; | |
| } | |
| } | |
| if (!found) dataRows.push(mon); | |
| } | |
| // Tinh diem TB | |
| let tongTC = 0, tongDiem = 0, tongTCCN = 0, tongDiemCN = 0; | |
| const maCN = 'CSC'; | |
| for (const dr of dataRows) { | |
| tongTC += dr.tinchi; tongDiem += dr.tinchi * dr.diem; | |
| if (dr.ten.includes(maCN)) { tongTCCN += dr.tinchi; tongDiemCN += dr.tinchi * dr.diem; } | |
| } | |
| // In KQ | |
| console.log(`Tong TC tich luy: ${tongTC}`); | |
| console.log(`Diem TB tich luy: ${(tongDiem / tongTC).toFixed(2)}`); | |
| console.log(`Tong TC tich luy ${maCN}: ${tongTCCN}`); | |
| console.log(`Diem TB tich luy ${maCN}: ${(tongDiemCN / tongTCCN).toFixed(2)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment