From f10b9fac7f28b248b68f178770eaca04598d812e Mon Sep 17 00:00:00 2001 From: JIANG Date: Mon, 22 Dec 2025 10:33:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_server.py | 2 +- timescaledb/schemas/scheme.py | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/run_server.py b/run_server.py index 8f7d80d..958ce34 100644 --- a/run_server.py +++ b/run_server.py @@ -13,6 +13,6 @@ if __name__ == "__main__": "main:app", host="0.0.0.0", port=8000, - # workers=2, # 这里可以设置多进程 + workers=2, # 这里可以设置多进程 loop="asyncio", ) diff --git a/timescaledb/schemas/scheme.py b/timescaledb/schemas/scheme.py index 205f6c9..54e170b 100644 --- a/timescaledb/schemas/scheme.py +++ b/timescaledb/schemas/scheme.py @@ -160,7 +160,9 @@ class SchemeRepository: query, (scheme_type, scheme_name, start_time, end_time, link_id) ) rows = await cur.fetchall() - return [{"time": row["time"].isoformat(), "value": row[field]} for row in rows] + return [ + {"time": row["time"].isoformat(), "value": row[field]} for row in rows + ] @staticmethod async def get_links_field_by_scheme_and_time_range( @@ -194,10 +196,9 @@ class SchemeRepository: rows = await cur.fetchall() result = defaultdict(list) for row in rows: - result[row["id"]].append({ - "time": row["time"].isoformat(), - "value": row[field] - }) + result[row["id"]].append( + {"time": row["time"].isoformat(), "value": row[field]} + ) return dict(result) @staticmethod @@ -375,7 +376,9 @@ class SchemeRepository: query, (scheme_type, scheme_name, start_time, end_time, node_id) ) rows = await cur.fetchall() - return [{"time": row["time"].isoformat(), "value": row[field]} for row in rows] + return [ + {"time": row["time"].isoformat(), "value": row[field]} for row in rows + ] @staticmethod async def get_nodes_field_by_scheme_and_time_range( @@ -400,10 +403,9 @@ class SchemeRepository: rows = await cur.fetchall() result = defaultdict(list) for row in rows: - result[row["id"]].append({ - "time": row["time"].isoformat(), - "value": row[field] - }) + result[row["id"]].append( + {"time": row["time"].isoformat(), "value": row[field]} + ) return dict(result) @staticmethod @@ -695,7 +697,12 @@ class SchemeRepository: raise ValueError(f"Invalid type: {type}. Must be 'node' or 'link'") # Format the results - return [{"ID": item["id"], "value": item["value"]} for item in data] + # Format the results + result = [] + for id, items in data.items(): + for item in items: + result.append({"ID": id, "value": item["value"]}) + return result @staticmethod async def query_scheme_simulation_result_by_id_time(