events.prisma 6.5 KB

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