renyupeng 3 anni fa
parent
commit
36410c1d39

+ 6 - 7
Apietl/kwai_etl/report/CampaignHourlyReport.py

@@ -23,12 +23,11 @@ class CampaignHourlyReport:
 
     def hourly_report(self):
         try:
-            sql = """select count(1) from media_api.kuaishou_campaign_report_hourly where 
-            stat_date between {start_time} and {end_time}""".format(
+            sql = """select advertiser_id from media_api.kuaishou_campaign_report_hourly where 
+            stat_date between {start_time} and {end_time} group by advertiser_id""".format(
                 start_time=self.start_time, end_time=self.end_time)
-            totalNum = TidbConn.quary(sql)[0][0]
-            pageCount = ceil(totalNum / 20000)
-            for i in range(pageCount):
+            account_list = TidbConn.quary(sql)
+            for account_id in account_list:
                 sql = """replace into application.kuaishou_campaign_report_hourly_dw
 (account_id, stat_date,`hour`, campaign_id, campaign_name, project_id, product_id, advertiser_id,
  company_id, account_name, project_name, advertiser_name, company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio, play_3s_ratio, action_ratio,
@@ -206,8 +205,8 @@ class CampaignHourlyReport:
                  left join
              `jeecg-boot`.ctop_account_attribution_info sys
              on report.advertiser_id = sys.account_id
-        where report.stat_date between {start_time} and {end_time} order by campaign_id,stat_date,`hour` limit {num},20000""". \
-                    format(start_time=self.start_time, end_time=self.end_time, num=i * 20000)
+        where report.stat_date between {start_time} and {end_time} and report.advertiser_id = {account_id}""". \
+                    format(start_time=self.start_time, end_time=self.end_time, account_id=account_id[0])
                 print(sql)
                 TidbConn.upsert(conn=self.conn, sql_buff=sql)
                 self.conn.commit()

+ 7 - 8
Apietl/kwai_etl/report/UnitHourlyReport.py

@@ -22,12 +22,11 @@ class UnitHourlyReport:
 
     def hourly_report(self):
         try:
-            sql = """select count(1) from media_api.kuaishou_unit_report_hourly where 
-            stat_date between {start_time} and {end_time}""".format(
+            sql = """select advertiser_id from media_api.kuaishou_unit_report_hourly where 
+            stat_date between {start_time} and {end_time} group by advertiser_id""".format(
                 start_time=self.start_time, end_time=self.end_time)
-            totalNum = TidbConn.quary(sql)[0][0]
-            pageCount = ceil(totalNum / 10000)
-            for i in range(pageCount):
+            account_list = TidbConn.quary(sql)
+            for account_id in account_list:
                 sql = """replace into application.kuaishou_unit_report_hourly_dw
 (account_id, stat_date,`hour`, campaign_id, campaign_name, unit_id, unit_name, project_id, product_id, advertiser_id,
  company_id, account_name, project_name, advertiser_name, company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio, play_3s_ratio, action_ratio,
@@ -207,8 +206,8 @@ class UnitHourlyReport:
                  left join
              `jeecg-boot`.ctop_account_attribution_info sys
              on report.advertiser_id = sys.account_id
-        where report.stat_date between {start_time} and {end_time} order by unit_id,hour,stat_date limit {num},10000""".\
-                    format(start_time=self.start_time, end_time=self.end_time,num=i * 10000)
+        where report.stat_date between {start_time} and {end_time} and report.advertiser_id={account_id}""". \
+                    format(start_time=self.start_time, end_time=self.end_time, account_id=account_id[0])
                 print(sql)
                 TidbConn.upsert(conn=self.conn, sql_buff=sql)
                 self.conn.commit()
@@ -226,4 +225,4 @@ if __name__ == '__main__':
         exit(0)
     else:
         print("作业执行失败")
-        exit(-1)
+        exit(-1)