main^2
QMZ 4 months ago
parent 9a6c7e45ce
commit 3fa158ec45

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

Binary file not shown.

@ -1,59 +0,0 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>模态框示例</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<style>
.modal {
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: #fff;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
</style>
</head>
<body>
<div id="app">
<button @click="tanchuang">创建房间</button>
<div class="modal" v-if="isModalVisible">
<div class="modal-content">
<span @click="closeModal" style="cursor:pointer; float:right;">&times;</span>
<h2>创建房间</h2>
<p>这里是房间创建的内容...</p>
</div>
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
isModalVisible : false
},
methods: {
tanchuang() {
this.isModalVisible = true; // 打开模态框
},
closeModal() {
this.isModalVisible = false; // 关闭模态框
}
}
});
</script>
</body>
</html>

@ -0,0 +1,266 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>课堂点名系统</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<script src="script.js"></script> <!-- 引入你的函数文件 -->
<style>
.joinbutton {
position: absolute; /* 设置为绝对定位 */
bottom:30%; /* 从顶部移动 */
left: 50%; /* 从左边移动 */
border-radius: 15px;
height: 7%;
width: 17%;
font-size: 20px; /* 文本大小 */
font-weight: bold;
transform: translate(-50%, -50%);
}
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
height: 90vh; /* 使 body 高度占满视口 */
}
h1 {
color: #333;
position: absolute; /* 设置为绝对定位 */
bottom:60%;
left: 50%; /* 从左边移动 */
font-size: 80px;
font-weight: bold;
transform: translate(-50%, -50%);
}
input[type="text"] {
padding: 10px;
border: 2px solid #007BFF;
border-radius: 20px;
width: 200px;
height: 40px; /* 增加高度 */
font-size: 16px; /* 可选:增加字体大小 */
transform: translate(-50%, -50%);
position: absolute; /* 设置为绝对定位 */
bottom:40%;
left: 50%; /* 从左边移动 */
}
button {
background-color: #020202;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
transition: background-color 0.3s;
}
.modal {
position: fixed;
z-index: 1; /* 在最上层 */
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
}
.modal-content {
background-color: #fff;
margin: 15% auto;
padding: 40px;
border: 1px solid #888;
width: 15%; /* 可以根据需要调整宽度 */
}
.horizontal-line {
transform: translate(-50%, -50%);
position: absolute; /* 设置为绝对定位 */
bottom:60%; /* 从顶部移动 */
left: 50%; /* 从左边移动 */
width: 25%; /* 横线宽度 */
height: 2px; /* 横线高度 */
background-color: black; /* 横线颜色 */
border: none; /* 去掉边框 */
margin: 20px 0; /* 上下外边距 */
}
</style>
</head>
<body>
<canvas id="Mycanvas"></canvas>
<div id="app">
<h1>课堂点名系统</h1>
<div class="horizontal-line"></div> <!-- 使用自定义的横线 -->
<div><input type="text" id="roomNumber" placeholder="请输入房间号..." required></div>
<div> <button class="joinbutton" @click="tanchuang">加入(创建)房间</button> </div>
<!-- 模态框 -->
<div class="modal" v-if="isModalVisible">
<div class="modal-content">
<span @click="closeModal" style="cursor:pointer; float:right;">&times;</span>
<div>当前房间号没有被创建是否创建房间</div>
<button @click="goToAboutPage" >确认创建房间</button>
</div>
</div>
<!-- 结束模态框 -->
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
isModalVisible:false,
isModalVisible2:false
},
methods: {
goToAboutPage() {
createroom();
// const roomNumber = document.getElementById('roomNumber').value;
// setTimeout(() => {
// window.location.href = `index.html?number=${roomNumber}`;
// }, 1000); // 等待1秒
},
handleFileUpload(event) {
// 这里可以添加处理文件上传的逻辑
},
tanchuang()
{
if(notcreate=true){
this.isModalVisible = true;
}
if(notcreate=false)
{
alert('此房间已存在,进入此房间中');
}
},
uploadFile() {
// 调用外部的 uploadFile 函数
uploadFile();
},
closeModal() {
this.isModalVisible = false; // 关闭模态框
}
}
});
</script>
</body>
<script>
// 定义画布宽高和生成点的个数
var WIDTH = window.innerWidth, HEIGHT = window.innerHeight, POINT = 35;
var canvas = document.getElementById('Mycanvas');
canvas.width = WIDTH,
canvas.height = HEIGHT;
var context = canvas.getContext('2d');
context.strokeStyle = 'rgba(0,0,0,0.02)',
context.strokeWidth = 1,
context.fillStyle = 'rgba(0,0,0,0.05)';
var circleArr = [];
// 线条开始xy坐标结束xy坐标线条透明度
function Line (x, y, _x, _y, o) {
this.beginX = x,
this.beginY = y,
this.closeX = _x,
this.closeY = _y,
this.o = o;
}
// 点圆心xy坐标半径每帧移动xy的距离
function Circle (x, y, r, moveX, moveY) {
this.x = x,
this.y = y,
this.r = r,
this.moveX = moveX,
this.moveY = moveY;
}
// 生成max和min之间的随机数
function num (max, _min) {
var min = arguments[1] || 0;
return Math.floor(Math.random()*(max-min+1)+min);
}
// 绘制原点
function drawCricle (cxt, x, y, r, moveX, moveY) {
var circle = new Circle(x, y, r, moveX, moveY)
cxt.beginPath()
cxt.arc(circle.x, circle.y, circle.r, 0, 2*Math.PI)
cxt.closePath()
cxt.fill();
return circle;
}
// 绘制线条
function drawLine (cxt, x, y, _x, _y, o) {
var line = new Line(x, y, _x, _y, o)
cxt.beginPath()
cxt.strokeStyle = 'rgba(0,0,0,'+ o +')'
cxt.moveTo(line.beginX, line.beginY)
cxt.lineTo(line.closeX, line.closeY)
cxt.closePath()
cxt.stroke();
}
// 初始化生成原点
function init () {
circleArr = [];
for (var i = 0; i < POINT; i++) {
circleArr.push(drawCricle(context, num(WIDTH), num(HEIGHT), num(15, 2), num(10, -10)/40, num(10, -10)/40));
}
draw();
}
// 每帧绘制
function draw () {
context.clearRect(0,0,canvas.width, canvas.height);
for (var i = 0; i < POINT; i++) {
drawCricle(context, circleArr[i].x, circleArr[i].y, circleArr[i].r);
}
for (var i = 0; i < POINT; i++) {
for (var j = 0; j < POINT; j++) {
if (i + j < POINT) {
var A = Math.abs(circleArr[i+j].x - circleArr[i].x),
B = Math.abs(circleArr[i+j].y - circleArr[i].y);
var lineLength = Math.sqrt(A*A + B*B);
var C = 1/lineLength*7-0.009;
var lineOpacity = C > 0.03 ? 0.03 : C;
if (lineOpacity > 0) {
drawLine(context, circleArr[i].x, circleArr[i].y, circleArr[i+j].x, circleArr[i+j].y, lineOpacity);
}
}
}
}
}
// 调用执行
window.onload = function () {
init();
setInterval(function () {
for (var i = 0; i < POINT; i++) {
var cir = circleArr[i];
cir.x += cir.moveX;
cir.y += cir.moveY;
if (cir.x > WIDTH) cir.x = 0;
else if (cir.x < 0) cir.x = WIDTH;
if (cir.y > HEIGHT) cir.y = 0;
else if (cir.y < 0) cir.y = HEIGHT;
}
draw();
}, 16);
}
</script>
</html>

