diff --git a/infra/docker/Dockerfile b/Dockerfile similarity index 63% rename from infra/docker/Dockerfile rename to Dockerfile index 51571e0..b2358ce 100644 --- a/infra/docker/Dockerfile +++ b/Dockerfile @@ -9,9 +9,14 @@ RUN conda install -y -c conda-forge python=3.12 pymetis && \ COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt +# 将代码放入子目录 'app',将数据放入子目录 'db_inp' +# 这样临时文件默认会生成在 /app 下,而代码在 /app/app 下,实现了分离 COPY app ./app +COPY db_inp ./db_inp +COPY temp ./temp COPY .env . +# 设置 PYTHONPATH 以便 uvicorn 找到 app 模块 ENV PYTHONPATH=/app EXPOSE 8000 diff --git a/app/algorithms/simulations.py b/app/algorithms/simulations.py index 4eaa1cb..f7d86d9 100644 --- a/app/algorithms/simulations.py +++ b/app/algorithms/simulations.py @@ -509,7 +509,7 @@ def contaminant_simulation( # step 2. set pattern if source_pattern != None: pt = get_pattern(new_name, source_pattern) - if pt == None: + if len(pt) == 0: str_response = str("cant find source_pattern") return str_response else: diff --git a/app/api/v1/endpoints/simulation.py b/app/api/v1/endpoints/simulation.py index 82bf8b1..74168ff 100644 --- a/app/api/v1/endpoints/simulation.py +++ b/app/api/v1/endpoints/simulation.py @@ -115,7 +115,15 @@ class PressureSensorPlacement(BaseModel): def run_simulation_manually_by_date( network_name: str, base_date: datetime, start_time: str, duration: int ) -> None: - start_hour, start_minute, start_second = map(int, start_time.split(":")) + time_parts = list(map(int, start_time.split(":"))) + if len(time_parts) == 2: + start_hour, start_minute = time_parts + start_second = 0 + elif len(time_parts) == 3: + start_hour, start_minute, start_second = time_parts + else: + raise ValueError("Invalid start_time format. Use HH:MM or HH:MM:SS") + start_datetime = base_date.replace( hour=start_hour, minute=start_minute, second=start_second ) @@ -654,13 +662,9 @@ async def fastapi_run_simulation_manually_by_date( globals.realtime_region_pipe_flow_and_demand_id, ) base_date = datetime.strptime(item["simulation_date"], "%Y-%m-%d") - thread = threading.Thread( - target=lambda: run_simulation_manually_by_date( - item["name"], base_date, item["start_time"], item["duration"] - ) + run_simulation_manually_by_date( + item["name"], base_date, item["start_time"], item["duration"] ) - thread.start() - thread.join() return {"status": "success"} except Exception as exc: return {"status": "error", "message": str(exc)}