7 Commits 65d9bebaa4 ... 1421a0ba8e

Author SHA1 Message Date
  chenhaiyang 1421a0ba8e set root_path by command line 1 year ago
  chenhaiyang ab4c636086 set root_path by command line 1 year ago
  chenhaiyang 377e951fd0 fix a bug 1 year ago
  chenhaiyang 57616ffc0d optimized the Dockerfile 1 year ago
  chenhaiyang 52fbb6dbd6 delete the requirement of build-essential 1 year ago
  chenhaiyang cc8047344c pip install use aliyun source 1 year ago
  chenhaiyang a59cb5fb75 fix a bug 1 year ago
4 changed files with 15 additions and 11 deletions
  1. 5 6
      Dockerfile
  2. 7 2
      app/api/routers/algorithms.py
  3. 2 2
      app/api/routers/devices.py
  4. 1 1
      app/main.py

+ 5 - 6
Dockerfile

@@ -1,4 +1,4 @@
-FROM python:3.10-slim
+FROM python:3.10
 
 WORKDIR /code
 
@@ -6,14 +6,13 @@ COPY ./requirements.txt /code/requirements.txt
 COPY ./app /code/app
 COPY .env_pro /code/.env
 
-RUN apt-get update && apt-get install -y --no-install-recommends \
-    build-essential && \
-    pip install --no-cache-dir --upgrade -r /code/requirements.txt && \
-    mkdir -p /code/ml_models
+RUN pip install --upgrade pip -i  https://mirrors.aliyun.com/pypi/simple/
+RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
+RUN mkdir -p /code/ml_models
 
 ENV PYTHONPATH=/code
 ENV TZ=Asia/Shanghai
 
 EXPOSE 8002
 
-CMD ["uvicorn", "app.main:app", "--log-level", "info", "--host", "0.0.0.0", "--port", "8002"]
+CMD ["uvicorn", "app.main:app", "--root-path", "/env-py", "--log-level", "info", "--host", "0.0.0.0", "--port", "8002"]

+ 7 - 2
app/api/routers/algorithms.py

@@ -1,15 +1,15 @@
-from fastapi import APIRouter
+from fastapi import APIRouter, Request
 from loguru import logger
 
 from app.controllers.algorithms.graph_coloring import get_graph_coloring
 from app.controllers.algorithms.meeting_attendee_recommendation import (
     build_recommendations,
 )
-from app.models.domain.algorithms import GraphColoringRequest, GraphColoringResponse
 from app.models.domain.algorithms import (
     AttendeesRecommendationRequest,
     AttendeesRecommendationResponse,
 )
+from app.models.domain.algorithms import GraphColoringRequest, GraphColoringResponse
 
 router = APIRouter()
 
@@ -19,6 +19,11 @@ async def get_living_condition():
     return {"message": "alive"}
 
 
+@router.get("/app")
+def read_main(request: Request):
+    return {"message": "Hello World", "root_path": request.scope.get("root_path")}
+
+
 @router.post("/graph-coloring", response_model=GraphColoringResponse)
 async def get_graph_coloring_result(graph: GraphColoringRequest):
     is_solvable, colored = await get_graph_coloring(graph.graph)

+ 2 - 2
app/api/routers/devices.py

@@ -243,12 +243,12 @@ async def get_acatvi_mode(params: domain_devices.ACATVIModeRequest):
     return {"mode": new_mode}
 
 
-@router.post("/instructions/acatvi/early-start", response_model=domain_devices.ACATVIEarlyStartPredictionResponse)
+@router.post("/prediction/acatvi/early-start", response_model=domain_devices.ACATVIEarlyStartPredictionResponse)
 async def get_acatvi_early_start_prediction(
         params: domain_devices.ACATVIEarlyStartPredictionRequest,
         db: Session = Depends(get_db)
 ):
-    minutes = build_acatvi_early_start_prediction(params, db)
+    minutes = await build_acatvi_early_start_prediction(params, db)
 
     logger.info(params)
     logger.info(f"{params.space_id} - {minutes}")

+ 1 - 1
app/main.py

@@ -27,7 +27,7 @@ logging.getLogger().handlers = [InterceptHandler()]
 
 
 def get_application() -> FastAPI:
-    application = FastAPI(title=settings.PROJECT_NAME, root_path="/env-py")
+    application = FastAPI(title=settings.PROJECT_NAME)
 
     application.add_event_handler("startup", create_start_app_handler())