@ -1,134 +0,0 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>课堂点名系统</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<style>
.joinbutton {
border-radius: 15px;
}
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center; /* 垂直居中 */
justify-content: center; /* 水平居中 */
height: 90vh; /* 使 body 高度占满视口 */
}
h1 {
color: #333;
margin-bottom: 20px;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"] {
margin-bottom: 10px;
padding: 10px;
border: 2px solid #007BFF;
border-radius: 20px;
width: 250px;
top
}
button {
background-color: #020202;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 100px;
padding: 10px;
background: white;
border: 1px solid #ddd;
border-radius: 5px;
width: 500px;
text-align: center;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.modal {
position: fixed;
z-index: 1; /* 在最上层 */
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
}
.modal-content {
background-color: #fff;
margin: 15% auto;
padding: 40px;
border: 1px solid #888;
width: 40%; /* 可以根据需要调整宽度 */
}
</style>
</head>
<body>
<div id="app">
<h1>课堂点名系统</h1>
<input type="text" placeholder="请输入房间号..." />
<div> <button class="joinbutton" @click="tanchuang">加入(创建)房间</button> </div>
<!-- 模态框 -->
<div class="modal" v-if="isModalVisible">
<div class="modal-content">
<span @click="closeModal" style="cursor:pointer; float:right;">&times;</span>
<h1>当前房间号没有被创建是否创建房间</h1>
<button @click="goToAboutPage">确认创建房间</button>
</div>
</div>
<!-- 结束模态框 -->
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
isModalVisible:false,
isModalVisible2:false
},
methods: {
goToAboutPage() {
window.location.href = 'index.html'; // 跳转到 index.html
},
handleFileUpload(event) {
// 这里可以添加处理文件上传的逻辑
},
tanchuang()
{
this.isModalVisible = true;
},
uploadFile() {
// 调用外部的 uploadFile 函数
uploadFile();
},
closeModal() {
this.isModalVisible = false; // 关闭模态框
}
}
});
</script>
</body>
</html>

