Browse Source

125444

master
lichong 8 months ago
parent
commit
11729f20ce
  1. 64
      api/main.py
  2. 8
      front/src/api/teacher.js
  3. 62
      front/src/component/table.vue
  4. 13
      front/src/views/student.vue
  5. 57
      front/src/views/teacher.vue

64
api/main.py

@ -86,15 +86,13 @@ def handle_video_frame(message):
_, img_data = base64_str.split(",")
img_data = base64.b64decode(img_data)
# 将字节流转换为PIL图像对象
# 将字节数据转换为NumPy数组
# 将字节数据转换为NumPy数组
np_data = np.frombuffer(img_data, dtype=np.uint8)
# 使用cv2.imdecode将数组解码为图像
image = cv2.imdecode(np_data, cv2.IMREAD_COLOR)
checkVedioResult(message, image)
socketio.emit(
"teacherVideo" + message["userId"], message, to=adminSid
)
socketio.emit("teacherVideo" + message["userId"], message, to=adminSid)
def checkVedioResult(message, image):
@ -105,7 +103,7 @@ def checkVedioResult(message, image):
global class_name
global clients
global adminSid
det_results = det_model(image,conf=0.5, iou=0.25)
det_results = det_model(image, conf=0.5, iou=0.25)
type = ""
for r in det_results:
if len(r) == 0:
@ -133,20 +131,14 @@ def checkVedioResult(message, image):
for item in clients:
if item["id"] == message["userId"]:
sid = item["sid"]
socketio.emit(
"studentMsg" + message["userId"], message, to=sid
)
socketio.emit("studentMsg" + message["userId"], message, to=sid)
# print(97444, type)
zuobiItem = {
"userId": message["userId"],
"msg": message["data"],
"type": type,
"create_at": time.strftime(
"%Y-%m-%d %H:%M:%S", time.localtime(time.time())
),
"update_at": time.strftime(
"%Y-%m-%d %H:%M:%S", time.localtime(time.time())
),
"create_at": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())),
"update_at": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())),
"isExit": 1,
}
addzuobi(zuobiItem)
@ -158,9 +150,7 @@ def handle_talk(message):
global adminSid
# print(f"Received video frame from {message['userId']}")
message["type"] = "talk"
socketio.emit(
"teacherTalk" + message["userId"], message, to=adminSid
)
socketio.emit("teacherTalk" + message["userId"], message, to=adminSid)
zuobiItem = {
"userId": message["userId"],
"msg": message["data"],
@ -177,9 +167,7 @@ def handle_msg(message):
# 说话实时传输给老师
global adminSid
# print(f"Received video frame from {message['userId']}")
socketio.emit(
"teacherMsg" + message["userId"], message, to=adminSid
)
socketio.emit("teacherMsg" + message["userId"], message, to=adminSid)
zuobiItem = {
"userId": message["userId"],
"msg": message["data"],
@ -198,9 +186,7 @@ def handle_answer_msg(message):
if item["id"] == message["userId"]:
sid = item["sid"]
message["type"] = "answer"
socketio.emit(
"studentMsg" + message["userId"], message, to=sid
)
socketio.emit("studentMsg" + message["userId"], message, to=sid)
zuobiItem = {
"userId": message["userId"],
"msg": message["data"],
@ -498,7 +484,37 @@ def getzuobi():
}
# 警告学生
@app.route("/jinggao", methods=["post"])
def jinggao():
resData = request.data
# 获取到POST过来的数据,转为json形式
userJson = json.loads(resData)
studentId = userJson["studentId"]
sid = ""
for item in clients:
if item["id"] == studentId:
sid = item["sid"]
message = {"type": "jinggao", "data": "请遵守考试规则"}
socketio.emit("studentMsg" + studentId, message, to=sid)
zuobiItem = {
"userId": studentId,
"msg": message["data"],
"type": "jinggao",
"create_at": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())),
"update_at": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())),
"isExit": 1,
}
addzuobi(zuobiItem)
return {
"code": 200,
"msg": "警告成功",
"list": [],
"hasError": False,
}
if __name__ == "__main__":
initData()
# app.run(debug=True)
socketio.run(app, host='0.0.0.0', port=5000, debug=True)
socketio.run(app, host="0.0.0.0", port=5000, debug=True)

