algorithms.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from fastapi import APIRouter, Request
  2. from loguru import logger
  3. from app.controllers.algorithms.graph_coloring import get_graph_coloring
  4. from app.controllers.algorithms.meeting_attendee_recommendation import (
  5. build_recommendations,
  6. )
  7. from app.models.domain.algorithms import (
  8. AttendeesRecommendationRequest,
  9. AttendeesRecommendationResponse,
  10. )
  11. from app.models.domain.algorithms import GraphColoringRequest, GraphColoringResponse
  12. router = APIRouter()
  13. @router.get("/status")
  14. async def get_living_condition():
  15. return {"message": "alive"}
  16. @router.get("/app")
  17. def read_main(request: Request):
  18. return {"message": "Hello World", "root_path": request.scope.get("root_path")}
  19. @router.post("/graph-coloring", response_model=GraphColoringResponse)
  20. async def get_graph_coloring_result(graph: GraphColoringRequest):
  21. is_solvable, colored = await get_graph_coloring(graph.graph)
  22. solution = {"is_solvable": is_solvable, "colored": colored}
  23. return solution
  24. @router.post(
  25. "/attendees-recommendation", response_model=AttendeesRecommendationResponse
  26. )
  27. async def get_recommended(meeting_info: AttendeesRecommendationRequest):
  28. try:
  29. res = await build_recommendations(
  30. meeting_info.companyId, meeting_info.initiatorId
  31. )
  32. except Exception as e:
  33. logger.error(e)
  34. return {"code": 500, "message": "Recommend failure."}
  35. else:
  36. return {"code": 200, "message": "success", "data": {"userIdList": res}}