events.prisma 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. model AdClickEvents {
  2. id String @id @map("_id") @default(auto()) @db.ObjectId
  3. uid String // 设备码(from JWT / device)
  4. adId String @db.ObjectId // 广告 ID
  5. adType String // 广告类型 (BANNER/STARTUP/...)
  6. clickedAt BigInt // 点击时间 (epoch)
  7. ip String // 点击 IP
  8. createAt BigInt // 记录创建时间
  9. updateAt BigInt // 记录更新时间
  10. // Query helpers
  11. // 1. 查某广告的点击列表
  12. @@index([adId, clickedAt])
  13. // 2. 查某设备的点击轨迹
  14. @@index([uid, clickedAt])
  15. // 3. 按广告类型/时间分析
  16. @@index([adType, clickedAt])
  17. // 4. 全局按时间片
  18. @@index([clickedAt])
  19. @@map("adClickEvents")
  20. }
  21. model VideoClickEvents {
  22. id String @id @map("_id") @default(auto()) @db.ObjectId
  23. uid String // 设备码
  24. videoId String @db.ObjectId // 视频 ID
  25. clickedAt BigInt // 点击时间 (epoch)
  26. ip String // 点击 IP
  27. createAt BigInt // 记录创建时间
  28. updateAt BigInt // 记录更新时间
  29. // Query helpers
  30. // 1. 查某视频的点击
  31. @@index([videoId, clickedAt])
  32. // 2. 查设备点击
  33. @@index([uid, clickedAt])
  34. // 3. 全局时间窗口
  35. @@index([clickedAt])
  36. @@map("videoClickEvents")
  37. }
  38. model AdImpressionEvents {
  39. id String @id @map("_id") @default(auto()) @db.ObjectId
  40. uid String // 设备码
  41. adId String @db.ObjectId // 广告 ID
  42. adType String // 广告类型 (BANNER/STARTUP/...)
  43. impressionAt BigInt // 曝光时间 (epoch)
  44. visibleDurationMs BigInt? // 可见时长(毫秒,optional)
  45. ip String // IP
  46. createAt BigInt // 记录创建时间
  47. updateAt BigInt // 记录更新时间
  48. // Query helpers
  49. // 1. 按广告查看曝光
  50. @@index([adId, impressionAt])
  51. // 2. 设备曝光轨迹
  52. @@index([uid, impressionAt])
  53. // 3. 按广告类型
  54. @@index([adType, impressionAt])
  55. // 4. 时间片
  56. @@index([impressionAt])
  57. @@map("adImpressionEvents")
  58. }
  59. model ProcessedMessage {
  60. id String @id @map("_id") @default(auto()) @db.ObjectId
  61. messageId String @unique // 去重用的唯一消息 ID
  62. eventType String // 事件类型(如 stats.ad.click)
  63. processedAt BigInt // 处理时间(epoch ms)
  64. createdAt BigInt // 创建时间(epoch ms)
  65. @@map("processedMessages")
  66. }
  67. model VideoGlobalStats {
  68. id String @id @map("_id") @default(auto()) @db.ObjectId
  69. videoId String @unique @db.ObjectId // 视频 ID(唯一)
  70. impressions BigInt @default(0) // 曝光总数
  71. clicks BigInt @default(0) // 点击总数
  72. firstSeenAt BigInt // 首次出现时间 (epoch)
  73. lastSeenAt BigInt // 最后活跃时间 (epoch)
  74. computedCtr Float @default(0) // 计算的点击率 (clicks/impressions)
  75. computedPopularity Float @default(0) // 计算的热度得分
  76. computedRecency Float @default(0) // 计算的时效性得分
  77. computedScore Float @default(0) // 综合得分
  78. createAt BigInt // 创建时间 (epoch)
  79. updateAt BigInt // 更新时间 (epoch)
  80. // Query helpers
  81. // 1. videoId has unique index via @unique
  82. // 2. 按综合得分排序(热门视频推荐)
  83. @@index([computedScore])
  84. // 3. 按时效性排序(最新热点)
  85. @@index([computedRecency, computedScore])
  86. // 4. 按点击率排序(高转化内容)
  87. @@index([computedCtr])
  88. // 5. 按最后活跃时间排序
  89. @@index([lastSeenAt])
  90. @@map("videoGlobalStats")
  91. }
  92. model AdsGlobalStats {
  93. id String @id @map("_id") @default(auto()) @db.ObjectId
  94. adId String @unique @db.ObjectId // 广告 ID(唯一)
  95. impressions BigInt @default(0) // 曝光总数
  96. clicks BigInt @default(0) // 点击总数
  97. firstSeenAt BigInt // 首次出现时间 (epoch)
  98. lastSeenAt BigInt // 最后活跃时间 (epoch)
  99. computedCtr Float @default(0) // 计算的点击率 (clicks/impressions)
  100. computedPopularity Float @default(0) // 计算的热度得分
  101. computedRecency Float @default(0) // 计算的时效性得分
  102. computedScore Float @default(0) // 综合得分
  103. createAt BigInt // 创建时间 (epoch)
  104. updateAt BigInt // 更新时间 (epoch)
  105. // Query helpers
  106. // 1. adId has unique index via @unique
  107. // 2. 按综合得分排序(热门广告推荐)
  108. @@index([computedScore])
  109. // 3. 按时效性排序(最新热点)
  110. @@index([computedRecency, computedScore])
  111. // 4. 按点击率排序(高转化广告)
  112. @@index([computedCtr])
  113. // 5. 按最后活跃时间排序
  114. @@index([lastSeenAt])
  115. @@map("adsGlobalStats")
  116. }