Files
RongGiuangKT/html/test_server_data.html
2025-10-09 19:25:48 +08:00

336 lines
9.4 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>服务器数据测试</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1000px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.section {
margin: 20px 0;
padding: 20px;
border: 2px solid #4ecdc4;
border-radius: 10px;
}
.status {
margin: 10px 0;
padding: 10px;
border-radius: 5px;
font-weight: bold;
}
.success {
background: #d4edda;
color: #155724;
}
.error {
background: #f8d7da;
color: #721c24;
}
.info {
background: #d1ecf1;
color: #0c5460;
}
button {
background: #4ecdc4;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #45b7aa;
}
.data-display {
background: #f8f9fa;
padding: 15px;
border-radius: 5px;
max-height: 400px;
overflow-y: auto;
font-family: monospace;
font-size: 12px;
white-space: pre-wrap;
border: 1px solid #dee2e6;
}
.detection-item {
margin: 10px 0;
padding: 10px;
background: #e9ecef;
border-radius: 5px;
border-left: 4px solid #4ecdc4;
}
.detection-property {
margin: 5px 0;
padding: 3px 8px;
background: white;
border-radius: 3px;
display: inline-block;
margin-right: 10px;
}
/* 体感交互容器样式 */
.box-body {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
padding: 20px;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
z-index: 2000;
max-width: 500px;
text-align: center;
}
.box-body img {
max-width: 100%;
height: auto;
border-radius: 10px;
margin: 10px 0;
}
.box-body div {
margin: 10px 0;
padding: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>🔍 服务器数据测试</h1>
<div class="section">
<h3>📋 测试说明</h3>
<p>
这个页面用于测试体感交互服务器返回的数据格式,帮助诊断举手检测问题。
</p>
<ul>
<li>点击"启动体感交互"按钮</li>
<li>允许摄像头权限</li>
<li>举起左手或右手</li>
<li>观察服务器返回的原始数据</li>
</ul>
</div>
<div class="section">
<h3>📊 连接状态</h3>
<div id="connectionStatus" class="status info">
未连接到体感检测服务器
</div>
<div id="handStatus" class="status info">等待检测...</div>
</div>
<div class="section">
<h3>🔧 控制面板</h3>
<button onclick="startBodySensation()">启动体感交互</button>
<button onclick="stopBodySensation()">停止体感交互</button>
<button onclick="clearData()">清除数据</button>
</div>
<div class="section">
<h3>📡 服务器原始数据</h3>
<div id="rawData" class="data-display">等待数据...</div>
</div>
<div class="section">
<h3>🔍 检测结果分析</h3>
<div id="detectionAnalysis" class="data-display">等待分析...</div>
</div>
<div class="section">
<h3>📝 详细日志</h3>
<div id="detailedLog" class="data-display">等待日志...</div>
</div>
</div>
<!-- 体感交互容器用于directBodySensation.js -->
<div class="box-body" style="display: none">
<div id="bodyConnectionStatus">未连接到服务器</div>
<img id="bodyVideoFeed" src="" alt="体感检测视频" />
<div id="bodyHandStatus">等待检测...</div>
</div>
<!-- 引入体感交互脚本 -->
<script src="../js/directBodySensation.js"></script>
<script>
let dataCount = 0;
let lastData = null;
// 启动体感交互
function startBodySensation() {
log("正在启动体感交互系统...");
try {
if (typeof showBody === "function") {
showBody();
log("✅ 体感交互系统已启动");
} else {
log("❌ 体感交互系统未加载");
}
} catch (error) {
log(`❌ 启动体感交互错误: ${error.message}`);
}
}
// 停止体感交互
function stopBodySensation() {
log("正在停止体感交互系统...");
try {
if (typeof showBody === "function") {
showBody(); // 再次调用会切换状态
log("✅ 体感交互系统已停止");
} else {
log("❌ 体感交互系统未加载");
}
} catch (error) {
log(`❌ 停止体感交互错误: ${error.message}`);
}
}
// 清除数据
function clearData() {
document.getElementById("rawData").textContent = "数据已清除...";
document.getElementById("detectionAnalysis").textContent =
"分析已清除...";
document.getElementById("detailedLog").textContent = "日志已清除...";
dataCount = 0;
lastData = null;
}
// 日志函数
function log(message) {
const logDiv = document.getElementById("detailedLog");
const timestamp = new Date().toLocaleTimeString();
logDiv.textContent += `[${timestamp}] ${message}\n`;
logDiv.scrollTop = logDiv.scrollHeight;
}
// 分析检测数据
function analyzeDetectionData(data) {
let analysis = "";
if (!data) {
analysis = "无数据";
return analysis;
}
analysis += `数据时间: ${new Date().toLocaleTimeString()}\n`;
analysis += `数据计数: ${++dataCount}\n\n`;
if (data.detections && data.detections.length > 0) {
analysis += `检测到 ${data.detections.length} 个人:\n\n`;
data.detections.forEach((detection, index) => {
analysis += `人员 ${index + 1}:\n`;
analysis += ` - ID: ${detection.id || "未知"}\n`;
analysis += ` - 举手状态: ${
detection.hand_raised ? "是" : "否"
}\n`;
analysis += ` - 手部状态: ${detection.hand_status || "未知"}\n`;
analysis += ` - 注意力集中: ${
detection.attention_focused ? "是" : "否"
}\n`;
analysis += ` - 注意力原因: ${
detection.attention_reason || "未知"
}\n`;
analysis += ` - 其他属性: ${JSON.stringify(
detection,
null,
2
)}\n\n`;
});
} else {
analysis += "未检测到任何人\n";
}
if (data.total_persons !== undefined) {
analysis += `总人数: ${data.total_persons}\n`;
}
if (data.processing_time !== undefined) {
analysis += `处理时间: ${data.processing_time}ms\n`;
}
return analysis;
}
// 监听体感交互状态变化
function updateStatus() {
const connectionStatus = document.getElementById(
"bodyConnectionStatus"
);
const handStatus = document.getElementById("bodyHandStatus");
if (connectionStatus) {
document.getElementById("connectionStatus").textContent =
connectionStatus.textContent;
}
if (handStatus) {
document.getElementById("handStatus").textContent =
handStatus.textContent;
}
}
// 重写 console.log 来捕获体感交互的日志和数据
const originalLog = console.log;
console.log = function (...args) {
originalLog.apply(console, args);
const message = args.join(" ");
// 捕获检测数据 - 直接检查参数中是否有对象
if (
args.length > 1 &&
typeof args[1] === "object" &&
args[1] !== null
) {
try {
const data = args[1];
lastData = data;
// 显示原始数据
document.getElementById("rawData").textContent = JSON.stringify(
data,
null,
2
);
// 分析数据
const analysis = analyzeDetectionData(data);
document.getElementById("detectionAnalysis").textContent = analysis;
} catch (e) {
log(`处理数据错误: ${e.message}`);
}
}
// 记录所有日志
log(message);
};
// 页面加载完成后自动初始化
document.addEventListener("DOMContentLoaded", function () {
log("🔍 服务器数据测试页面已加载");
// 定期更新状态
setInterval(updateStatus, 1000);
log("✅ 页面初始化完成,可以开始测试");
});
</script>
</body>
</html>