@ -7,6 +7,16 @@
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<script src="script.js"></script> <!-- 引入你的函数文件 -->
<style>
.filee
{
position: absolute; /* 绝对定位 */
top: 22%;
left: 6%;
height: 30px; /* 设置高度 */
}
.container {
display: grid; /* 使用 Grid 布局 */
grid-template-columns: repeat(3, 1fr); /* 创建三列 */
@ -70,6 +80,7 @@
width: 280px;
height: 80px;
justify-content: center; /* 水平居中 */
}
.rpointbutton
{
@ -78,6 +89,8 @@
height: 120px; /* 设置高度,确保与宽度相等 */
border-radius: 50%; /* 圆形 */
font-size: 25px; /* 字体大小 */
}
.lpointbutton
{
@ -85,6 +98,7 @@
height: 120px; /* 设置高度,确保与宽度相等 */
border-radius: 50%; /* 圆形 */
font-size: 25px; /* 字体大小 */
}
.small-button {
position: absolute;
@ -102,6 +116,8 @@
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.lsmall-button {
position: absolute;
@ -119,6 +135,8 @@
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.uploadbutton
{
@ -198,11 +216,13 @@
.show .small-button {
opacity: 1; /* 显示小按钮 */
opacity: 1;
}
.show .lsmall-button {
opacity: 1; /* 显示小按钮 */
opacity: 1;
}
/* 添加展开效果并使文本保持竖直 */
@ -217,48 +237,49 @@
</style>
</head>
<body>
<canvas id="Mycanvas"></canvas>
<div id="app">
<div><button class="uploadbutton" @click="uploadFile">上传名单</button></div>
<div class="container">
<div class="topstu">{{ top3[0] }}<br>学号<br>积分</div>
<div class="topstu">{{ top3[1] }}<br>学号<br>积分</div>
<div class="topstu">{{ top3[2] }}<br>学号<br>积分</div>
</div>
<div class="pickedstu">文本内容</div>
<div class="pickedstu" id="picked"> 被抽中的同学</div>
<div><button class = "notinclass" @click="uploadFile">未到课堂</button></div>
<div><button class="pickbutton" @click="getRandomStudent">随机点名</button></div>
<div><input type="file" class="filee" id="fileInput" /></div>
<div class="rcontainer">
<button class="rpointbutton" @click="rtoggleButtons">加分</button>
<div class="small-buttons">
<button class="small-button">1.5</button>
<button class="small-button">2.0</button>
<button class="small-button">2.5</button>
<button class="small-button">3.0</button>
<button class="small-button">0.5</button>
<button class="small-button">1.0</button>
<button class="small-button" @click="changepoints(1.5)">1.5</button>
<button class="small-button" @click="changepoints(2.0)">2.0</button>
<button class="small-button" @click="changepoints(2.5)">2.5</button>
<button class="small-button" @click="changepoints(3.0)">3.0</button>
<button class="small-button" @click="changepoints(0.5)">0.5</button>
<button class="small-button" @click="changepoints(1.0)">1.0</button>
</div>
</div>
<div class="lcontainer">
<button class="lpointbutton" @click="ltoggleButtons">减分</button>
<div class="lsmall-buttons">
<button class="small-button">1.5</button>
<button class="small-button">2.0</button>
<button class="small-button">2.5</button>
<button class="small-button">3.0</button>
<button class="small-button">0.5</button>
<button class="small-button">1.0</button>
<button class="small-button" @click="changepoints(-1.5)">1.5</button>
<button class="small-button" @click="changepoints(-2.0)">2.0</button>
<button class="small-button" @click="changepoints(-2.5)">2.5</button>
<button class="small-button" @click="changepoints(-3.0)">3.0</button>
<button class="small-button" @click="changepoints(-0.5)">0.5</button>
<button class="small-button" @click="changepoints(-1.0)">1.0</button>
</div>
</div>
</div>
@ -270,8 +291,10 @@
},
methods: {
uploadFile() {
// 调用外部的 uploadFile 函数
uploadFile();
uploadFile();
},
getRandomStudent() {
// 调用外部的 getRandomStudent 函数
@ -284,14 +307,7 @@
this.uploadFile();
}
},
addpoints()
{
},
divpoints()
{
},
rtoggleButtons()
{
smallButtons = document.querySelector('.small-buttons');
@ -301,9 +317,117 @@
{
smallButtons = document.querySelector('.lsmall-buttons');
smallButtons.classList.toggle('show');
},
changepoints(chan)
{
console.log(chan);
changepoints(chan);
}
}
})
});
</script>
<script>
// 定义画布宽高和生成点的个数
var WIDTH = window.innerWidth, HEIGHT = window.innerHeight, POINT = 35;
var canvas = document.getElementById('Mycanvas');
canvas.width = WIDTH,
canvas.height = HEIGHT;
var context = canvas.getContext('2d');
context.strokeStyle = 'rgba(0,0,0,0.02)',
context.strokeWidth = 1,
context.fillStyle = 'rgba(0,0,0,0.05)';
var circleArr = [];
// 线条开始xy坐标结束xy坐标线条透明度
function Line (x, y, _x, _y, o) {
this.beginX = x,
this.beginY = y,
this.closeX = _x,
this.closeY = _y,
this.o = o;
}
// 点圆心xy坐标半径每帧移动xy的距离
function Circle (x, y, r, moveX, moveY) {
this.x = x,
this.y = y,
this.r = r,
this.moveX = moveX,
this.moveY = moveY;
}
// 生成max和min之间的随机数
function num (max, _min) {
var min = arguments[1] || 0;
return Math.floor(Math.random()*(max-min+1)+min);
}
// 绘制原点
function drawCricle (cxt, x, y, r, moveX, moveY) {
var circle = new Circle(x, y, r, moveX, moveY)
cxt.beginPath()
cxt.arc(circle.x, circle.y, circle.r, 0, 2*Math.PI)
cxt.closePath()
cxt.fill();
return circle;
}
// 绘制线条
function drawLine (cxt, x, y, _x, _y, o) {
var line = new Line(x, y, _x, _y, o)
cxt.beginPath()
cxt.strokeStyle = 'rgba(0,0,0,'+ o +')'
cxt.moveTo(line.beginX, line.beginY)
cxt.lineTo(line.closeX, line.closeY)
cxt.closePath()
cxt.stroke();
}
// 初始化生成原点
function init () {
circleArr = [];
for (var i = 0; i < POINT; i++) {
circleArr.push(drawCricle(context, num(WIDTH), num(HEIGHT), num(15, 2), num(10, -10)/40, num(10, -10)/40));
}
draw();
}
// 每帧绘制
function draw () {
context.clearRect(0,0,canvas.width, canvas.height);
for (var i = 0; i < POINT; i++) {
drawCricle(context, circleArr[i].x, circleArr[i].y, circleArr[i].r);
}
for (var i = 0; i < POINT; i++) {
for (var j = 0; j < POINT; j++) {
if (i + j < POINT) {
var A = Math.abs(circleArr[i+j].x - circleArr[i].x),
B = Math.abs(circleArr[i+j].y - circleArr[i].y);
var lineLength = Math.sqrt(A*A + B*B);
var C = 1/lineLength*7-0.009;
var lineOpacity = C > 0.03 ? 0.03 : C;
if (lineOpacity > 0) {
drawLine(context, circleArr[i].x, circleArr[i].y, circleArr[i+j].x, circleArr[i+j].y, lineOpacity);
}
}
}
}
}
// 调用执行
window.onload = function () {
init();
setInterval(function () {
for (var i = 0; i < POINT; i++) {
var cir = circleArr[i];
cir.x += cir.moveX;
cir.y += cir.moveY;
if (cir.x > WIDTH) cir.x = 0;
else if (cir.x < 0) cir.x = WIDTH;
if (cir.y > HEIGHT) cir.y = 0;
else if (cir.y < 0) cir.y = HEIGHT;
}
draw();
}, 16);
}
</script>
</body>
</html>

