renyupeng 1 سال پیش
والد
کامیت
bcb7a6e116
1فایلهای تغییر یافته به همراه73 افزوده شده و 8 حذف شده
  1. 73 8
      Apietl/kwai_etl/Q4Task/AppKuaishouVideoList.py

+ 73 - 8
Apietl/kwai_etl/Q4Task/AppKuaishouVideoList.py

@@ -20,10 +20,11 @@ class AppKuaishouVideoList:
 
     def execSql(self):
         try:
-            sql = """select account_id from media_api.kuaishou_video_list where  date_format(stat_date, '%Y-%m-%d') >= date_sub('{date_time}', INTERVAL 13 DAY)
-              group by account_id """.format(date_time=self.date_time)
-            account_list = TidbConn.quary(self.conn, sql)
-            for account_id in account_list:
+            sql = """select account_id from `jeecg-boot`.ctop_user_allocation where  account_status=0 and media_id=2""".format(date_time=self.date_time)
+            cur = self.conn.cursor()
+            cur.execute(sql)
+            result = cur.fetchall()
+            for account_id in result:
                 try:
                     sql = """
             replace into application.app_kuaishou_video_list
@@ -160,12 +161,77 @@ class AppKuaishouVideoList:
                   group by code, tag_category_id, tag_category_name, parent_id, parent_name) m
                  on v.signature = m.code
                      left join (
-                                select signature,effect_date as stat_date from application.effect_material where media_id =2
-
+                select stat_date, signature, sum
+                from (
+                         select stat_date, signature, sum, row_number() over (partition by signature order by sum) as rn
+                         from (
+                                  select stat_date,
+                                         signature,
+                                         sum(cost) over (partition by signature order by stat_date) as sum
+                                  from (
+                                           select rep.stat_date, video.signature, cost
+                                           from (select photo_id, signature, stat_date
+                                                 from (select photo_id,
+                                                              stat_date,
+                                                              signature,
+                                                              row_number() over (partition by photo_id order by stat_date) rn
+                                                       from media_api.kuaishou_video_list
+                                                       where photo_id is not null
+                                                         and photo_id != 0 and account_id ={account_id}
+                                                         and date_format(stat_date, '%Y-%m-%d') >=
+                                                             date_sub('{date_time}', INTERVAL 6 DAY)
+                                                       group by photo_id, signature) s
+                                                 where rn = 1) video
+                                                    left join
+                                                (
+                                                    select stat_date, photo_id, sum(charge) as cost
+                                                    from media_api.kuaishou_material_video_report_daily
+                                                    where photo_id is not null
+                                                      and photo_id != 0 and advertiser_id ={account_id}
+                                                    group by stat_date, photo_id
+                                                ) rep
+                                                on video.photo_id = rep.photo_id
+                                           where rep.stat_date between date_format(video.stat_date, '%Y%m%d') and date_format(date_add(video.stat_date, INTERVAL 6 DAY), '%Y%m%d')) t) t
+                         where sum >= 5000
+                     ) t
+                where rn = 1
             ) effect
                                on effect.signature = v.signature
                      left join (
-           select signature,hot_date as stat_date from application.hot_material where media_id =2
+                select stat_date, signature, sum
+                from (
+                         select stat_date, signature, sum, row_number() over (partition by signature order by sum) as rn
+                         from (
+                                  select stat_date,
+                                         signature,
+                                         sum(cost) over (partition by signature order by stat_date) as sum
+                                  from (
+                                           select rep.stat_date, video.signature, cost
+                                           from (select photo_id, signature, stat_date
+                                                 from (select photo_id,
+                                                              stat_date,
+                                                              signature,
+                                                              row_number() over (partition by photo_id order by stat_date) rn
+                                                       from media_api.kuaishou_video_list
+                                                       where photo_id is not null 
+                                                         and photo_id != 0 and account_id ={account_id}
+                                                         and date_format(stat_date, '%Y-%m-%d') >=
+                                                             date_sub('{date_time}', INTERVAL 13 DAY)
+                                                       group by photo_id, signature) s
+                                                 where rn = 1) video
+                                                    left join
+                                                (
+                                                    select stat_date, photo_id, sum(charge) as cost
+                                                    from media_api.kuaishou_material_video_report_daily
+                                                    where photo_id is not null and advertiser_id ={account_id}
+                                                      and photo_id != 0
+                                                    group by stat_date, photo_id
+                                                ) rep
+                                                on video.photo_id = rep.photo_id
+                                           where rep.stat_date between date_format(video.stat_date, '%Y%m%d') and date_format(date_add(video.stat_date, INTERVAL 13 DAY), '%Y%m%d')) t) t
+                         where sum >= 50000
+                     ) t
+                where rn = 1
             ) hot
                                on hot.signature = v.signature
             group by account_id, photo_id, v.stat_date, v.signature, tag_category_id, parent_id, tag_code
@@ -175,7 +241,6 @@ class AppKuaishouVideoList:
                     self.conn.commit()
                 except Exception as e:
                     logging.error(e)
-                    return -1
             TidbConn.conn_close(conn=self.conn)
             return 0
         except Exception as e: