route.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from __future__ import annotations
  2. """路线评估结果模型:RouteLeg路线段与RouteEvaluationResult酒店位置评估。"""
  3. from typing import Any, Literal
  4. from pydantic import Field
  5. from app.schemas.common import AppModel
  6. RouteDataSource = Literal[
  7. "amap",
  8. "haversine_fallback",
  9. ]
  10. class RouteLeg(AppModel):
  11. """酒店与一个景点之间的距离结果。"""
  12. origin_name: str
  13. origin_location: str
  14. destination_name: str
  15. destination_location: str
  16. distance_meters: float = Field(ge=0)
  17. duration_seconds: float | None = Field(
  18. default=None,
  19. ge=0,
  20. )
  21. source: RouteDataSource = "amap"
  22. class HotelRouteEvaluation(AppModel):
  23. """综合酒店自身质量和真实位置后的评分结果。"""
  24. hotel_id: str
  25. hotel_name: str
  26. final_score: float = Field(
  27. ge=0,
  28. le=100,
  29. )
  30. base_hotel_score: float = Field(
  31. ge=0,
  32. le=100,
  33. )
  34. centrality_score: float = Field(
  35. ge=0,
  36. le=100,
  37. )
  38. subway_score: float = Field(
  39. ge=0,
  40. le=100,
  41. )
  42. average_distance_meters: float | None = None
  43. maximum_distance_meters: float | None = None
  44. average_duration_seconds: float | None = None
  45. nearest_subway_distance_meters: (
  46. float | None
  47. ) = None
  48. route_legs: list[RouteLeg] = Field(
  49. default_factory=list
  50. )
  51. reasons: list[str] = Field(
  52. default_factory=list
  53. )
  54. warnings: list[str] = Field(
  55. default_factory=list
  56. )
  57. hotel: dict[str, Any]
  58. class RouteEvaluationResult(AppModel):
  59. """路线评估阶段的最终结果。"""
  60. evaluated_hotels: list[
  61. HotelRouteEvaluation
  62. ] = Field(
  63. default_factory=list
  64. )
  65. reference_attractions: list[str] = Field(
  66. default_factory=list
  67. )
  68. selected_hotel_id: str | None = None
  69. distance_call_count: int = 0
  70. around_search_call_count: int = 0
  71. warnings: list[str] = Field(
  72. default_factory=list
  73. )