194 lines
7.5 KiB
Python
194 lines
7.5 KiB
Python
# coding: gb2312
|
|
import json
|
|
import os
|
|
import time
|
|
import traceback
|
|
|
|
from AcrossPlatform.get_platform import GLOBAL_DIR
|
|
from DeviceDefine.consensus import *
|
|
from LogRecord.log_recorder import GLOBAL_LOG
|
|
from PureBackend.base_driver import BaseDriver, MODEL_MEDIAPIPE
|
|
from PureBackend.general import *
|
|
|
|
|
|
# 训练难度
|
|
difficulty_lookup = {
|
|
DIFFICULT_HARD: "比武难度", DIFFICULT_EASY: "考核难度", COMMON_EASY: "普通难度"
|
|
}
|
|
# 动作标准
|
|
standards_lookup = {
|
|
STANDARDS_NEW: "新式动作标准", STANDARDS_OLD: "旧式动作标准"
|
|
}
|
|
DIFFICULT_FILE = os.path.join(GLOBAL_DIR, "train_info.json")
|
|
SUMMARY_FILE = os.path.join(GLOBAL_DIR, "summary_info.json")
|
|
DIFFICULTY_MES = "difficulty_mes"
|
|
DIFFICULTY_DIS = "difficulty_display"
|
|
DIFFICULTY = "difficulty"
|
|
STANDARDS_DIS = "standards_display"
|
|
STANDARDS = "standards"
|
|
|
|
|
|
class StandardManager(BaseDriver):
|
|
|
|
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)
|
|
# 管理难度
|
|
# 生成初始化动作难度与标准json文件
|
|
if not os.path.exists(DIFFICULT_FILE):
|
|
self.train_info = {
|
|
DIFFICULTY_DIS: difficulty_lookup[DIFFICULT_HARD],
|
|
DIFFICULTY: DIFFICULT_HARD,
|
|
STANDARDS_DIS: standards_lookup[STANDARDS_OLD],
|
|
STANDARDS: STANDARDS_OLD,
|
|
}
|
|
try:
|
|
with open(DIFFICULT_FILE, "w+", encoding='utf-8_sig') as f:
|
|
json.dump(self.train_info, f, ensure_ascii=False)
|
|
except:
|
|
pass
|
|
else:
|
|
try:
|
|
with open(DIFFICULT_FILE, "r", encoding='utf-8_sig') as f:
|
|
self.train_info = json.load(f)
|
|
except:
|
|
pass
|
|
|
|
# 汇总分析
|
|
if not os.path.exists(SUMMARY_FILE):
|
|
batch = self.manager.get_this_batch()
|
|
if not batch:
|
|
this_time = int(time.time())
|
|
batch = time.strftime("%Y年%m月%d日%H时", time.localtime(this_time))
|
|
self.summary_info = {
|
|
'batch': batch,
|
|
'default_projects': {SITUP: '仰卧起坐', RUNAROUND: '30*2蛇形跑', PULLUP: '引体向上',
|
|
RUNNING: '长跑'},
|
|
'default_batch': batch,
|
|
'default_class_projects': {RUNNING: '长跑'},
|
|
'default_class_batch': batch,
|
|
'default_group_projects': {RUNNING: '长跑'},
|
|
'default_team_project': {RUNNING: '长跑'},
|
|
'default_team_batch': batch,
|
|
'default_team_class': ['1班'],
|
|
'default_personal_projects': {SITUP: '仰卧起坐', RUNAROUND: '30*2蛇形跑', PULLUP: '引体向上',
|
|
RUNNING: '长跑'},
|
|
'default_personal_batch': [batch],
|
|
'default_personal_personal': {'id': 1, 'name': '人员1'}
|
|
}
|
|
try:
|
|
with open(SUMMARY_FILE, "w+", encoding='utf-8_sig') as f:
|
|
json.dump(self.summary_info, f, ensure_ascii=False)
|
|
except:
|
|
pass
|
|
else:
|
|
try:
|
|
with open(SUMMARY_FILE, "r", encoding='utf-8_sig') as f:
|
|
self.summary_info = json.load(f)
|
|
batch = self.manager.get_this_batch()
|
|
if batch:
|
|
self.summary_info['batch'] = self.manager.get_this_batch()
|
|
except:
|
|
batch = self.manager.get_this_batch()
|
|
if not batch:
|
|
this_time = int(time.time())
|
|
batch = time.strftime("%Y年%m月%d日%H时", time.localtime(this_time))
|
|
self.summary_info = {
|
|
'batch': batch,
|
|
'default_projects': {SITUP: '仰卧起坐', RUNAROUND: '30*2蛇形跑', PULLUP: '引体向上',
|
|
RUNNING: '长跑'},
|
|
'default_batch': batch,
|
|
'default_class_projects': {RUNNING: '长跑'},
|
|
'default_class_batch': batch,
|
|
'default_group_projects': {RUNNING: '长跑'},
|
|
'default_team_project': {RUNNING: '长跑'},
|
|
'default_team_batch': batch,
|
|
'default_team_class': ['1班'],
|
|
'default_personal_projects': {SITUP: '仰卧起坐', RUNAROUND: '30*2蛇形跑',
|
|
PULLUP: '引体向上',
|
|
RUNNING: '长跑'},
|
|
'default_personal_batch': [batch],
|
|
'default_personal_personal': {'id': 1, 'name': '人员1'}
|
|
}
|
|
|
|
# 更新汇总信息json
|
|
def update_summary_info(self):
|
|
try:
|
|
with open(SUMMARY_FILE, "w", encoding='utf-8_sig') as f:
|
|
json.dump(self.summary_info, f, ensure_ascii=False)
|
|
return True
|
|
except Exception as e:
|
|
GLOBAL_LOG.write(f"发生错误,{str(e)},错误来源:{traceback.format_exc()}")
|
|
return False
|
|
|
|
# 读取当前考核批次GET
|
|
def get_batch(self):
|
|
try:
|
|
batch = self.summary_info['batch']
|
|
return batch
|
|
except Exception as e:
|
|
GLOBAL_LOG.write(f"发生错误,{str(e)},错误来源:{traceback.format_exc()}")
|
|
|
|
# 生成新的考核批次GET
|
|
def set_batch(self):
|
|
try:
|
|
batch = self.manager.generate_batch()
|
|
self.summary_info['batch'] = batch
|
|
return batch
|
|
except Exception as e:
|
|
GLOBAL_LOG.write(f"发生错误,{str(e)},错误来源:{traceback.format_exc()}")
|
|
|
|
# 获得动作标准
|
|
def get_train_info(self):
|
|
try:
|
|
with open(DIFFICULT_FILE, 'r', encoding='utf-8_sig') as read_json:
|
|
self.train_info = json.load(read_json)
|
|
except:
|
|
if os.path.exists(DIFFICULT_FILE):
|
|
os.remove(DIFFICULT_FILE)
|
|
self.train_info = {
|
|
DIFFICULTY_DIS: difficulty_lookup[DIFFICULT_HARD],
|
|
DIFFICULTY: DIFFICULT_HARD,
|
|
STANDARDS_DIS: standards_lookup[STANDARDS_OLD],
|
|
STANDARDS: STANDARDS_OLD,
|
|
}
|
|
with open(DIFFICULT_FILE, "w+", encoding='utf-8_sig') as f:
|
|
json.dump(self.train_info, f, ensure_ascii=False)
|
|
return self.train_info
|
|
|
|
# 设置动作标准
|
|
def set_train_info(self, train_info):
|
|
try:
|
|
difficulty = train_info.get(DIFFICULTY)
|
|
standards = train_info.get(STANDARDS)
|
|
if not difficulty or not standards:
|
|
return
|
|
self.train_info = {
|
|
DIFFICULTY_DIS: difficulty_lookup[difficulty],
|
|
DIFFICULTY: difficulty,
|
|
STANDARDS_DIS: standards_lookup[standards],
|
|
STANDARDS: standards
|
|
}
|
|
with open(DIFFICULT_FILE, "w+", encoding='utf-8_sig') as f:
|
|
json.dump(self.train_info, f, ensure_ascii=False)
|
|
return True
|
|
except:
|
|
print(traceback.format_exc())
|
|
return False
|
|
|
|
# 获得所有的难度
|
|
@staticmethod
|
|
def get_all_difficulty():
|
|
return [
|
|
{"value": value, "label": label}
|
|
for value, label in difficulty_lookup.items()
|
|
]
|
|
|
|
# 获得所有的标准
|
|
@staticmethod
|
|
def get_all_standard():
|
|
return [
|
|
{"value": value, "label": label}
|
|
for value, label in standards_lookup.items()
|
|
]
|