增加了每个设备合格的通过时间,将急停灯改为红色

This commit is contained in:
Jay Huang 2024-10-19 16:58:08 +08:00
parent a35baf7d3d
commit 5601bb0f6e
4 changed files with 88 additions and 49 deletions

26
app.py
View File

@ -44,6 +44,7 @@ def analyze_signals():
lights['alarm'] = False
lights['up'] = False
lights['down'] = False
all_signals.clear()
return # 如果急停条件满足,立即返回
# 然后检查 '08' 信号
@ -55,21 +56,24 @@ def analyze_signals():
if '09' in all_signals:
lights['common'] = True
if len(all_signals) >= 3 and all_signals[-3:] == ['09', '08', '09']:
lights['alarm'] = True
if all_signals[-2:] != ['08', '09']:
lights['alarm'] = False
if '0b' in all_signals or (len(all_signals) >= 2 and all_signals[-2:] == ['09', '0b']):
lights['up'] = True
if all_signals[-1:] != ['0b']:
lights['up'] = False
if '0d' in all_signals or (len(all_signals) >= 2 and all_signals[-2:] == ['09', '0d']):
lights['down'] = True
if all_signals[-1:] != ['0d']:
lights['down'] = False
if len(all_signals) >= 3 and all_signals[-3:] == ['09', '08', '09']:
lights['alarm'] = True
if all_signals[-2:] != ['08', '09']:
lights['alarm'] = False
all_signals.clear()
def read_serial():
global all_signals, thread_running
while thread_running:
@ -175,9 +179,15 @@ def test_port():
@app.route('/clear_signal_data', methods=['POST'])
def clear_signal_data():
global signal_data
signal_data = []
return '', 204
global lights_status
lights_status = {
'common': False,
'alarm': False,
'up': False,
'down': False,
'emergency_stop': False
}
return jsonify({"success": True})
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5888)

View File

