algorithms.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from fastapi import APIRouter
  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 GraphColoringRequest, GraphColoringResponse
  8. from app.models.domain.algorithms import (
  9. AttendeesRecommendationRequest,
  10. AttendeesRecommendationResponse,
  11. )
  12. router = APIRouter()
  13. @router.get("/status")
  14. async def get_living_condition():
  15. return {"message": "alive"}
  16. @router.post("/graph-coloring", response_model=GraphColoringResponse)
  17. async def get_graph_coloring_result(graph: GraphColoringRequest):
  18. is_solvable, colored = await get_graph_coloring(graph.graph)
  19. solution = {"is_solvable": is_solvable, "colored": colored}
  20. return solution
  21. @router.post(
  22. "/attendees-recommendation", response_model=AttendeesRecommendationResponse
  23. )
  24. async def get_recommended(meeting_info: AttendeesRecommendationRequest):
  25. try:
  26. res = await build_recommendations(
  27. meeting_info.companyId, meeting_info.initiatorId
  28. )
  29. except Exception as e:
  30. logger.error(e)
  31. return {"code": 500, "message": "Recommend failure."}
  32. else:
  33. return {"code": 200, "message": "success", "data": {"userIdList": res}}