@ -1,6 +1,19 @@
let globalStudent = null;
let globalnumber =0;
async function uploadFile() {
const fileInput = document.getElementById('fileInput'); // 获取文件输入元素
const url = window.location.href;
console.log(fileInput);
// 创建一个 URL 对象
const urlObj = new URL(url);
// 使用 URLSearchParams 获取查询参数
const params = new URLSearchParams(urlObj.search);
// 获取 'number' 参数的值
globalnumber = params.get('number');
// 检查是否选中了文件
if (fileInput.files.length === 0) {
alert('请先选择一个文件!');
@ -26,10 +39,8 @@ async function uploadFile() {
const formData = new FormData();
formData.append('file', file);
document.getElementById('result').innerText = '上传中...';
try {
const response = await fetch('http://10.133.39.58:8000/upload', {
const response = await fetch(`http://10.133.39.58:8000/${globalnumber}/upload`, {
method: 'POST',
body: formData
});
@ -40,34 +51,101 @@ async function uploadFile() {
const data = await response.json();
console.log(data);
document.getElementById('result').innerText = '上传成功!';
} catch (error) {
}
catch (error) {
console.error('错误:', error);
alert('上传失败: ' + error.message);
}
}
async function getRandomStudent() {
const response = await fetch('http://10.133.39.58:8000/random-call');
console.log('haha');
const response = await fetch(`http://10.133.39.58:8000/${globalnumber}/random-call`,
{
method: 'POST',
});
const student = await response.json();
document.getElementById('result').innerText = `Selected: ${student.name} (ID: ${student.id}) (points: ${student.points})`;
globalStudent=student;
console.log(student);
document.getElementById('picked').innerText = `Selected: ${student.name} (ID: ${student.id}) (points: ${student.points})`;
}
async function createroom()
{
const response = await fetch('http://10.133.39.58:8000/random-call');
const student = await response.json();
document.getElementById('result').innerText = `Selected: ${student.name} (ID: ${student.id}) (points: ${student.points})`;
async function createroom() {
const roomNumber = document.getElementById('roomNumber').value;
if (roomNumber.trim() === '') {
alert('房间号码不能为空!');
this.isModalVisible = false;
return;
}
globalnumber = roomNumber;
console.log(roomNumber);
try {
const response = await fetch(`http://10.133.39.58:8000/create-class/${globalnumber}`, {
method: 'POST',
});
if (!response.ok) {
throw new Error('文件上传失败。');
}
const data = await response.json(); // 解析响应数据(假设返回的是 JSON 格式)
console.log('房间创建成功:', data); // 输出成功消息或处理数据
alert(data.message);
} catch (error) {
console.error('发生错误:', error.message); // 输出错误信息
alert(`连接后端服务器失败: ${error.message}`); // 弹窗显示错误信息
}
setTimeout(() => {
window.location.href = `index.html?number=${roomNumber}`;
}, 300); // 等待1秒
}
async function backpoints()
async function changepoints(chan)
{
const response = await fetch('http://10.133.39.58:8000/random-call');
const student = await response.json();
document.getElementById('result').innerText = `Selected: ${student.name} (ID: ${student.id}) (points: ${student.points})`;
const idi = globalStudent.id;
const namei = globalStudent.name;
const pointsi = chan;
globalStudent.points+=chan;
const response = await fetch(`http://10.133.39.58:8000/${globalnumber}/change-points`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: String(idi),
name: String(namei),
points: parseFloat(pointsi)
}),
});
response.json().then(result => {
console.log(result); // 输出 Promise 的结果
}).catch(error => {
console.error("发生错误:", error);
});
document.getElementById('picked').innerText = `Selected: ${globalStudent.name} (ID: ${globalStudent.id}) (points: ${globalStudent.points})`;
}

@ -1,73 +0,0 @@
const express = require('express');
const multer = require('multer');
const XLSX = require('xlsx');
const path = require('path');
const app = express();
const upload = multer({ dest: 'uploads/' });
let students = [];
let scores = {};
// Middleware to serve static files
app.use(express.static('public'));
// Endpoint to upload Excel file
app.post('/upload', upload.single('file'), (req, res) => {
const workbook = XLSX.readFile(req.file.path);
const sheetName = workbook.SheetNames[0];
const sheet = workbook.Sheets[sheetName];
students = XLSX.utils.sheet_to_json(sheet);
// Initialize scores
students.forEach(student => {
scores[student.id] = { name: student.name, points: 0 };
});
res.json(students);
});
// Endpoint to randomly select a student
app.get('/random', (req, res) => {
if (students.length === 0) return res.status(400).send('No students available.');
// Calculate weights based on scores
const weights = students.map(student => {
return Math.max(1, 10 - scores[student.id].points); // Higher score -> lower weight
});
const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
const randomNum = Math.random() * totalWeight;
let cumulativeWeight = 0;
for (let i = 0; i < students.length; i++) {
cumulativeWeight += weights[i];
if (randomNum < cumulativeWeight) {
return res.json(students[i]);
}
}
});
// Endpoint to update scores
app.post('/update-score', (req, res) => {
const { id, correctRepeat, correctAnswer } = req.body;
if (!scores[id]) return res.status(400).send('Invalid student ID.');
if (correctRepeat) {
scores[id].points += 0.5;
} else {
scores[id].points -= 1;
}
if (correctAnswer) {
scores[id].points += 1; // Adjust according to your scoring logic
}
res.json(scores[id]);
});
// Start the server
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
Loading…
Cancel
Save