Advertisement
YuvalGai

Untitled

Sep 8th, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. SELECT
  2. match_end_date AS INTERVAL_DATE,
  3. case
  4. when current_arena_index <= 13 then 'Studios'
  5. when current_arena_index <= 22 then 'Master Ranks'
  6. else 'Legends League'
  7. End as arena_group,
  8. case
  9. when current_arena_index <= 22 then current_arena_index
  10. else 100
  11. end current_arena_index,
  12. CASE
  13. WHEN trophies_cnt < 1500 THEN '0-1500'
  14. WHEN trophies_cnt < 3800 THEN '1500-3800'
  15. WHEN trophies_cnt < 8000 THEN '3800-8000'
  16. WHEN trophies_cnt < 17000 THEN '8000-17000'
  17. WHEN trophies_cnt < 30000 THEN '17000-30000'
  18. ELSE '30000+'
  19. END AS trophy_group,
  20. daily_p.PAYERS_SEGMENT,
  21. calendar.LO_ENTRY_IS_PREMIUM_PASS_EXCLUSIVE,
  22. pvp_mode,
  23. MATCH_TYPE_ID,
  24. case
  25. when pvp_mode = 'Rumble' then 'Rumble'
  26. when calendar_entry_id like '%onboarding%' then 'Onboarding'
  27. when PVP_MODE = 'Solo' then 'Solo'
  28. when PVP_MODE = 'Showdown' then 'Showdown'
  29. when calendar_entry_id like '%adventure%' then 'Adventure'
  30. when match_sub_type = 'boosters-clash-friendly' then 'Booster Clash'
  31. when match_sub_type = 'score-race' then 'Leaderboard'
  32. when is_random_mixer = TRUE then 'Random Mixer'
  33. else MATCH_TYPE
  34. end match_type,
  35. MATCH_MODE,
  36. MODIFIER_1,
  37. MODIFIER_2,
  38. match_modifier_3,
  39. RESOURCE_SUB_TYPE,
  40. BOOSTER_NAME,
  41. RIVAL_RESOURCE_SUB_TYPE,
  42. RUMBLE_SIZE,
  43. CASE
  44. WHEN PVP_MODE In ('Solo','Rumble') THEN 'No Rival(Solo/Rumble)'
  45. ELSE RIVAL_BOOSTER_NAME
  46. END RIVAL_BOOSTER_NAME,
  47. rounds_cnt,
  48. is_private,
  49. is_rival_bot,
  50. turn_index,
  51. app_version,
  52. CASE
  53. when LO_EVENT_ID like '%-mc-%' then 'MC'
  54. when LO_EVENT_ID like '%cosmic%' then 'cosmic'
  55. when LO_EVENT_ID like '%rally%' then 'rally'
  56. when LO_EVENT_ID like '%heist%' then 'heist'
  57. end Solo_Type,
  58. ifnull(stakes_multiplier,1) as stakes_multiplier,
  59. match_end_date as last_updated_dt,
  60. current_timestamp() as dw_insert_dt,
  61. SUM(ROUNDS_CNT) AS ROUNDS,
  62. SUM(MATCH_SCORE) AS MATCH_SCORE,
  63. SUM(MATCH_DURATION_SEC) / 60 AS MATCH_DURATION_MINS,
  64. SUM(ABILITY_ACTIVATED_CNT) AS BOOSTER_ACTIVATIONS,
  65. SUM(ifnull(CS_RESYNCS, 0)) AS RESYNCS,
  66. COUNT(
  67. DISTINCT CASE
  68. WHEN CS_RESYNCS > 0 THEN concat(match_id, match.user_id, rematch_cnt)
  69. END
  70. ) AS RESYNC_MATCHES,
  71. SUM(ifnull(ERROR_RESYNCS, 0)) AS ERROR_RESYNCS,
  72. COUNT(
  73. DISTINCT CASE
  74. WHEN ERROR_RESYNCS > 0 THEN concat(match_id, match.user_id, rematch_cnt)
  75. END
  76. ) AS ERROR_RESYNC_MATCHES,
  77. SUM(
  78. CASE
  79. WHEN is_conceded = 1
  80. AND is_won = 0
  81. AND match_duration_sec = 0 THEN 1
  82. END
  83. ) AS CONCEDED_MATCHES,
  84. SUM(
  85. CASE
  86. WHEN is_conceded = 1
  87. AND is_won = 0
  88. AND match_duration_sec BETWEEN 1
  89. AND 10 THEN 1
  90. END
  91. ) AS CONCEDED_MATCHES_1_10,
  92. SUM(
  93. CASE
  94. WHEN is_conceded = 1
  95. AND is_won = 0
  96. AND match_duration_sec BETWEEN 10
  97. AND 60 THEN 1
  98. END
  99. ) AS CONCEDED_MATCHES_10_60,
  100. SUM(
  101. CASE
  102. WHEN is_conceded = 1
  103. AND is_won = 0
  104. AND match_duration_sec > 60 THEN 1
  105. END
  106. ) AS CONCEDED_MATCHES_AFTER_60sec,
  107. SUM(ifnull(rival_played_out_of_time, 0)) AS OOT,
  108. COUNT(
  109. DISTINCT CASE
  110. WHEN rival_played_out_of_time > 0 THEN concat(match_id, match.user_id, rematch_cnt)
  111. END
  112. ) AS OOT_MATCHES,
  113. COUNT(DISTINCT concat(match_id, match.user_id, rematch_cnt)) AS MATCHES,
  114. SUM(is_won) AS wins,
  115. AVG(MATCH_RANK) AS AVG_MATCH_RANK,
  116. sum(is_rival_bot) AS agianst_bot_MATCHES,
  117. sum(MATCH_DURATION_SEC) as total_seconds_played_in_segment,
  118. sum(ability_activated_cnt) as total_booster_activations_in_segment,
  119. sum(four_matched_cnt) as total_fours,
  120. sum(five_matched_cnt) as total_fives,
  121. sum(rshaped_matched_cnt) as total_rshaped,
  122. sum(square_shapes_cnt) as total_square_shaped,
  123. sum(extra_moves_cnt) as total_extra_moves,
  124. sum(match_making_found_time) as match_making_found_time
  125. FROM
  126. MATCH_MASTERS.PROD.F_USER_MATCH match
  127. LEFT JOIN (
  128. SELECT
  129. *
  130. FROM
  131. (
  132. SELECT
  133. *
  134. ,CASE
  135. WHEN lo_entry_ts IS NULL THEN lo_entry_update_ts
  136. ELSE lo_entry_ts
  137. END lo_entry_ts2,
  138. ROW_NUMBER() OVER (
  139. partition BY lo_entry_id
  140. ORDER BY
  141. lo_entry_ts2 DESC
  142. ) rn
  143. FROM
  144. MATCH_MASTERS.PROD.F_LIVEOPS_CALENDAR
  145. where 1=1
  146. and derived_tstamp >= current_date - 91
  147. )
  148. WHERE
  149. rn = 1
  150. ) calendar on match.calendar_entry_id = calendar.lo_entry_id
  151. left join
  152. (select user_id,interval_date,payers_segment from MATCH_MASTERS.prod.daily_users_from_params where interval_date >= current_date - 91) daily_p
  153. on match.user_id = daily_p.user_id and match.match_end_date = daily_p.interval_date
  154. WHERE
  155. is_bot = FALSE
  156. AND MATCH_END_DATE >= current_date - 91
  157. GROUP BY ALL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement