import random from copy import deepcopy import requests from LSZXBackend.general import * from LSZXNetWork.lszx_network import * video_path = os.path.join(GLOBAL_DIR, "LSZXVideo", "Video") # 模拟大屏数据 class BaseStation: def __init__(self): self.ip = '127.0.0.1' self.situp = {'count': 0, 'time': time.time(), 'name': '人员1', 'id': 1, 'hr': 85, 'bo': 92, 'normal': True, 'h_time': time.time()} self.pullup = {'count': 0, 'time': time.time(), 'name': '人员2', 'id': 2, 'hr': 85, 'bo': 92, 'normal': True, 'h_time': time.time()} self.runaround = {'count': 0.0, 'time': time.time(), 'name': '人员3', 'id': 3, 'hr': 85, 'bo': 92, 'normal': True, 'h_time': time.time()} self.pushup = {'count': 0, 'time': time.time(), 'name': '人员4', 'id': 4, 'hr': 85, 'bo': 92, 'normal': True, 'h_time': time.time()} self.running = [] self.finish_num = 0 threading.Thread(target=self.running_info).start() self.fake_info = {SITUP: self.situp, PULLUP: self.pullup, PUSHUP: self.pushup, RUNAROUND: self.runaround, RUNNING: self.running, 'time': time.time()} self.server = Server(ip="0.0.0.0", port=server_port, file_port=server_file_port, cache_path=video_path) self.client = Client(ip="0.0.0.0") threading.Thread(target=self.send_info).start() def send_info(self): while True: try: this_time = time.time() if this_time - self.situp['time'] >= 1.2: self.situp['count'] += 1 if this_time - self.situp['h_time'] > 5: self.situp['hr'] = random.randint(72, 132) self.situp['bo'] = random.randint(88, 97) self.situp['h_time'] = this_time self.situp['time'] = this_time if this_time - self.pullup['time'] >= 1.8: self.pullup['count'] += 1 if this_time - self.pullup['h_time'] > 5: self.pullup['hr'] = random.randint(72, 132) self.pullup['bo'] = random.randint(88, 97) self.pullup['h_time'] = this_time self.pullup['time'] = this_time if this_time - self.pushup['time'] > 1.5: self.pushup['count'] += 1 if this_time - self.pushup['h_time'] > 5: self.pushup['hr'] = random.randint(72, 132) self.pushup['bo'] = random.randint(88, 97) self.pushup['h_time'] = this_time self.pushup['time'] = this_time self.runaround['count'] = this_time - self.runaround['time'] if this_time - self.runaround['h_time'] > 5: self.runaround['hr'] = random.randint(72, 132) self.runaround['bo'] = random.randint(88, 97) self.runaround['h_time'] = this_time if self.situp['count'] == 89: self.situp['count'] = 0 if self.pullup['count'] == 17: self.pullup['count'] = 0 if self.pushup['count'] == 67: self.pushup['count'] = 0 if self.runaround['count'] > 25: self.runaround['count'] = 0 self.runaround['time'] = this_time for i in self.running: count = this_time - i['time'] if i['finish'] != '已完成': i['count'] = count if count > i['c_time']: i['round'] += 1 i['c_time'] = i['c_time'] + 240 if count > i['final_time']: i['finish'] = '已完成' self.finish_num += 1 if this_time - i['h_time'] > 5: i['hr'] = random.randint(72, 132) i['bo'] = random.randint(88, 97) i['h_time'] = this_time if self.finish_num >= 10: self.finish_num = 0 threading.Thread(target=self.running_info).start() self.fake_info['time'] = this_time broadcast_pkg = { DATA: self.fake_info, 'ip': self.ip } print(broadcast_pkg) address_list = [] pkg_list = [] address_list.append((self.ip, server_port)) pkg_list.append([{'data': broadcast_pkg, 'data_type': 'totals_data'}]) self.client.distributed_send(address_list, pkg_list) time.sleep(0.4) except: print(traceback.format_exc()) def running_info(self): try: self.running = [] _rank = [random.randint(720, 800) for _ in range(10)] _rank.sort() rank_list = deepcopy(_rank) while len(self.running) < 10: try: rank = random.choice(_rank) self.running.append({ 'id': len(self.running) + 5, 'name': '人员' + str(len(self.running) + 1), 'hr': 85, 'bo': 92, 'count': 0.0, 'time': time.time(), 'normal': True, 'round': 0, 'finish': '已开始', 'rank': rank_list.index(rank) + 1, 'final_time': rank, 'c_time': rank / 3, 'h_time': time.time() }) _rank.remove(rank) except IndexError: break self.fake_info = {SITUP: self.situp, PULLUP: self.pullup, PUSHUP: self.pushup, RUNAROUND: self.runaround, RUNNING: self.running, 'time': time.time()} except: print(traceback.format_exc()) if __name__ == '__main__': basestation = BaseStation()