浏览代码

MOD:修改素材展示归因

cxyu 3 年之前
父节点
当前提交
15da0d17d7
共有 2 个文件被更改,包括 32 次插入22 次删除
  1. 27 19
      app/etl/MaterialLibrary/MaterialDataClean.py
  2. 5 3
      app/etl/dw/dw_image_cost_day.py

+ 27 - 19
app/etl/MaterialLibrary/MaterialDataClean.py

@@ -45,7 +45,6 @@ def description():
 
     df = db.dm.pd_data_sql(sql)
 
-    # print(df)
 
     df["data_type"] = 'all'
     df['type'] = '2'
@@ -59,7 +58,6 @@ def description():
 
 
 def image():
-
     sql = """select signature,sum(consume_amount) consume_amount,
             sum(click_times) click_times,
             sum(view_times) view_times,
@@ -76,7 +74,8 @@ def image():
             min(media_format) media_format,
             min(video_length) video_length,
             min(video_bit_rate) video_bit_rate,
-            0 max_media_size 
+            0 max_media_size,
+            min(width)/if(min(height),min(height),1) aspect_ratio
         from (select replace(signature,' ,','') as signature ,
             sum(cost) consume_amount,
             sum(click_count) click_times,
@@ -88,9 +87,9 @@ def image():
             replace (min(preview_url),' ,','') as content,
             if(is_video=1,2,1) type,  
             if(locate(',',signature)>0,0,1) single_img,
-            min(replace(if(left (width ,2)='0,',substring(width ,3),width) ,',0','')) width ,
-			min(replace(if(left (height ,2)='0,',substring(height ,3),height) ,',0','')) height,
-			min(replace(if(left (size ,2)='0,',substring(size ,3),size) ,',0','')) media_size ,
+            min(width) width ,
+			min(height) height,
+			min(replace(if(left (size ,2)='0,',substring(size ,3),size) ,',0','')) media_size,
             min(replace(format ,' ,','')) media_format,
             min(video_length) video_length,
             min(video_bit_rate) video_bit_rate
@@ -112,7 +111,7 @@ def image():
         max_size = 0
         for size_data in size_list:
             if size_data != 'None':
-                if float(size_data) > max_size:
+                if float(size_data) > float(max_size):
                     max_size = str(size_data)
         df['max_media_size'][i] = max_size
 
@@ -120,8 +119,11 @@ def image():
     df["data_type"] = 'all'
 
     key = ["signature"]
-    tag = ['media_size', 'media_format', 'video_length', 'video_bit_rate', 'use_times', "view_times", "click_times", "novels", "start_date", "end_date", "create_by", "single_img",
-           "content", 'consume_amount', 'type', 'width', 'height']
+    tag = ['media_size', 'media_format', 'video_length', 'video_bit_rate',
+           'max_media_size', 'use_times', "view_times",
+           "click_times",
+           "novels", "start_date", "end_date", "create_by", "single_img",
+           "content", 'consume_amount', 'type', 'width', 'height', 'aspect_ratio']
     table = "t_ads_media"
 
     db.zx_ads.dfsave2mysql(df, table, key, tag)
@@ -140,13 +142,14 @@ min(media) media,
 min(channel) channel ,
 min(type) type,
 if(locate(',',signature)>0,0,1) single_img,
-min(width) width ,
+min(width) width,
 min(height) height,
 min(media_size) media_size ,
 min(media_format) media_format,
 min(video_length) video_length,
 min(video_bit_rate) video_bit_rate,
-0 max_media_size 
+0 max_media_size,
+min(width)/if(min(height),min(height),1) aspect_ratio
 from 
  (select replace(signature ,' ,','') as signature,title,description article,
 sum(click_count) click_times,
@@ -156,8 +159,8 @@ sum(cost) consume_amount,
 group_concat(distinct book) novels,
 min(dt) start_date,max(dt) end_date,
 min(replace(preview_url ,' ,','')) media,
-min(replace(if(left (width ,2)='0,',substring(width ,3),width) ,',0','')) width ,
-min(replace(if(left (height ,2)='0,',substring(height ,3),height) ,',0','')) height ,
+min(width) width ,
+min(height) height,
 min(replace(if(left (size ,2)='0,',substring(size ,3),size) ,',0','')) media_size ,
 min(replace(format ,' ,','')) media_format,
 min(video_length) video_length,
@@ -165,9 +168,10 @@ min(video_bit_rate) video_bit_rate,
 type channel,
 if(is_video=1,2,1) type,
 if(locate(',',signature)>0,0,1) single_img
-from dw_image_cost_day where signature is not null and signature!=''   
-GROUP BY  signature,title,description,type,is_video) as foo
-group by signature ,title,article  """
+from dw_image_cost_day where signature is not null and signature!='' 
+GROUP BY signature,title,description,type,is_video) as foo
+group by signature ,title ,article
+  """
 
     # df = db.dm.getData_pd(sql)
     df = db.dm.pd_data_sql(sql)
@@ -179,14 +183,15 @@ group by signature ,title,article  """
         max_size = 0
         for size_data in size_list:
             if size_data != 'None':
-                if float(size_data) > max_size:
+                if float(size_data) > float(max_size):
                     max_size = str(size_data)
         df['max_media_size'][i] = max_size
 
     key = ["signature", 'title', 'article']
-    tag = ['media_size', 'media_format', 'video_length', 'video_bit_rate', 'max_media_size', 'use_times', "view_times",
+    tag = ['media_size', 'media_format', 'video_length', 'video_bit_rate', 'max_media_size',
+           'use_times', "view_times",
            "click_times", "novels", "start_date", "end_date", "type", "channel",
-           'consume_amount', 'single_img', 'media', 'width', 'height']
+           'consume_amount', 'single_img', 'media', 'width', 'height', 'aspect_ratio']
     table = "t_ads_idea"
 
     db.zx_ads.dfsave2mysql(df, table, key, tag)
@@ -205,3 +210,6 @@ if __name__ == '__main__':
     # description()
     # image()
     # adcreative()
+
+
+

+ 5 - 3
app/etl/dw/dw_image_cost_day.py

@@ -78,8 +78,8 @@ def run(dt):
         i.append(preview_url[1:])
         i.append(signature[1:])
         i.append(0)
-        i.append(width[1:])
-        i.append(height[1:])
+        i.append(width)
+        i.append(height)
         i.append(size[1:])
         i.append(type[1:])
         i.append(video_length)
@@ -129,6 +129,8 @@ def day():
 if __name__ == '__main__':
     # run('2021-05-18')
 
-    for i in du.getDateLists(du.get_n_days(-3), du.get_n_days(0)):
+    for i in du.getDateLists(du.get_n_days(-10), du.get_n_days(0)):
         print(i)
         run(i)
+
+