|
@@ -625,7 +625,7 @@ def advertisement_rank(user_id, start, end, type, page, page_size, order, order_
|
|
|
|
|
|
|
|
|
def idea_rank(user_id, start, end, page, page_size, order, order_by, book, channel, is_singleimg,
|
|
|
- is_video, label_ids, collect, data_type):
|
|
|
+ is_video, data_type, campaign_ids):
|
|
|
# TODO:修改为clickhouse来进行数据访问
|
|
|
|
|
|
# 时间的归因-----获取到所有这段时间内的记录,并进行聚合(聚合周末再做,先把数据拿出来)
|
|
@@ -646,23 +646,25 @@ def idea_rank(user_id, start, end, page, page_size, order, order_by, book, chann
|
|
|
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----图片
|
|
|
|
|
|
- op_label = f" and label_id in ({label_ids}) " if label_ids else ''
|
|
|
- op_label2 = f' and labels is not null' if label_ids else ''
|
|
|
+ if campaign_ids:
|
|
|
+ campaign_ids = campaign_ids.split(',')
|
|
|
+ campaign_ids = "','".join([str(i) for i in campaign_ids])
|
|
|
+ campaign_ids = "'" + campaign_ids + "'"
|
|
|
+ op_campaign_id = f'and campaign_id in ({campaign_ids})' if campaign_ids else ''
|
|
|
|
|
|
# 公共数据,和素材库一样,个人只显示个人(小组)数据
|
|
|
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(click_count=0 or view_count =0 or view_count is null or click_count is null,0,round(click_count / view_count,2)) '
|
|
|
- order_by = 'clickRate'
|
|
|
+ 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 ''
|
|
|
|
|
@@ -673,8 +675,7 @@ def idea_rank(user_id, start, end, page, page_size, order, order_by, book, chann
|
|
|
db = MysqlUtils().dm
|
|
|
|
|
|
sql = f'''
|
|
|
- select foo.*,foo2.labels as labels from
|
|
|
- (select
|
|
|
+ select
|
|
|
campaign_id as id,
|
|
|
book as novels,
|
|
|
dt as startDate,
|
|
@@ -710,18 +711,11 @@ def idea_rank(user_id, start, end, page, page_size, order, order_by, book, chann
|
|
|
from dw_image_cost_day
|
|
|
where replace (preview_url,' ,','') !=''
|
|
|
and (1=1 {op1} {op_or1})
|
|
|
- {op4} {op10} {op11} {op12}
|
|
|
+ {op4} {op10} {op11} {op12} {op_campaign_id}
|
|
|
{op_time_bigger} {op_time_small}
|
|
|
- ) as foo
|
|
|
- left join (select a.campaign_id,group_concat(b.label) as labels from label_database a
|
|
|
- left join ads_label b on a.label_id=b.id
|
|
|
- where 1=1 {op_label}
|
|
|
- group by a.campaign_id ) as foo2 on foo.id= foo2.campaign_id
|
|
|
- where 1=1 {op_label2}
|
|
|
{op_order}
|
|
|
|
|
|
'''
|
|
|
-
|
|
|
print(sql)
|
|
|
data, total = getLimitData(db, sql, page, page_size)
|
|
|
data = {'records': data, 'total': total, 'size': page_size, 'current': page, 'pages': int(total / page_size) + 1}
|
|
@@ -729,7 +723,7 @@ def idea_rank(user_id, start, end, page, page_size, order, order_by, book, chann
|
|
|
|
|
|
|
|
|
def media_rank(user_id, start, end, page, page_size, order, order_by, book, channel, is_singleimg,
|
|
|
- is_video, label_ids, collect, data_type):
|
|
|
+ is_video, data_type, campaign_ids):
|
|
|
# TODO:修改为clickhouse来进行数据访问
|
|
|
|
|
|
# 时间的归因-----获取到所有这段时间内的记录,并进行聚合(聚合周末再做,先把数据拿出来)
|
|
@@ -751,24 +745,27 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
|
|
|
|
|
|
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----图片
|
|
|
- op_label = f" and label_id in ({label_ids}) " if label_ids else ''
|
|
|
- op_label2 = f' and labels is not null' if label_ids else ''
|
|
|
+
|
|
|
+ if campaign_ids:
|
|
|
+ campaign_ids = campaign_ids.split(',')
|
|
|
+ campaign_ids = "','".join([str(i) for i in campaign_ids])
|
|
|
+ campaign_ids = "'" + campaign_ids + "'"
|
|
|
+ op_campaign_id = f'and campaign_id in ({campaign_ids})' if campaign_ids else ''
|
|
|
|
|
|
# 公共数据,和素材库一样,个人只显示个人(小组)数据
|
|
|
# TODO:之后op_or1 变化为owner来限制,------dw_image_cost_day 生成时就根据dt,cost来归类owner
|
|
|
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(click_count=0 or view_count =0 or view_count is null or click_count is null,0,round(click_count / view_count,2)) '
|
|
|
- order_by = 'clickRate'
|
|
|
+ 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 ''
|
|
|
|
|
@@ -779,8 +776,6 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
|
|
|
db = MysqlUtils().dm
|
|
|
|
|
|
sql = f'''
|
|
|
- select foo.*,foo2.labels as labels from
|
|
|
- (
|
|
|
select
|
|
|
campaign_id as id,
|
|
|
book as novels,
|
|
@@ -816,14 +811,8 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
|
|
|
from dw_image_cost_day
|
|
|
where replace (preview_url,' ,','') !=''
|
|
|
and (1=1 {op1} {op_or1})
|
|
|
- {op4} {op10} {op11} {op12}
|
|
|
+ {op4} {op10} {op11} {op12} {op_campaign_id}
|
|
|
{op_time_bigger} {op_time_small}
|
|
|
- ) as foo
|
|
|
- left join (select a.campaign_id,group_concat(b.label) as labels from label_database a
|
|
|
- left join ads_label b on a.label_id=b.id
|
|
|
- where 1=1 {op_label}
|
|
|
- group by a.campaign_id ) as foo2 on foo.id= foo2.campaign_id
|
|
|
- where 1=1 {op_label2}
|
|
|
{op_order}
|
|
|
|
|
|
'''
|
|
@@ -835,7 +824,7 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
|
|
|
|
|
|
|
|
|
def content_rank(user_id, start, end, page, page_size, order, order_by, book, channel, is_singleimg,
|
|
|
- is_video, label_ids, collect, data_type):
|
|
|
+ is_video, data_type, campaign_ids):
|
|
|
# TODO:修改为clickhouse来进行数据访问
|
|
|
|
|
|
# 时间的归因-----获取到所有这段时间内的记录,并进行聚合(聚合周末再做,先把数据拿出来)
|
|
@@ -851,13 +840,16 @@ def content_rank(user_id, start, end, page, page_size, order, order_by, book, ch
|
|
|
op1 = f" and pitcher in {str(user)}"
|
|
|
|
|
|
op4 = f" and channel='{channel}'" if channel else ''
|
|
|
- op_label = f" and label_id in ({label_ids}) " if label_ids else ''
|
|
|
- op_label2 = f' and labels is not null' if label_ids else ''
|
|
|
op10 = f" and book='{book}'" if book else ''
|
|
|
# TODO:添加标签相关处理------id与对应计划进行--对应
|
|
|
|
|
|
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])
|
|
|
+ campaign_ids = "'" + campaign_ids + "'"
|
|
|
+ op_campaign_id = f'and campaign_id in ({campaign_ids})' if campaign_ids else ''
|
|
|
|
|
|
# 公共数据,和素材库一样,个人只显示个人(小组)数据
|
|
|
# TODO:之后op_or1 变化为owner来限制,------dw_image_cost_day 生成时就根据dt,cost来归类owner
|
|
@@ -902,8 +894,8 @@ where REPLACE(REPLACE(title , CHAR(10), ''), CHAR(13), '') is not null and le
|
|
|
print(page, page_size, start_title, start_des)
|
|
|
|
|
|
sql = f"""
|
|
|
- select * from (select
|
|
|
- a.campaign_id as id,
|
|
|
+( select
|
|
|
+ campaign_id as id,
|
|
|
book as novels,
|
|
|
dt as startDate,
|
|
|
date_format( now(),'%Y-%m-%d') as endDate,
|
|
@@ -911,7 +903,6 @@ where REPLACE(REPLACE(title , CHAR(10), ''), CHAR(13), '') is not null and le
|
|
|
'all' as dataType,
|
|
|
owner as creator,
|
|
|
False as isCollected,
|
|
|
- b.labels as labels,
|
|
|
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,
|
|
@@ -925,19 +916,15 @@ where REPLACE(REPLACE(title , CHAR(10), ''), CHAR(13), '') is not null and le
|
|
|
null as updateBy,
|
|
|
use_times as userTimes
|
|
|
from
|
|
|
- dw_image_cost_day a
|
|
|
- left join (select a.campaign_id,group_concat(b.label) as labels from label_database a
|
|
|
- left join ads_label b on a.label_id=b.id
|
|
|
- where 1=1 {op_label}
|
|
|
- group by a.campaign_id ) as b on a.campaign_id= b.campaign_id
|
|
|
+ dw_image_cost_day
|
|
|
where REPLACE(REPLACE(description, CHAR(10), ''), CHAR(13), '') is not null and length(description)>0
|
|
|
and (1=1 {op1} {op_or1})
|
|
|
- {op4} {op10} {op11} {op12} {op_label2}
|
|
|
+ {op4} {op10} {op11} {op12} {op_campaign_id}
|
|
|
{op_time_bigger} {op_time_small}
|
|
|
- limit {start_title} , {int(page_size / 2)}) as a
|
|
|
+ limit {start_title} , {int(page_size / 2)})
|
|
|
union all
|
|
|
-select * from (select
|
|
|
- a.campaign_id as id,
|
|
|
+(select
|
|
|
+ campaign_id as id,
|
|
|
book as novels,
|
|
|
dt as startDate,
|
|
|
date_format( now(),'%Y-%m-%d') as endDate,
|
|
@@ -945,7 +932,6 @@ select * from (select
|
|
|
'all' as dataType,
|
|
|
owner as creator,
|
|
|
False as isCollected,
|
|
|
- b.labels as labels,
|
|
|
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,
|
|
@@ -958,19 +944,13 @@ select * from (select
|
|
|
date_format( now(),'%Y-%m-%d %H:%i:%S') as upateTime,
|
|
|
null as updateBy,
|
|
|
use_times as userTimes
|
|
|
- from
|
|
|
- dw_image_cost_day a
|
|
|
- left join (select a.campaign_id,group_concat(b.label) as labels from label_database a
|
|
|
- left join ads_label b on a.label_id=b.id
|
|
|
- where 1=1 {op_label}
|
|
|
- group by a.campaign_id ) as b on a.campaign_id= b.campaign_id
|
|
|
+ from dw_image_cost_day
|
|
|
where REPLACE(REPLACE(title, CHAR(10), ''), CHAR(13), '') is not null and length(title)>0
|
|
|
and (1=1 {op1} {op_or1})
|
|
|
- {op4} {op10} {op11} {op12} {op_label2}
|
|
|
+ {op4} {op10} {op11} {op12} {op_campaign_id}
|
|
|
{op_time_bigger} {op_time_small}
|
|
|
limit {start_des} , {int(page_size / 2)}
|
|
|
- ) as b
|
|
|
-
|
|
|
+ )
|
|
|
{op_order}
|
|
|
"""
|
|
|
print(sql)
|