diff --git a/index.js b/index.js deleted file mode 100644 index 4d08617..0000000 --- a/index.js +++ /dev/null @@ -1,210 +0,0 @@ -let originalData = []; -let updatedData = []; -let workbook; -let sheetName; -let skippedStudents = []; -// 导入学生名单 -document.getElementById('excelFileInput').addEventListener('change', function (e) { - var file = e.target.files[0]; - if (!file) { - return; - } - var reader = new FileReader(); - reader.onload = function (e) { - var data = new Uint8Array(e.target.result); - workbook = XLSX.read(data, { type: 'array' }); - sheetName = workbook.SheetNames[0]; - var worksheet = workbook.Sheets[sheetName]; - originalData = XLSX.utils.sheet_to_json(worksheet); - updatedData = JSON.parse(JSON.stringify(originalData)); - var displayDiv = document.getElementById('excelDataDisplay'); - // 添加表头 - displayDiv.innerHTML = '
点到的学生学号:${studentId},姓名:${studentName}
`; - return; - } - - // 计算每个学生被选中的概率(总积分越高,被点到的概率越低) - let probabilities = eligibleStudents.map(student => { - let pointsKey = Object.keys(student).find(key => key.includes('积分')); - let studentPoints = pointsKey ? parseInt(student[pointsKey]) : 0; - return 1 / (studentPoints + 1) / totalPoints; - }); - - // 使用 Math.random 和 Date.now 作为种子 - let randomValue = Math.random() + Date.now() % 1000 / 1000; - let cumulativeProbability = 0; - let selectedStudent; - for (let i = 0; i < eligibleStudents.length; i++) { - cumulativeProbability += probabilities[i]; - if (randomValue < cumulativeProbability) { - selectedStudent = eligibleStudents[i]; - break; - } - } - - if (selectedStudent) { - var displayDiv = document.getElementById('excelDataDisplay'); - var rows = Array.from(displayDiv.children).slice(1); - var selectedRow = rows.find(row => row.querySelector('span').textContent.trim() === selectedStudent[Object.keys(selectedStudent)[0]]); - selectedRow.style.backgroundColor = 'lightblue'; - // 获取选中行的学号和姓名并显示在主页面 - var studentInfo = selectedRow.querySelectorAll('span'); - var studentId = studentInfo[0].textContent.trim(); - var studentName = studentInfo[1].textContent.trim(); - var selectedStudentDiv = document.getElementById('selectedStudentInfo'); - selectedStudentDiv.innerHTML = `点到的学生学号:${studentId},姓名:${studentName}
`; - } -}); - -// 到达教室按钮 -document.getElementById('arriveClassroom').addEventListener('click', function () { - var displayDiv = document.getElementById('excelDataDisplay'); - var rows = Array.from(displayDiv.children).slice(1); - if (rows.length > 0) { - var selectedRow = rows.find(row => row.style.backgroundColor === 'lightblue'); - if (selectedRow) { - var studentInfo = selectedRow.querySelectorAll('span'); - var studentId = studentInfo[0].textContent.trim(); - var studentName = studentInfo[1].textContent.trim(); - // 查找对应的学生并增加积分 - var student = updatedData.find(student => student[Object.keys(student)[0]] === studentId && student[Object.keys(student)[1]] === studentName); - if (student) { - let pointsKey = Object.keys(student).find(key => key.includes('积分')); - if (pointsKey) { - student[pointsKey] = parseFloat(student[pointsKey]) + 1; - // 更新显示 - var rowSpans = selectedRow.querySelectorAll('span'); - rowSpans[rowSpans.length - 1].textContent = student[pointsKey]; - } - } - } - } -}); - -// 准确重复所提问的问题 -document.getElementById('repeatedQuestionYes').addEventListener('click', function () { - var displayDiv = document.getElementById('excelDataDisplay'); - var rows = Array.from(displayDiv.children).slice(1); - if (rows.length > 0) { - var selectedRow = rows.find(row => row.style.backgroundColor === 'lightblue'); - if (selectedRow) { - var studentInfo = selectedRow.querySelectorAll('span'); - var studentId = studentInfo[0].textContent.trim(); - var studentName = studentInfo[1].textContent.trim(); - // 查找对应的学生并增加积分 - var student = updatedData.find(student => student[Object.keys(student)[0]] === studentId && student[Object.keys(student)[1]] === studentName); - if (student) { - let pointsKey = Object.keys(student).find(key => key.includes('积分')); - if (pointsKey) { - student[pointsKey] = parseFloat(student[pointsKey]) + 0.5; - // 更新显示 - var rowSpans = selectedRow.querySelectorAll('span'); - rowSpans[rowSpans.length - 1].textContent = student[pointsKey]; - } - } - } - } -}); - -// 不能准确重复所提问的问题 -document.getElementById('repeatedQuestionNo').addEventListener('click', function () { - var displayDiv = document.getElementById('excelDataDisplay'); - var rows = Array.from(displayDiv.children).slice(1); - if (rows.length > 0) { - var selectedRow = rows.find(row => row.style.backgroundColor === 'lightblue'); - if (selectedRow) { - var studentInfo = selectedRow.querySelectorAll('span'); - var studentId = studentInfo[0].textContent.trim(); - var studentName = studentInfo[1].textContent.trim(); - // 查找对应的学生并减少积分 - var student = updatedData.find(student => student[Object.keys(student)[0]] === studentId && student[Object.keys(student)[1]] === studentName); - if (student) { - let pointsKey = Object.keys(student).find(key => key.includes('积分')); - if (pointsKey) { - student[pointsKey] = parseFloat(student[pointsKey]) - 1; - // 更新显示 - var rowSpans = selectedRow.querySelectorAll('span'); - rowSpans[rowSpans.length - 1].textContent = student[pointsKey]; - } - } - } - } -}); - -// 增加自定义分数 -document.getElementById('addScoreButton').addEventListener('click', function () { - var inputScore = parseFloat(document.getElementById('addScoreInput').value); - if (inputScore >= 0.5 && inputScore <= 3 && !isNaN(inputScore)) { - var displayDiv = document.getElementById('excelDataDisplay'); - var rows = Array.from(displayDiv.children).slice(1); - if (rows.length > 0) { - var selectedRow = rows.find(row => row.style.backgroundColor === 'lightblue'); - if (selectedRow) { - var studentInfo = selectedRow.querySelectorAll('span'); - var studentId = studentInfo[0].textContent.trim(); - var studentName = studentInfo[1].textContent.trim(); - // 查找对应的学生并增加积分 - var student = updatedData.find(student => student[Object.keys(student)[0]] === studentId && student[Object.keys(student)[1]] === studentName); - if (student) { - let pointsKey = Object.keys(student).find(key => key.includes('积分')); - if (pointsKey) { - student[pointsKey] = parseFloat(student[pointsKey]) + inputScore; - // 更新显示 - var rowSpans = selectedRow.querySelectorAll('span'); - rowSpans[rowSpans.length - 1].textContent = student[pointsKey]; - - // 如果得分超过 2.5 分,将该学生加入跳过列表 - if (student[pointsKey] > 2.5) { - skippedStudents.push(student); - } - } - } - } - } - } else { - alert('输入的分数应在 0.5 到 3 之间且为有效数字。'); - } -}); \ No newline at end of file