新增Dockerfile;修改simulations中部分参数格式判断

This commit is contained in:
2026-02-10 15:25:03 +08:00
parent a0987105dc
commit a472639b8a
3 changed files with 17 additions and 8 deletions

View File

@@ -9,9 +9,14 @@ RUN conda install -y -c conda-forge python=3.12 pymetis && \
COPY requirements.txt . COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# 将代码放入子目录 'app',将数据放入子目录 'db_inp'
# 这样临时文件默认会生成在 /app 下,而代码在 /app/app 下,实现了分离
COPY app ./app COPY app ./app
COPY db_inp ./db_inp
COPY temp ./temp
COPY .env . COPY .env .
# 设置 PYTHONPATH 以便 uvicorn 找到 app 模块
ENV PYTHONPATH=/app ENV PYTHONPATH=/app
EXPOSE 8000 EXPOSE 8000

View File

@@ -509,7 +509,7 @@ def contaminant_simulation(
# step 2. set pattern # step 2. set pattern
if source_pattern != None: if source_pattern != None:
pt = get_pattern(new_name, source_pattern) pt = get_pattern(new_name, source_pattern)
if pt == None: if len(pt) == 0:
str_response = str("cant find source_pattern") str_response = str("cant find source_pattern")
return str_response return str_response
else: else:

View File

@@ -115,7 +115,15 @@ class PressureSensorPlacement(BaseModel):
def run_simulation_manually_by_date( def run_simulation_manually_by_date(
network_name: str, base_date: datetime, start_time: str, duration: int network_name: str, base_date: datetime, start_time: str, duration: int
) -> None: ) -> 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( start_datetime = base_date.replace(
hour=start_hour, minute=start_minute, second=start_second 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, globals.realtime_region_pipe_flow_and_demand_id,
) )
base_date = datetime.strptime(item["simulation_date"], "%Y-%m-%d") base_date = datetime.strptime(item["simulation_date"], "%Y-%m-%d")
thread = threading.Thread( run_simulation_manually_by_date(
target=lambda: run_simulation_manually_by_date( item["name"], base_date, item["start_time"], item["duration"]
item["name"], base_date, item["start_time"], item["duration"]
)
) )
thread.start()
thread.join()
return {"status": "success"} return {"status": "success"}
except Exception as exc: except Exception as exc:
return {"status": "error", "message": str(exc)} return {"status": "error", "message": str(exc)}