You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

353 lines
17 KiB

@{
ViewData["Title"] = "统计测试";
}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">统计功能测试</h3>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<h5>API测试</h5>
<button class="btn btn-primary mb-2" onclick="testGetAllStats()">获取所有统计数据</button>
<button class="btn btn-info mb-2" onclick="testGetLatestStats()">获取最新统计数据</button>
<button class="btn btn-success mb-2" onclick="testGetSummary()">获取统计摘要</button>
<button class="btn btn-warning mb-2" onclick="testClearStats()">清空统计数据</button>
</div>
<div class="col-md-6">
<h5>SSE测试</h5>
<button class="btn btn-primary mb-2" onclick="testSSE()">测试SSE连接</button>
<button class="btn btn-danger mb-2" onclick="stopSSE()">停止SSE</button>
</div>
</div>
<div class="row mt-3">
<div class="col-12">
<h5>统计配置管理</h5>
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h6>全局统计配置</h6>
</div>
<div class="card-body">
<div class="form-group">
<label>默认Samples:</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="globalSamples">
<label class="form-check-label" for="globalSamples">启用Samples</label>
</div>
</div>
<div class="form-group">
<label>默认RF:</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="globalRf">
<label class="form-check-label" for="globalRf">启用RF</label>
</div>
</div>
<button class="btn btn-primary btn-sm" onclick="loadGlobalConfig()">加载配置</button>
<button class="btn btn-success btn-sm" onclick="saveGlobalConfig()">保存配置</button>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h6>客户端特定配置</h6>
</div>
<div class="card-body">
<div class="form-group">
<label>客户端名称:</label>
<input type="text" class="form-control" id="clientName" placeholder="输入客户端名称">
</div>
<div class="form-group">
<label>IP地址:</label>
<input type="text" class="form-control" id="clientIp" placeholder="输入IP地址">
</div>
<div class="form-group">
<label>配置选项:</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="clientSamples">
<label class="form-check-label" for="clientSamples">启用Samples</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="clientRf">
<label class="form-check-label" for="clientRf">启用RF</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="clientEnabled" checked>
<label class="form-check-label" for="clientEnabled">启用配置</label>
</div>
</div>
<div class="form-group">
<label>描述:</label>
<input type="text" class="form-control" id="clientDescription" placeholder="配置描述">
</div>
<button class="btn btn-primary btn-sm" onclick="loadClientConfig()">加载配置</button>
<button class="btn btn-success btn-sm" onclick="saveClientConfig()">保存配置</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-3">
<div class="col-12">
<h5>配置列表</h5>
<button class="btn btn-info btn-sm mb-2" onclick="loadAllClientConfigs()">刷新配置列表</button>
<div id="configList" class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>客户端名称</th>
<th>IP地址</th>
<th>Samples</th>
<th>RF</th>
<th>启用</th>
<th>描述</th>
<th>操作</th>
</tr>
</thead>
<tbody id="configTableBody">
</tbody>
</table>
</div>
</div>
</div>
<div class="row mt-3">
<div class="col-12">
<h5>测试结果</h5>
<pre id="testResult" style="background-color: #f8f9fa; padding: 10px; border-radius: 5px; max-height: 400px; overflow-y: auto;"></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@section Scripts {
<script>
let sseConnection = null;
function logResult(message) {
const result = document.getElementById('testResult');
const timestamp = new Date().toLocaleTimeString();
result.textContent += `[${timestamp}] ${message}\n`;
result.scrollTop = result.scrollHeight;
}
function testGetAllStats() {
logResult('测试获取所有统计数据...');
$.get('/Statistics/GetAllStats', function(response) {
logResult('响应: ' + JSON.stringify(response, null, 2));
}).fail(function(xhr, status, error) {
logResult('错误: ' + error);
});
}
function testGetLatestStats() {
logResult('测试获取最新统计数据...');
$.get('/Statistics/GetLatestStats', function(response) {
logResult('响应: ' + JSON.stringify(response, null, 2));
}).fail(function(xhr, status, error) {
logResult('错误: ' + error);
});
}
function testGetSummary() {
logResult('测试获取统计摘要...');
$.get('/Statistics/GetSummary', function(response) {
logResult('响应: ' + JSON.stringify(response, null, 2));
}).fail(function(xhr, status, error) {
logResult('错误: ' + error);
});
}
function testClearStats() {
logResult('测试清空统计数据...');
$.post('/Statistics/ClearStats', function(response) {
logResult('响应: ' + JSON.stringify(response, null, 2));
}).fail(function(xhr, status, error) {
logResult('错误: ' + error);
});
}
function testSSE() {
logResult('测试SSE连接...');
if (sseConnection) {
sseConnection.close();
}
sseConnection = new EventSource('/Statistics/SSEStats');
sseConnection.onopen = function(event) {
logResult('SSE连接已建立');
};
sseConnection.onmessage = function(event) {
logResult('SSE消息: ' + event.data);
};
sseConnection.onerror = function(event) {
logResult('SSE错误: ' + JSON.stringify(event));
};
}
function stopSSE() {
logResult('停止SSE连接...');
if (sseConnection) {
sseConnection.close();
sseConnection = null;
logResult('SSE连接已关闭');
}
}
// 统计配置相关函数
function loadGlobalConfig() {
logResult('加载全局统计配置...');
$.get('/Statistics/GetGlobalStatisticsConfig', function(response) {
if (response.success) {
const config = response.data;
document.getElementById('globalSamples').checked = config.defaultSamples;
document.getElementById('globalRf').checked = config.defaultRf;
logResult('全局配置已加载: ' + JSON.stringify(config, null, 2));
} else {
logResult('加载全局配置失败: ' + response.message);
}
}).fail(function(xhr, status, error) {
logResult('加载全局配置错误: ' + error);
});
}
function saveGlobalConfig() {
const config = {
defaultSamples: document.getElementById('globalSamples').checked,
defaultRf: document.getElementById('globalRf').checked,
clientConfigs: []
};
logResult('保存全局统计配置...');
$.ajax({
url: '/Statistics/SetGlobalStatisticsConfig',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(config),
success: function(response) {
logResult('响应: ' + JSON.stringify(response, null, 2));
},
error: function(xhr, status, error) {
logResult('错误: ' + error);
}
});
}
function loadClientConfig() {
const clientName = document.getElementById('clientName').value;
if (!clientName) {
logResult('请输入客户端名称');
return;
}
logResult('加载客户端统计配置: ' + clientName);
$.get('/Statistics/GetClientStatisticsConfig', { clientName: clientName }, function(response) {
if (response.success && response.data) {
const config = response.data;
document.getElementById('clientName').value = config.clientName;
document.getElementById('clientIp').value = config.ipAddress;
document.getElementById('clientSamples').checked = config.enableSamples;
document.getElementById('clientRf').checked = config.enableRf;
document.getElementById('clientEnabled').checked = config.isEnabled;
document.getElementById('clientDescription').value = config.description;
logResult('客户端配置已加载: ' + JSON.stringify(config, null, 2));
} else {
logResult('客户端配置未找到或加载失败');
}
}).fail(function(xhr, status, error) {
logResult('加载客户端配置错误: ' + error);
});
}
function saveClientConfig() {
const config = {
clientName: document.getElementById('clientName').value,
ipAddress: document.getElementById('clientIp').value,
enableSamples: document.getElementById('clientSamples').checked,
enableRf: document.getElementById('clientRf').checked,
isEnabled: document.getElementById('clientEnabled').checked,
description: document.getElementById('clientDescription').value
};
if (!config.clientName) {
logResult('请输入客户端名称');
return;
}
logResult('保存客户端统计配置...');
$.ajax({
url: '/Statistics/SetClientStatisticsConfig',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(config),
success: function(response) {
logResult('响应: ' + JSON.stringify(response, null, 2));
loadAllClientConfigs(); // 刷新配置列表
},
error: function(xhr, status, error) {
logResult('错误: ' + error);
}
});
}
function loadAllClientConfigs() {
logResult('加载所有客户端配置...');
$.get('/Statistics/GetAllClientStatisticsConfigs', function(response) {
if (response.success) {
const configs = response.data;
const tbody = document.getElementById('configTableBody');
tbody.innerHTML = '';
configs.forEach(function(config) {
const row = document.createElement('tr');
row.innerHTML = `
<td>${config.clientName}</td>
<td>${config.ipAddress}</td>
<td>${config.enableSamples ? '是' : '否'}</td>
<td>${config.enableRf ? '是' : '否'}</td>
<td>${config.isEnabled ? '是' : '否'}</td>
<td>${config.description}</td>
<td>
<button class="btn btn-sm btn-primary" onclick="editConfig('${config.clientName}')">编辑</button>
</td>
`;
tbody.appendChild(row);
});
logResult('配置列表已更新,共 ' + configs.length + ' 个配置');
} else {
logResult('加载配置列表失败: ' + response.message);
}
}).fail(function(xhr, status, error) {
logResult('加载配置列表错误: ' + error);
});
}
function editConfig(clientName) {
document.getElementById('clientName').value = clientName;
loadClientConfig();
}
// 页面加载时初始化
$(document).ready(function() {
document.getElementById('testResult').textContent = '';
loadGlobalConfig();
loadAllClientConfigs();
});
</script>
}