import os import threading import time import traceback import random import pandas as pd import requests from AcrossPlatform.get_platform import * MAX_HR = "max_hr" MIN_BO = "min_bo" HR = "hr" BO = "bo" class BaseStation: def __init__(self): self.send_information_signal = threading.Event() threading.Thread(target=self.send_fake_information).start() file_path = os.path.join(GLOBAL_DIR, 'BaseStation', 'PERSON.xlsx') sheet_name = 'PERSON' df = pd.read_excel(file_path, sheet_name=sheet_name) column_name = 'band_id' column_data = df[column_name].tolist() self.HrBo_info = {} for i in column_data: hr = 85 self.HrBo_info[i] = {'hr': {'hr': hr, 'color': 'G'}, 'bo': {'bo': "{:.2%}".format(94 / 100), 'color': 'G'}, 'normal': True, 'record_time': time.time()} self.ip = '127.0.0.1' # 获取hrbo信息 def get_information(self): while True: try: this_time = time.time() for k, v in self.HrBo_info.items(): if this_time - v['record_time'] > 15: hr = random.randint(72, 145) bo = random.randint(83, 97) v['record_time'] = this_time if 180 >= hr > 140: hr_c = 'Y' elif hr > 180: hr_c = 'R' else: hr_c = 'G' if 80 <= bo < 88: bo_c = 'Y' elif bo < 80: bo_c = 'R' else: bo_c = 'G' v['hr'] = {'hr': hr, 'color': hr_c} v['bo'] = {'bo': "{:.2%}".format(bo / 100), 'color': bo_c} time.sleep(0.5) except Exception as e: print(traceback.format_exc()) # 发送hrbo信息给管理端 def send_fake_information(self): while True: try: time.sleep(0.5) print(self.HrBo_info) broadcast_pkg = { "data": self.HrBo_info, 'ip': self.ip } try: requests.post(url=f"http://{self.ip}:{34567}/totals_HrBoInfo_server", json=broadcast_pkg, timeout=1) except: print(traceback.format_exc()) except Exception as e: print(traceback.format_exc()) if __name__ == '__main__': basestation = BaseStation() threading.Thread(target=basestation.get_information).start()