demand_popularity_stats.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from __future__ import annotations
  2. from datetime import datetime
  3. from decimal import Decimal
  4. from sqlalchemy import BigInteger, Integer, Numeric, String, UniqueConstraint, func
  5. from sqlalchemy.orm import Mapped, mapped_column
  6. from supply_infra.db.base import Base
  7. class DemandPopularityStats(Base):
  8. """需求分类热度统计表(六维 avg + count)。"""
  9. __tablename__ = "demand_popularity_stats"
  10. __table_args__ = (
  11. UniqueConstraint("demand_category_id", "biz_dt", name="uk_demand_category"),
  12. )
  13. id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
  14. demand_category_id: Mapped[int] = mapped_column(
  15. BigInteger, nullable=False, comment="需求分类ID"
  16. )
  17. demand_word_name: Mapped[str | None] = mapped_column(
  18. String(128), nullable=True, comment="需求词名称"
  19. )
  20. biz_dt: Mapped[str] = mapped_column(String(32), nullable=False, comment="日期")
  21. ext_pop_avg: Mapped[Decimal | None] = mapped_column(
  22. Numeric(12, 2), nullable=True, comment="外部热度-平均值"
  23. )
  24. ext_pop_count: Mapped[int] = mapped_column(
  25. Integer, nullable=False, default=0, comment="外部热度-出现数量"
  26. )
  27. plat_sust_pop_avg: Mapped[Decimal | None] = mapped_column(
  28. Numeric(12, 2), nullable=True, comment="平台持续热度-平均值"
  29. )
  30. plat_sust_pop_count: Mapped[int] = mapped_column(
  31. Integer, nullable=False, default=0, comment="平台持续热度-出现数量"
  32. )
  33. plat_ly_pop_avg: Mapped[Decimal | None] = mapped_column(
  34. Numeric(12, 2), nullable=True, comment="平台去年同期热度-平均值"
  35. )
  36. plat_ly_pop_count: Mapped[int] = mapped_column(
  37. Integer, nullable=False, default=0, comment="平台去年同期热度-出现数量"
  38. )
  39. recent_pop_avg: Mapped[Decimal | None] = mapped_column(
  40. Numeric(12, 2), nullable=True, comment="近期热度-平均值"
  41. )
  42. recent_pop_count: Mapped[int] = mapped_column(
  43. Integer, nullable=False, default=0, comment="近期热度-出现数量"
  44. )
  45. real_rov_7d_avg: Mapped[Decimal | None] = mapped_column(
  46. Numeric(12, 4), nullable=True, comment="近7日ROV相对全局diff-平均值"
  47. )
  48. real_rov_7d_count: Mapped[int] = mapped_column(
  49. Integer, nullable=False, default=0, comment="近7日ROV相对全局diff-出现数量"
  50. )
  51. real_vov_7d_avg: Mapped[Decimal | None] = mapped_column(
  52. Numeric(12, 4), nullable=True, comment="近7日VOV相对全局diff-平均值"
  53. )
  54. real_vov_7d_count: Mapped[int] = mapped_column(
  55. Integer, nullable=False, default=0, comment="近7日VOV相对全局diff-出现数量"
  56. )
  57. created_time: Mapped[datetime] = mapped_column(
  58. nullable=False,
  59. server_default=func.now(),
  60. comment="创建时间",
  61. )
  62. updated_time: Mapped[datetime] = mapped_column(
  63. nullable=False,
  64. server_default=func.now(),
  65. onupdate=func.now(),
  66. comment="更新时间",
  67. )