selection.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. from __future__ import annotations
  2. """候选筛选结果模型:RankedFlightCandidate与RankedHotelCandidate等经排序的候选。"""
  3. from typing import Any, Literal
  4. from pydantic import Field
  5. from app.schemas.common import AppModel
  6. class RankedFlightCandidate(AppModel):
  7. """经过确定性评分的单个航班候选。"""
  8. option_id: str
  9. score: float = Field(
  10. ge=0,
  11. le=100,
  12. )
  13. reasons: list[str] = Field(
  14. default_factory=list
  15. )
  16. warnings: list[str] = Field(
  17. default_factory=list
  18. )
  19. flight: dict[str, Any]
  20. class RoundTripOption(AppModel):
  21. """一个完整的往返航班组合。"""
  22. combination_id: str
  23. score: float = Field(
  24. ge=0,
  25. le=100,
  26. )
  27. # 返程查询返回的完整往返接口报价(不是去程+返程的加总)。
  28. quoted_price: float | None = None
  29. currency: str = "CNY"
  30. outbound: dict[str, Any]
  31. return_flight: dict[str, Any]
  32. reasons: list[str] = Field(
  33. default_factory=list
  34. )
  35. warnings: list[str] = Field(
  36. default_factory=list
  37. )
  38. class RankedHotelCandidate(AppModel):
  39. """经过确定性评分的酒店候选。"""
  40. hotel_id: str
  41. score: float = Field(
  42. ge=0,
  43. le=100,
  44. )
  45. reasons: list[str] = Field(
  46. default_factory=list
  47. )
  48. warnings: list[str] = Field(
  49. default_factory=list
  50. )
  51. hotel: dict[str, Any]
  52. class CandidateSelectionResult(AppModel):
  53. """航班和酒店候选筛选结果。"""
  54. flight_type: Literal[
  55. "one_way",
  56. "round_trip",
  57. ]
  58. # 往返搜索时,用于发起返程查询的去程候选。
  59. outbound_candidates: list[
  60. RankedFlightCandidate
  61. ] = Field(
  62. default_factory=list
  63. )
  64. # 单程旅行使用。
  65. one_way_options: list[
  66. RankedFlightCandidate
  67. ] = Field(
  68. default_factory=list
  69. )
  70. # 往返旅行使用。
  71. round_trip_options: list[
  72. RoundTripOption
  73. ] = Field(
  74. default_factory=list
  75. )
  76. hotels: list[
  77. RankedHotelCandidate
  78. ] = Field(
  79. default_factory=list
  80. )
  81. warnings: list[str] = Field(
  82. default_factory=list
  83. )