events.prisma 6.1 KB

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