LISHUZUOXUN_yangjiang/PureBackend/running_backend.py

179 lines
6.6 KiB
Python

# coding: gb2312
import time
import traceback
import Exercise3.running_muwb_pure_detection
import Exercise3.running_muwb_with_rssi
from DeviceDefine.consensus import *
from PureBackend.general import RUNNING
from LogRecord.log_recorder import GLOBAL_LOG
from PureBackend.base_driver import MODEL_MEDIAPIPE
from PureBackend.exam_driver import ExamDriver
class RunningBackend(ExamDriver):
def __init__(self, master_mode=True, positioning=True, camera=True, model=MODEL_MEDIAPIPE, speaker=True,
multi_positioning_mode=True, device_type=UNKNOWN, pure_mode=False):
super().__init__(master_mode, positioning, camera, model, speaker, multi_positioning_mode, device_type, pure_mode)
# 开启多基站长跑模式
def running_master_mode(self):
self.running_mes.clear()
try:
if self.multi_positioning_mode:
self.running = Exercise3.running_muwb_with_rssi.Running(positioning=self.positioning)
else:
self.running = Exercise3.running_muwb_pure_detection.Running(positioning=self.positioning)
coordinates_data = {
"master": [
[0, 0, "主机"]
for _ in range(len(self.positioning.multi_uwb.uwb_driver_table))
],
"slaver": []
}
self.speak_driver.add_speak("基站识别成功,请检查基站数量!")
return coordinates_data
except Exception as e:
GLOBAL_LOG.write(f"开启多基站长跑模式出现错误,错误原因:{e.args}, {traceback.format_exc()}")
# 设置长跑的圈时圈数
def set_running_config(self, round_num, min_round_time):
try:
self.running.set_config(round_num, min_round_time)
return True
except Exception as e:
GLOBAL_LOG.write(f"设置长跑的圈时圈数出现错误,错误原因:{e.args}, {traceback.format_exc()}")
return False
# 重设长跑数据
def running_reset(self):
try:
self.running_mes.clear()
self.running.reset()
return True
except Exception as e:
GLOBAL_LOG.write(f"重设长跑数据出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
return False
# 长跑增加一个手环
def running_set_bands(self, ids):
try:
self.running_mes = {}
self.running.reset()
test_person_name = []
for person_id in ids:
person_mes = self.manager.select_a_person(person_id)
band_id = person_mes[0]["band_id"]
if not band_id:
if person_mes:
GLOBAL_LOG.write(f"{person_mes[0]['name']}未链接到人员信息!")
return False
else:
GLOBAL_LOG.write(f"找不到人员编号为<{person_id}>的信息!")
return False
self.running_mes[band_id] = person_mes[0]
self.running.add_tag(band_id)
self.running.add_tag_mes(band_id, person_mes[0])
test_person_name.append(person_mes[0]["name"])
return True
except Exception as e:
GLOBAL_LOG.write(f"长跑手环设置出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
return False
# 查看当前指定人员的圈时
def get_round_time(self, person_id):
try:
data = self.running.get_person_round_time(person_id)
result = []
time_counting = 0
if data:
for key, value in data.items():
time_counting += value
round_time = str(time.strftime("%H:%M:%S", time.gmtime(value)))
counting_round_time = str(time.strftime("%H:%M:%S", time.gmtime(time_counting)))
result.append({
"name": f"{key}圈用时",
"time": f"{round_time}({counting_round_time})",
"no": key
})
else:
result = []
result = sorted(result, key=lambda x: x["no"])
return result
except Exception as e:
GLOBAL_LOG.write(f"查看当前指定人员的圈时出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
# 获得所有考生详情
def get_running_all_score(self):
try:
data = self.running.get_all_score()
return data
except Exception as e:
GLOBAL_LOG.write(f"获得所有考生详情出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
# 修正指定考生成绩
def fix_score(self, person_id):
try:
self.running.fix_score(person_id)
return True
except Exception as e:
GLOBAL_LOG.write(f"修正指定考生成绩出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
return False
# 撤销修正指定考生成绩
def fix_withdraw(self, person_id):
try:
self.running.fix_withdraw(person_id)
return True
except Exception as e:
GLOBAL_LOG.write(f"撤销修正指定考生成绩出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
return False
# 长跑手环列表
def running_list(self):
try:
return list(self.running_mes.values())
except Exception as e:
GLOBAL_LOG.write(f"获得长跑手环列表出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
# 开始长跑
def start_running(self):
try:
self.running.start()
return True
except Exception as e:
GLOBAL_LOG.write(f"开始长跑出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
return False
# 设置是否进行语音播报
def voice_play(self, is_play):
try:
self.running.set_play(is_play)
return True
except Exception as e:
GLOBAL_LOG.write(f"设置是否进行语音播报出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
return False
# 结束长跑
def stop_running(self):
try:
self.synchronization_info[RUNNING] = []
self.send_score_signal.set()
if self.running:
self.running.stop()
return True
except Exception as e:
GLOBAL_LOG.write(f"结束长跑出现错误,错误原因:{e.args}, "
f"{traceback.format_exc()}")
return False