import requests import json import time from datetime import datetime def save_mysql_data(sensor_id,json_data,save_path): url = "http://47.106.222.181:25081/algorithm/oxygen/result/data_post" current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') payload = json.dumps({ "sensor_id": "X12345679S", "raw_file_path": save_path }) print("payload:",payload) headers = { 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) print(response.json()) def save_mysql_data_with_jpg(device_id,module_code,json_data,save_path,save_jpg_path): url = "http://47.106.222.181:25081/algorithm/oxygen/result/data_post" current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') payload = json.dumps({ "device_id": "d100000002", # "device_id": "d100000002", #机器人ID "module_code": module_code, #传感器ID "timestamp": current_time, "confidence": 0.99, #传感器输出结果 "result_data":json_data, # "result_data": { # "detection": "fall", # "position": { # "x": 125, # "y": 80, # "width": 50, # "height": 120 # }, # "duration": 3.5 # }, #需要替换 # "raw_ref": "/storage/raw/20250814/DEV-001/camera_001.mp4" "raw_ref": save_path, "pic_ref":save_jpg_path }) print("payload:",payload) headers = { 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) print(response.json()) def save_senser_mysql_data(device_id, module_code, json_data, save_path): # def save_senser_mysql_data(): url = "http://47.106.222.181:25081/elderly/health/data" current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') payload = json.dumps({ "elderly_id": 1, # 必选,关联老人ID "sensor_id": "X12345679S", # 必选,传感器设备ID "module_code": module_code, # 可选,算法模块编码 # "sensor_data_path": "http://47.106.222.181:25079/sftp-images/uploads/device_info/data/device_info/d80801000058/senser_001/20250826/20250826_09/20250826_09_33_01_d80801000058_senser_001.json", # 可选,传感器原始数据存储路径 "sensor_data_path": save_path, # 可选,传感器原始数据存储路径 "algorithm_data_path": "/processed/202508/oxygen_1005_1030.json", # 可选,算法处理数据存储路径 "data_time": current_time # 可选,数据采集时间,默认当前时间 }) print("payload:", payload) headers = { 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) print(response.json()) def test_main(): start_time = time.time() # 获取开始时间 save_path = "/d100000002/X12345681S/20251101/20251101_11/20251101_11_11_11_d100000002_X12345681S.json" json_data = {'heart_rate': 0, 'blood_oxygen': 0, 'micro_circulation': 0, 'fatigue_index': 0, 'systolic_pressure': 0, 'diastolic_pressure': 0, 'cardiac_output': 0} save_mysql_data("X11223366S",json_data,save_path) end_time = time.time() # 获取结束时间 # 计算耗时 duration = end_time - start_time print(f"Function 'save_mysql_data' took {duration} seconds to execute.") #0.668 秒 def test_main_jpg(): start_time = time.time() # 获取开始时间 json_data = { "detection": "fall", "position": { "x": 125, "y": 80, "width": 50, "height": 120 }, "duration": 3.5 } save_path = "/storage/raw/20250814/DEV-001/camera_001.mp4" save_jpg_path = "/storage/raw/20250814/DEV-001/camera_001.jpg" save_mysql_data_with_jpg("d80801000062", "A0001", json_data, save_path, save_jpg_path) end_time = time.time() # 获取结束时间 # 计算耗时 duration = end_time - start_time print(f"Function 'save_mysql_data' took {duration} seconds to execute.") #0.668 秒 def test_main_1(): start_time = time.time() # 获取开始时间 json_data = { "detection": "fall", "position": { "x": 125, "y": 80, "width": 50, "height": 120 }, "duration": 3.5 } save_path = "/storage/raw/20250814/DEV-001/camera_001.mp4" save_senser_mysql_data( "d100000002","A0001",json_data,save_path) end_time = time.time() # 获取结束时间 # 计算耗时 duration = end_time - start_time print(f"Function 'save_mysql_data' took {duration} seconds to execute.") #0.668 秒 if __name__ == "__main__": test_main() # test_main_jpg() # save_senser_mysql_data()