Kaynağa Gözat

MOD:广告素材-文案,添加格式

cxyu 3 yıl önce
ebeveyn
işleme
3cd3f03c18
1 değiştirilmiş dosya ile 16 ekleme ve 96 silme
  1. 16 96
      data_manage/public_analysis.py

+ 16 - 96
data_manage/public_analysis.py

@@ -822,7 +822,6 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
 
     db = MysqlUtils().dm
 
-
     sql = f'''
     select 
     campaign_id as id,
@@ -895,8 +894,7 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
     return data
 
 
-def content_rank(user_id, start, end, page, page_size, order, order_by, book, channel, is_singleimg,
-                 is_video, data_type, campaign_ids):
+def content_rank(user_id, start, end, page, page_size, order, order_by, book, channel,  data_type, campaign_ids):
     # TODO:修改为clickhouse来进行数据访问
 
     # 时间的归因-----获取到所有这段时间内的记录,并进行聚合(聚合周末再做,先把数据拿出来)
@@ -914,8 +912,6 @@ def content_rank(user_id, start, end, page, page_size, order, order_by, book, ch
     op4 = f" and channel='{channel}'" if channel else ''
     op10 = f" and book='{book}'" if book else ''
 
-    op11 = f" and image_id like '%,%' " if not is_singleimg else ''
-    op12 = f" and is_video" if is_video == 2 else ' and not is_video'  # 进行对应修改1----图片
     if campaign_ids:
         campaign_ids = campaign_ids.split(',')
         campaign_ids = "','".join([str(i) for i in campaign_ids])
@@ -926,15 +922,15 @@ def content_rank(user_id, start, end, page, page_size, order, order_by, book, ch
     op_or1 = f' or (dt<date_add(now(),interval -5 day) or cost>5000) ' if data_type == 'all' else ''
     # clicktimes,view_times,consume_amount,click_rate---------数据进行一一对应
     if order_by == 'click_times':
-        order_by = 'clickTimes'
+        order_by = 'click_count'
     if order_by == 'view_times':
-        order_by = 'viewTimes'
+        order_by = 'view_count'
     if order_by == 'consume_amount':
-        order_by = 'consumeAmount'
+        order_by = 'cost'
     if order_by == 'click_rate':
-        order_by = 'if(clickTimes=0 or viewTimes =0 or viewTimes is null or clickTimes is null,0,clickTimes / viewTimes) '
+        order_by = 'if(click_count=0 or view_count =0 or view_count is null or click_count is null,0,round(click_count / view_count,2)) '
     if order_by == 'create_time' or order_by == 'start_date':
-        order_by = 'consumeAmount'
+        order_by = 'cost'
 
     op_order = f" order by {order_by}  {order}" if order_by and order else ''
 
@@ -944,32 +940,12 @@ def content_rank(user_id, start, end, page, page_size, order, order_by, book, ch
 
     db = MysqlUtils().dm
 
-    title_totle = db.getData(f'''select count(*) from dw_image_cost_day dicd
-where   REPLACE(REPLACE(title , CHAR(10), ''), CHAR(13), '')  is not null and length(title)>0 
-    and (1=1 {op1}  {op4}   {op10} {op11}  {op12}  {op_or1}) 
-    {op_time_bigger} {op_time_small} 
-''')[0][0]
-    des_totle = db.getData(f'''select count(*) from dw_image_cost_day dicd
- where   REPLACE(REPLACE(description , CHAR(10), ''), CHAR(13), '')  is not null and length(description)>0 
-    and (1=1 {op1}  {op4}   {op10} {op11}  {op12}  {op_or1}) 
-    {op_time_bigger} {op_time_small} 
-''')[0][0]
-    total = des_totle + title_totle
-    if total:
-        start_title = int(((page - 1) * page_size) / total * title_totle)
-        start_des = int(((page - 1) * page_size) / total * des_totle)
-    else:
-        start_title = 0
-        start_des = 0
-    print(page, page_size, start_title, start_des)
-
     sql = f"""
-(  select 
+    select 
     campaign_id as id,
     book as novels,
     dt as startDate,
     date_format( now(),'%Y-%m-%d') as endDate,
-    1 as type,
     'all' as dataType,
     owner as creator,
     False as isCollected,
@@ -981,7 +957,8 @@ where   REPLACE(REPLACE(title , CHAR(10), ''), CHAR(13), '')  is not null and le
     round((cost/view_count)*1000,2) cpm, 
     round(click_count/view_count,4) ctr,
     round(cost/click_count,2) cpc,
-    REPLACE(REPLACE(description , CHAR(10), ''), CHAR(13), '') as content ,
+    REPLACE(REPLACE(description , CHAR(10), ''), CHAR(13), '') as description,
+    REPLACE(REPLACE(title, CHAR(10), ''), CHAR(13), '') as title,
     date_format( now(),'%Y-%m-%d %H:%i:%S') as upateTime,
     null as updateBy,
     use_times as userTimes
@@ -1009,74 +986,17 @@ where   REPLACE(REPLACE(title , CHAR(10), ''), CHAR(13), '')  is not null and le
     max(video_length) as video_length,
     sum(use_times) as use_times
     from dw_image_cost_day 
-    where     REPLACE(REPLACE(description, CHAR(10), ''), CHAR(13), '') is not null 
+    where (REPLACE(REPLACE(description, CHAR(10), ''), CHAR(13), '') is not null 
+    or REPLACE(REPLACE(title, CHAR(10), ''), CHAR(13), '') is not null )
     and (1=1 {op1}  {op_or1})
-    {op4}   {op10} {op11}  {op12}   {op_campaign_id}
+    {op4} {op10} {op_campaign_id}
     {op_time_bigger} {op_time_small} 
-    group by campaign_id
-    ) as foo
-    limit {start_title} , {int(page_size / 2)})
-union all
-(select 
-    campaign_id as id,
-    book as novels,
-    dt as startDate,
-    date_format( now(),'%Y-%m-%d') as endDate,
-    2 as type,
-    'all' as dataType,
-    owner as creator,
-    False as isCollected,
-    if(click_count=0 or view_count =0 or view_count is null or click_count is null,0,round(click_count / view_count,2)) as clickRate,
-    round(width/if(height,height,1),2) aspect_ratio,
-    cost as consumeAmount,
-    view_count as viewTimes,
-    click_count as clickTimes,
-    round((cost/view_count)*1000,2) cpm, 
-    round(click_count/view_count,4) ctr,
-    round(cost/click_count,2) cpc,
-    REPLACE(REPLACE(title, CHAR(10), ''), CHAR(13), '') as content ,
-    date_format( now(),'%Y-%m-%d %H:%i:%S') as upateTime,
-    null as updateBy,
-    use_times as userTimes
-    from  (
-     select
-    max(campaign_id) as campaign_id ,
-    max(book) as book,
-    min(dt) as dt,
-    max(image_id) as image_id,
-    max(`type`) as type,
-    max(owner) as owner,
-    max(download_path) as download_path,
-    max(height) as height,
-    max(width) as width,
-    max(preview_url) as preview_url,
-    max(format) as format,
-    max(size) as size,
-    sum(cost) as cost,
-    sum(view_count) as view_count,
-    sum(click_count) as click_count,
-    max(title) as title,
-    max(is_video) as is_video,
-    max(description) as description,
-    max(video_bit_rate) as video_bit_rate,
-    max(video_length) as video_length,
-    sum(use_times) as use_times
-    from dw_image_cost_day 
-    where     REPLACE(REPLACE(description, CHAR(10), ''), CHAR(13), '') is not null 
-    and (1=1 {op1}  {op_or1})
-    {op4}   {op10} {op11}  {op12}   {op_campaign_id}
-    {op_time_bigger} {op_time_small} 
-    group by campaign_id
-    ) as foo
-    limit {start_des} , {int(page_size / 2)}
-    ) 
-     {op_order} 
+    group by campaign_id ) as foo
+     {op_order}
     """
-    print(sql)
-
-    data = db.getData_json(sql)
 
-    data = {'records': data, 'total': total, 'size': page_size, 'current': page, 'pages': int(total / page_size) + 1}
+    print(sql)
+    data, total = getLimitData(db, sql, page, page_size)
     return data