AccountDailyReport.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/9/27 10:50 上午
  4. # @Site :
  5. # @File : AccountDailyReport.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import logging
  10. from math import ceil
  11. from Apietl.kwai_etl.report.ReplaceAccountInfo import ReplaceAccountInfo
  12. from Apietl.utlis.Logger import Logger
  13. from Apietl.utlis.Utils import Utils
  14. from Apietl.conn.TidbConn import TidbConn
  15. class AccountDailyReport:
  16. def __init__(self):
  17. self.conn = TidbConn.get_connection()
  18. self.parm = Utils.get_args()
  19. self.start_time = self.parm[0]
  20. self.end_time = self.parm[1]
  21. def daily_report(self):
  22. ReplaceAccountInfo.handler()
  23. try:
  24. sql = """select count(1) from media_api.kuaishou_account_report_daily where
  25. stat_date between {start_time} and {end_time}""".format(
  26. start_time=self.start_time, end_time=self.end_time)
  27. totalNum = TidbConn.quary(sql)[0][0]
  28. pageCount = ceil(totalNum / 20000)
  29. for i in range(pageCount):
  30. sql = """
  31. replace into application.kuaishou_account_report_daily_dw
  32. (account_id, stat_date, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
  33. company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
  34. play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
  35. cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
  36. event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
  37. event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
  38. event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
  39. event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
  40. event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
  41. event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
  42. event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
  43. event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
  44. event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
  45. play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
  46. event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
  47. event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
  48. event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
  49. event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
  50. event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
  51. event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
  52. event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
  53. event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
  54. union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
  55. key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
  56. event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
  57. ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
  58. event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
  59. event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
  60. event_outbound_call_ratio, event_ad_watch_times)
  61. select report.advertiser_id as account_id,
  62. stat_date,
  63. project_id,
  64. product_id,
  65. sys.advertiser_id,
  66. company_id,
  67. account_name,
  68. project_name,
  69. advertiser_name,
  70. company_name,
  71. sale_id,
  72. user_id,
  73. org_code,
  74. charge,
  75. `show`,
  76. photo_click,
  77. aclick,
  78. bclick,
  79. photo_click_ratio,
  80. play_3s_ratio,
  81. action_ratio,
  82. impression_1k_cost,
  83. photo_click_cost,
  84. action_cost,
  85. share,
  86. comment,
  87. `like`,
  88. follow,
  89. cancel_follow,
  90. report,
  91. block,
  92. negative,
  93. submit,
  94. download_started,
  95. download_completed,
  96. activation,
  97. event_pay_first_day,
  98. event_pay_purchase_amount_first_day,
  99. event_pay_first_day_roi,
  100. event_pay,
  101. event_pay_purchase_amount,
  102. event_pay_roi,
  103. event_register,
  104. event_register_cost,
  105. event_register_ratio,
  106. event_jin_jian_app,
  107. event_jin_jian_app_cost,
  108. event_credit_grant_app,
  109. event_credit_grant_app_cost,
  110. event_credit_grant_app_ratio,
  111. event_order_paid,
  112. event_order_paid_purchase_amount,
  113. event_order_paid_cost,
  114. event_next_day_stay,
  115. event_next_day_stay_cost,
  116. event_next_day_stay_ratio,
  117. form_count,
  118. form_cost,
  119. form_action_ratio,
  120. event_jin_jian_landing_page,
  121. event_jin_jian_landing_page_cost,
  122. event_credit_grant_landing_page,
  123. event_credit_grant_landing_page_cost,
  124. event_credit_grant_landing_page_ratio,
  125. event_valid_clues,
  126. event_valid_clues_cost,
  127. event_add_wechat,
  128. event_add_wechat_cost,
  129. event_add_wechat_ratio,
  130. event_get_through,
  131. event_get_through_cost,
  132. event_get_through_ratio,
  133. event_app_invoked,
  134. event_app_invoked_cost,
  135. event_app_invoked_ratio,
  136. event_credit_grant_landing_ratio,
  137. play_5s_ratio,
  138. play_end_ratio,
  139. event_new_user_pay,
  140. event_new_user_pay_cost,
  141. event_new_user_pay_ratio,
  142. click_1k_cost,
  143. ad_product_cnt,
  144. event_goods_view,
  145. merchant_reco_fans,
  146. event_order_amount_roi,
  147. event_goods_view_cost,
  148. merchant_reco_fans_cost,
  149. event_button_click,
  150. event_button_click_cost,
  151. event_button_click_ratio,
  152. event_order_paid_roi,
  153. event_new_user_jinjian_app,
  154. event_new_user_jinjian_app_cost,
  155. event_new_user_jinjian_app_roi,
  156. event_new_user_credit_grant_app,
  157. event_new_user_credit_grant_app_cost,
  158. event_new_user_credit_grant_app_roi,
  159. event_new_user_jinjian_page,
  160. event_new_user_jinjian_page_cost,
  161. event_new_user_jinjian_page_roi,
  162. event_new_user_credit_grant_page,
  163. event_new_user_credit_grant_page_cost,
  164. event_new_user_credit_grant_page_roi,
  165. event_appoint_form,
  166. event_appoint_form_cost,
  167. event_appoint_form_ratio,
  168. event_appoint_jump_click,
  169. event_appoint_jump_click_cost,
  170. event_appoint_jump_click_ratio,
  171. union_event_pay_purchase_amount_7d,
  172. union_event_pay_purchase_amount_7d_roi,
  173. placement_type,
  174. ad_scene,
  175. event_order_successed,
  176. ad_photo_played_10s_ratio,
  177. key_action_cost,
  178. event_add_shopping_cart_cost,
  179. event_ad_watch_times_ratio,
  180. event_outbound_call_cost,
  181. event_outbound_call,
  182. action_new_ratio,
  183. event_watch_app_ad,
  184. event_multi_conversion_cost,
  185. event_phone_card_activate,
  186. ad_photo_played_75percent_ratio,
  187. key_action_ratio,
  188. event_ad_watch_times_cost,
  189. event_add_shopping_cart,
  190. key_action,
  191. event_multi_conversion,
  192. event_wechat_connected,
  193. event_dsp_gift_form,
  194. event_intention_confirmed,
  195. event_phone_get_through,
  196. event_multi_conversion_ratio,
  197. event_measurement_house,
  198. ad_photo_played_2s_ratio,
  199. event_outbound_call_ratio,
  200. event_ad_watch_times
  201. from media_api.kuaishou_account_report_daily report
  202. left join
  203. `jeecg-boot`.ctop_account_attribution_info sys
  204. on report.advertiser_id = sys.account_id
  205. where report.stat_date between {start_time} and {end_time}
  206. order by account_id,stat_date limit {num},20000
  207. """.format(start_time=self.start_time, end_time=self.end_time,num=i * 20000)
  208. print(sql)
  209. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  210. self.conn.commit()
  211. TidbConn.conn_close(conn=self.conn)
  212. return 0
  213. except Exception as e:
  214. logging.error(e)
  215. return -1
  216. if __name__ == '__main__':
  217. status = AccountDailyReport().daily_report()
  218. if status == 0:
  219. print("作业执行成功")
  220. exit(0)
  221. else:
  222. print("作业执行失败")
  223. exit(-1)