@ -58,7 +58,7 @@ function checkAllTestsPassed() {
allTestsPassed = Array.from(document.querySelectorAll(`#statusCheckList${currentDeviceType} .badge`))
.every(badge => badge.style.display === 'inline-block');
// 更测试结果
// 更测试结果
updateTestResult();
}
@ -97,16 +97,24 @@ function updateRowTestResult(row) {
const pendingSpan = label.querySelector('.pending');
const passSpan = label.querySelector('.pass');
const failSpan = label.querySelector('.fail');
const passTimeSpan = row.querySelector('.pass-time');
if (allTestsPassed) {
checkbox.disabled = false;
checkbox.checked = true;
pendingSpan.style.display = 'none';
passSpan.style.display = 'inline';
failSpan.style.display = 'none';
row.classList.remove('pending-row');
row.classList.add('pass-row');
row.classList.remove('fail-row');
if (!checkbox.checked) { // 只在首次通过测试时记录时间
checkbox.disabled = false;
checkbox.checked = true;
pendingSpan.style.display = 'none';
passSpan.style.display = 'inline';
failSpan.style.display = 'none';
row.classList.remove('pending-row');
row.classList.add('pass-row');
row.classList.remove('fail-row');
// 记录合格时间
const now = new Date();
const timeString = now.toLocaleString('zh-CN', { hour12: false });
passTimeSpan.textContent = timeString;
}
} else {
checkbox.disabled = true;
checkbox.checked = false;
@ -116,6 +124,7 @@ function updateRowTestResult(row) {
row.classList.add('pending-row');
row.classList.remove('pass-row');
row.classList.remove('fail-row');
// 不清空合格时间,保留之前记录的时间(如果有的话)
}
}
@ -139,6 +148,7 @@ function addNewRow(button) {
const cell1 = newRow.insertCell(0);
const cell2 = newRow.insertCell(1);
const cell3 = newRow.insertCell(2);
const cell4 = newRow.insertCell(3);
cell1.innerHTML = '<input type="text" class="form-control serial-number" placeholder="输入设备序列号">';
cell2.innerHTML = `
@ -150,17 +160,24 @@ function addNewRow(button) {
<span class="fail" style="display: none;">不合格</span>
</label>
</div>`;
cell3.innerHTML = '<button class="btn btn-primary add-row-btn" onclick="addNewRow(this)">增加下一条</button>';
cell3.innerHTML = '<span class="pass-time"></span>';
cell4.innerHTML = '<button class="btn btn-primary add-row-btn" onclick="addNewRow(this)">增加下一条</button>';
// 重置表单和状态
resetForm();
// 聚焦到新的设备序列号输入框
const newSerialInput = newRow.querySelector('.serial-number');
newSerialInput.focus();
// 重置灯光状态监控
resetLights();
// 重置检测状态记录
resetCheckList();
// 清空app.py的信号数据
clearSignalData();
// 聚焦到新的设备序列号输入框
const newSerialInput = newRow.querySelector('.serial-number');
newSerialInput.focus();
}
function finalizeRowStatus(row) {
@ -173,22 +190,13 @@ function finalizeRowStatus(row) {
checkbox.disabled = true;
}
function resetForm() {
// 重置测试结果为待测试状态
resetTestResult();
// 重置检测状态记录
resetDetectionStatus();
// 重置灯光状态
resetLightStatus();
}
//重置测试结果
function resetTestResult() {
allTestsPassed = false;
updateTestResult();
}
//重置检测状态记录
function resetDetectionStatus() {
lightHistory = {
common: false,
@ -208,6 +216,7 @@ function resetDetectionStatus() {
}
}
//重置灯光状态
function resetLightStatus() {
const lights = document.querySelectorAll('.light');
lights.forEach(light => {
@ -216,14 +225,31 @@ function resetLightStatus() {
});
}
function resetForm() {
// 重置测试结果为待测试状态
resetTestResult();
// 重置检测状态记录
resetDetectionStatus();
// 重置灯光状态
resetLightStatus();
}
function clearSignalData() {
fetch('/clear_signal_data', {
method: 'POST',
}).then(response => {
if (!response.ok) {
console.error('清空信号数据失败');
}
});
// 发送请求到后端清空信号数据
fetch('/clear_signal_data', { method: 'POST' })
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('信号数据已清空');
} else {
console.error('清空信号数据失败');
}
})
.catch(error => {
console.error('清空信号数据时发生错误:', error);
});
}
function exportToExcel() {
@ -242,20 +268,21 @@ function exportToExcel() {
data.push(['测试日期', testDate]);
data.push([]); // 空行
const headers = ['设备序列号', '测试结果'];
const headers = ['设备序列号', '测试结果', '合格时间'];
data.push(headers);
for (let i = 1; i < table.rows.length; i++) {
const row = table.rows[i];
const serialNumber = row.cells[0].querySelector('input').value;
const testResult = row.cells[1].querySelector('input').checked ? '合格' : '不合格';
data.push([serialNumber, testResult]);
const passTime = row.cells[2].querySelector('.pass-time').textContent;
data.push([serialNumber, testResult, passTime]);
}
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet(data);
const colWidth = [{ wch: 20 }, { wch: 20 }];
const colWidth = [{ wch: 20 }, { wch: 10 }, { wch: 20 }];
ws['!cols'] = colWidth;
XLSX.utils.book_append_sheet(wb, ws, "测试结果");
@ -405,5 +432,5 @@ document.addEventListener('DOMContentLoaded', function() {
updateDeviceTypeDisplay();
// 每100毫秒更新一次灯光状态
setInterval(updateLights, 100);
setInterval(updateLights, 300);
});

View File

@ -64,8 +64,8 @@ body {
}
.light.emergency_stop.on {
background-color: #007bff; /* 蓝色 */
box-shadow: 0 0 20px 5px rgba(0, 123, 255, 0.5);
background-color: #9d002c; /* 深红色 */
box-shadow: 0 0 20px 5px rgba(157, 0, 44, 0.5);
}
.light.up.on {

View File

@ -119,10 +119,6 @@
<div class="light common off" id="common-4"></div>
<p>公共灯</p>
</div>
<div class="light-item">
<div class="light emergency_stop off" id="emergency_stop-4"></div>
<p>急停灯</p>
</div>
<div class="light-item">
<div class="light up off" id="up-4"></div>
<p>上行灯</p>
@ -131,6 +127,10 @@
<div class="light down off" id="down-4"></div>
<p>下行灯</p>
</div>
<div class="light-item">
<div class="light emergency_stop off" id="emergency_stop-4"></div>
<p>急停灯</p>
</div>
</div>
</div>
</div>
@ -195,6 +195,7 @@
<tr>
<th>设备序列号</th>
<th>测试结果</th>
<th>合格时间</th>
<th>操作</th>
</tr>
</thead>
@ -211,6 +212,7 @@
</label>
</div>
</td>
<td><span class="pass-time"></span></td>
<td><button class="btn btn-primary add-row-btn" onclick="addNewRow(this)">增加下一条</button></td>
</tr>
</tbody>