From 2ed288830f753cabe6a85c6804a3e8aae1e9342f Mon Sep 17 00:00:00 2001 From: DingZQ Date: Thu, 14 Aug 2025 19:59:20 +0800 Subject: [PATCH 1/5] Update influxdb token --- influxdb_info.py | 2 +- setup_server.md | 4 ++-- simulation.py | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/influxdb_info.py b/influxdb_info.py index 186a11b..cd6700b 100644 --- a/influxdb_info.py +++ b/influxdb_info.py @@ -1,7 +1,7 @@ # influxdb数据库连接信息 url = "http://localhost:8086" # 替换为你的InfluxDB实例地址 -token = "Vq8F5tzxqmjH6JYPBP5xqwo6nJbzRqCnahlcoMVyZGMPm3H92swD08VX-5lTH1laN_JG1x7EZ80WOQoycanmBw==" # 替换为你的InfluxDB Token +token = "LsqvuqtBqtBv44z_CWh5bWfn9hs1QKcYu5kWahF_cdF6JyqtwuUxU5CK7HWP7BOtP5_2f5mjx76qXyuPLOHWdw==" # 替换为你的InfluxDB Token # _ENCODED_TOKEN = "eEdETTVSWnFSSkF1ekFHUy1vdFhVZEMyTkZkWTc1cUpBalJMcUFCNHA1V2NJSUFsSVVwT3BUOF95QTE2QU9IbUpXZXJ3UV8wOGd3Yjg0c3k0MmpuWlE9PQ==" # token = base64.b64decode(_ENCODED_TOKEN).decode("utf-8") org = "TJWATERORG" # 替换为你的Organization名称 diff --git a/setup_server.md b/setup_server.md index b7fac3a..2c5a8f1 100644 --- a/setup_server.md +++ b/setup_server.md @@ -51,12 +51,12 @@ Password Tjwater@123456 Organizatio TJWATEORG Bucket TJWATERBUCKET -API Token : cpuAmRnJqSMd7F34q1VjG6JgwZfO0S0w0vK2ZmAvA6zvf6m-6UAobUKSW3xhGr_nxZI5HsFlpfZHT1i8sI3LyQ== +API Token : LsqvuqtBqtBv44z_CWh5bWfn9hs1QKcYu5kWahF_cdF6JyqtwuUxU5CK7HWP7BOtP5_2f5mjx76qXyuPLOHWdw== influx config create --config-name onboarding ` --host-url "http://localhost:8086" ` --org "TJWATERORG" ` - --token "cpuAmRnJqSMd7F34q1VjG6JgwZfO0S0w0vK2ZmAvA6zvf6m-6UAobUKSW3xhGr_nxZI5HsFlpfZHT1i8sI3LyQ==" ` + --token "LsqvuqtBqtBv44z_CWh5bWfn9hs1QKcYu5kWahF_cdF6JyqtwuUxU5CK7HWP7BOtP5_2f5mjx76qXyuPLOHWdw==" --active diff --git a/simulation.py b/simulation.py index 88847b7..6d6efff 100644 --- a/simulation.py +++ b/simulation.py @@ -593,6 +593,9 @@ def run_simulation(name: str, simulation_type: str, modify_pattern_start_time: s # 打开数据库 open_project(name_c) dic_time = get_time(name_c) + + print(dic_time) + # 获取水力模拟步长,如’0:15:00‘ globals.hydraulic_timestep = dic_time['HYDRAULIC TIMESTEP'] # 将时间字符串转换为 timedelta 对象 From 065bcded8e3625951ef15ccb011bbf39e2fa0ef6 Mon Sep 17 00:00:00 2001 From: DingZQ Date: Thu, 14 Aug 2025 20:19:50 +0800 Subject: [PATCH 2/5] Update document for time format --- setup_server.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup_server.md b/setup_server.md index 2c5a8f1..23bd4e1 100644 --- a/setup_server.md +++ b/setup_server.md @@ -83,6 +83,8 @@ Setup instructions for WMH's work (4)submit_risk_probability_result (5)pressure_sensor_placement_sensitivity +6. In times table, all time values should be the format "hh:mm::ss" + NOTES: 1. SCADA设备的时候,单位要转换,现在模拟算出来的单位是L/s,SCADA数据是m3/h,L/s要乘3.6才是m3/h 2. 之前的SCADA压力应该转过了,SCADA数据的单位是MPa,要乘以100才是m \ No newline at end of file From 40f3ae02fb949841738c5705eae9fd5183d73f8b Mon Sep 17 00:00:00 2001 From: DingZQ Date: Fri, 15 Aug 2025 14:49:22 +0800 Subject: [PATCH 3/5] Remove logger: --- main.py | 85 ++------------------------------------------------------- 1 file changed, 2 insertions(+), 83 deletions(-) diff --git a/main.py b/main.py index 4997ace..1c3f61d 100644 --- a/main.py +++ b/main.py @@ -144,44 +144,6 @@ redis_client = redis.Redis(host="localhost", port=6379, db=0) # influx_org_name = influxdb_info.org # influx_client = InfluxDBClient(url=influx_url, token=influx_token, org=influx_org_name, timeout=100*1000) # 100 seconds -def setup_logger(): - # 创建日志目录 - log_dir = "logs" - os.makedirs(log_dir, exist_ok=True) - - # 配置基础日志格式 - log_format = "%(asctime)s - %(levelname)s - %(message)s" - formatter = logging.Formatter(log_format) - - # 创建主 Logger - logger = logging.getLogger() - logger.setLevel(logging.INFO) # 全局日志级别 - - # --- 1. 按日期分割的日志文件 Handler --- - log_file = os.path.join(log_dir, "fastapi.log") - file_handler = TimedRotatingFileHandler( - filename=log_file, - when="midnight", # 每天午夜轮转 - interval=1, - backupCount=7, - encoding="utf-8" - ) - file_handler.suffix = "fastapi-%Y-%m-%d.log" # 文件名格式 - file_handler.setFormatter(formatter) - file_handler.setLevel(logging.INFO) # 文件记录所有级别日志 - - # --- 2. 控制台实时输出 Handler --- - console_handler = logging.StreamHandler() # 默认输出到 sys.stderr (控制台) - console_handler.setFormatter(formatter) - console_handler.setLevel(logging.INFO) # 控制台仅显示 INFO 及以上级别 - - # 将 Handler 添加到 Logger - logger.addHandler(file_handler) - # logger.addHandler(console_handler) - - return logger - -logger = setup_logger() # 配置 CORS 中间件 app.add_middleware( @@ -208,51 +170,8 @@ async def receive_with_body(body: bytes) -> Receive: return receive -@app.middleware("http") -async def log_requests(request: Request, call_next): - if request.url.path == "/favicon.ico": - return Response(status_code=204) - - # 记录接收请求的时间 - request_time = time.time() - request_time_str = datetime.fromtimestamp(request_time).strftime('%Y-%m-%d %H:%M:%S') - - # 判断是否为文件上传 - is_file_upload = request.headers.get("content-type", "").startswith("multipart/form-data") - - # 记录接收的请求数据 - logger.info(f"Received request: {request.method} {request.url} at {request_time_str}") - if not is_file_upload: - request_body = await request.body() - logger.info(f"Request body: {request_body.decode('utf-8')}") - - # 创建新的 Request 对象,传递缓存的请求体 - receive = await receive_with_body(request_body) - request = Request(request.scope, receive=receive) - else: - logger.info(f"Request body: File") - - # 处理请求 - response = await call_next(request) - - # 记录发送响应的时间 - response_time = time.time() - response_time_str = datetime.fromtimestamp(response_time).strftime('%Y-%m-%d %H:%M:%S') - processing_time = response_time - request_time - - # 记录发送的响应数据 - # response_body = b"" - # async for chunk in response.body_iterator: - # response_body += chunk - - # 记录响应的状态码以及是否成功 - success_status = response.status_code < 400 - logger.info(f"Response status: {response.status_code} at {response_time_str}, success: {success_status}") - # logging.info(f"Response body: {response_body.decode('utf-8')}") - logger.info(f"Processing time: {processing_time:.3f} seconds") - - return response - +logger = logging.getLogger() +logger.setLevel(logging.INFO) @app.on_event("startup") async def startup_db(): From 3b1a4b4b9506952cc8b9d73284ca505672eb7363 Mon Sep 17 00:00:00 2001 From: DingZQ Date: Fri, 15 Aug 2025 14:50:58 +0800 Subject: [PATCH 4/5] Refine --- main.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/main.py b/main.py index 1c3f61d..2160a98 100644 --- a/main.py +++ b/main.py @@ -159,17 +159,6 @@ lock_simulation = Value('i', 0) app.add_middleware(GZipMiddleware, minimum_size=1000) - -async def receive_with_body(body: bytes) -> Receive: - async def receive() -> dict: - return { - "type": "http.request", - "body": body, - "more_body": False, - } - return receive - - logger = logging.getLogger() logger.setLevel(logging.INFO) From 92e21227437712e6d70ace877350b8b059d8aab8 Mon Sep 17 00:00:00 2001 From: DingZQ Date: Fri, 15 Aug 2025 14:59:36 +0800 Subject: [PATCH 5/5] Refine --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 2160a98..946fd32 100644 --- a/main.py +++ b/main.py @@ -2823,8 +2823,9 @@ async def fastapi_run_simulation_manually_by_date(data: Run_Simulation_Manually_ thread.start() # thread.join() - matched_keys = redis_client.keys(f"*{item['simulation_date']}*") - redis_client.delete(*matched_keys) + # DingZQ 08152025 + # matched_keys = redis_client.keys(f"*{item['simulation_date']}*") + # redis_client.delete(*matched_keys) ############################################################