8
front/src/api/teacher.js

@ -58,4 +58,12 @@ export function getzuobi(data = {}) {
method: "POST",
data: { id: localStorage.getItem("userId"), ...data },
});
}
//警告学生
export function jinggao(data = {}) {
return _axios({
url: `/v1/jinggao`,
method: "POST",
data: { id: localStorage.getItem("userId"), ...data },
});
}

62
front/src/component/table.vue

@ -38,23 +38,43 @@
</template>
</template>
</el-table-column>
<el-table-column fixed="right" align="center" label="Operations" width="110">
<el-table-column fixed="right" align="center" label="Operations" width="180">
<template #default="scope">
<el-button link type="primary" text @click="detailInfo(scope.row)">
<el-icon>
<InfoFilled />
</el-icon>
</el-button>
<el-button link type="primary" text @click="editInfo(scope.row)">
<el-icon>
<Edit />
</el-icon>
</el-button>
<el-button link type="primary" text @click="updateMima(scope.row)">
<el-icon>
<WalletFilled />
</el-icon>
</el-button>
<el-tooltip content="查看详细信息" placement="top">
<el-button link type="primary" text @click="detailInfo(scope.row)">
<el-icon>
<InfoFilled />
</el-icon>
</el-button>
</el-tooltip>
<el-tooltip content="编辑信息" placement="top">
<el-button link type="primary" text @click="editInfo(scope.row)">
<el-icon>
<Edit />
</el-icon>
</el-button>
</el-tooltip>
<el-tooltip content="更改密码" placement="top">
<el-button link type="primary" text @click="updateMima(scope.row)">
<el-icon>
<WalletFilled />
</el-icon>
</el-button>
</el-tooltip>
<el-tooltip content="警告学生" placement="top">
<el-button link type="primary" text @click="jingaoxuesheng(scope.row)">
<el-icon>
<WarnTriangleFilled />
</el-icon>
</el-button>
</el-tooltip>
<el-tooltip content="显示作弊详情" placement="top">
<el-button link type="primary" text @click="showzuobi(scope.row)">
<el-icon>
<QuestionFilled />
</el-icon>
</el-button>
</el-tooltip>
</template>
</el-table-column>
</el-table>
@ -63,7 +83,7 @@
import _ from "lodash"
export default {
name: "app",
emits: ["detailInfo", "editInfo"],
emits: ["detailInfo", "editInfo", "updateMima", "jingaoxuesheng", "showzuobi"],
props: {
refName: {
typeof: String,
@ -100,7 +120,13 @@ export default {
},
updateMima(item) {
this.$emit("updateMima", item);
}
},
jingaoxuesheng(item) {
this.$emit("jingaoxuesheng", item);
},
showzuobi(item) {
this.$emit("showzuobi", item);
},
},
watch: {},
computed: {},

13
front/src/views/student.vue

@ -200,7 +200,7 @@ export default {
},
async initWebSocket() {
this.socket = io('http://127.0.0.1:5000',
{
{
secure: true,
rejectUnauthorized: false, //
query: { id: this.userId, isAdmin: "0" }
@ -211,7 +211,7 @@ export default {
});
console.log(78444, `studentMsg${this.userId}`)
this.socket.on(`studentMsg${this.userId}`, (data) => {
console.log(78875454477, data)
console.log(777, data)
let msg = _.get(data, ['data'], "")
let answer = _.split(msg, "@@@")
let type = _.get(data, ['type'], "")
@ -220,13 +220,20 @@ export default {
message: `老师回答:${answer[1]}`,
type: "success",
});
} else if (type === "jinggao") {
ElMessage({
message: `${msg}`,
type: "error",
duration: 0,
showClose: true,
});
} else {
if (type !== 'normal') {
ElMessage({
message: `请不要${type}`,
type: "error",
});
}else{
} else {
ElMessage({
message: `${type}`,
type: "success",

57
front/src/views/teacher.vue

@ -14,7 +14,8 @@
</div>
<div>
<vueTable ref="userTableParent" :refName="refName" :tableHeader="tableHeader" :tableData="tableData"
@detailInfo="detailInfo" @editInfo="editInfo" @updateMima="updateMima">
@detailInfo="detailInfo" @editInfo="editInfo" @updateMima="updateMima" @jingaoxuesheng="jingaoxuesheng"
@showzuobi="showzuobi">
</vueTable>
<el-card>
<template #header>
@ -58,6 +59,32 @@
</div>
</template>
</el-dialog>
<el-dialog v-model="showzuobiObj.show" :title="showzuobiObj.title" width="80%" draggable>
<div>
<el-table :data="zuobiListData" height="600">
<el-table-column prop="type" label="作弊类型"></el-table-column>
<el-table-column prop="msg" label="作弊信息" show-overflow-tooltip>
<template #default="scope">
<el-image
v-if="['many_humans', 'leave', 'normal', 'raise_hand', 'speak', 'stand', 'turn_head', 'use_phone'].indexOf(scope.row.type) !== -1 && _.trim(scope.row.msg)"
style="width: 20px; height: 20px;" :src="scope.row.msg" fit="fill" :preview-src-list="[scope.row.msg]"
preview-teleported>
</el-image>
<span v-else-if="scope.row.type !== 'answer'">{{ scope.row.msg }}</span>
<span v-else>{{ _.split(scope.row.msg, "@")[1] || '' }}</span>
</template>
</el-table-column>
<el-table-column prop="create_at" label="作弊时间"></el-table-column>
</el-table>
</div>
<template #footer v-if="!formDisabled">
<div class="dialog-footer">
<el-button @click="closeDialog(showzuobiObj)" type="info" plain>
取消
</el-button>
</div>
</template>
</el-dialog>
</template>
<script>
import vueTable from "../component/table.vue";
@ -70,6 +97,7 @@ import {
getUser, //user
updatePassword,//
getzuobi,//
jinggao,//
} from "@/api/teacher";
import io from "socket.io-client";
import { ElMessage, ElMessageBox } from 'element-plus'
@ -220,6 +248,12 @@ export default {
show: false,
title: "新增用户",
},
showzuobiObj: {
show: false,
title: "查看作弊信息",
},
zuobiObjLocal: {},
zuobiListData: [],
formData: {},
formDataLocal: {},
formHeader: [],
@ -231,6 +265,7 @@ export default {
canvasObj: {},
zuobiInterval: null,
teacherEcharts: null,
};
},
watch: {},
@ -364,6 +399,25 @@ export default {
this.formHeader = _.cloneDeep(_.filter(this.formHeaderLocal, o => o.prop !== "mima"))
this.formData = { ...item };
},
//
async jingaoxuesheng(item) {
let res = await jinggao({ studentId: item._id });
ElMessage({ message: `${item.xueshengxingming}${res.msg}`, type: "success" });
},
//
showzuobi(item) {
if (_.isEmpty(this.zuobiObjLocal)) {
ElMessage({ message: `稍等一会`, type: "info" });
} else {
this.showzuobiObj = {
show: true,
title: `查看${item.xueshengxingming}的作弊信息`,
}
this.zuobiListData = JSON.parse(JSON.stringify(this.zuobiObjLocal[item._id]))
console.log(888, this.zuobiListData)
}
},
//
editInfo(item) {
this.addDialog = {
@ -520,6 +574,7 @@ export default {
let res = await getzuobi()
let zuobiList = res.list
let zuobiObj = _.groupBy(zuobiList, 'userId')
this.zuobiObjLocal = JSON.parse(JSON.stringify(zuobiObj))
let allZuobi = {}
let dataLocal = []
for (let key in zuobiObj) {

Loading…
Cancel
Save