|
@@ -4,8 +4,8 @@ from model.log import logger
|
|
from model.CommonUtils import *
|
|
from model.CommonUtils import *
|
|
from model import UserAuthUtils
|
|
from model import UserAuthUtils
|
|
from model.UserAuthUtils import super_auth
|
|
from model.UserAuthUtils import super_auth
|
|
-du = DateUtils()
|
|
|
|
|
|
|
|
|
|
+du = DateUtils()
|
|
|
|
|
|
from data_manage.operate import get_pitcher
|
|
from data_manage.operate import get_pitcher
|
|
|
|
|
|
@@ -22,19 +22,20 @@ log = logger()
|
|
# return di.get(channel,'')
|
|
# return di.get(channel,'')
|
|
|
|
|
|
"""根据名字获取其归属的公众号"""
|
|
"""根据名字获取其归属的公众号"""
|
|
|
|
+
|
|
|
|
+
|
|
def get_channels_from_user(user):
|
|
def get_channels_from_user(user):
|
|
- sql=f"""SELECT a.nick_name FROM t_mp_account a
|
|
|
|
|
|
+ sql = f"""SELECT a.nick_name FROM t_mp_account a
|
|
left join t_sys_user b on a.oper_user_id=b.user_id where b.nick_name='{user}'"""
|
|
left join t_sys_user b on a.oper_user_id=b.user_id where b.nick_name='{user}'"""
|
|
return tuple(MysqlUtils().zx.getOneList(sql))
|
|
return tuple(MysqlUtils().zx.getOneList(sql))
|
|
|
|
|
|
|
|
|
|
|
|
+def get_pitcher_panel_channel(pitcher, channel, start, end, page, page_size, order_by, order):
|
|
|
|
+ db = MysqlUtils()
|
|
|
|
+ op1 = f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
|
+ op2 = f" and channel='{channel}'" if channel else ''
|
|
|
|
|
|
-def get_pitcher_panel_channel(pitcher,channel,start,end,page,page_size,order_by,order):
|
|
|
|
- db=MysqlUtils()
|
|
|
|
- op1=f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
|
- op2=f" and channel='{channel}'" if channel else ''
|
|
|
|
-
|
|
|
|
- sql=f"""select channel,stage,platform,book,
|
|
|
|
|
|
+ sql = f"""select channel,stage,platform,book,
|
|
dt as date,cost,first_order_amount,
|
|
dt as date,cost,first_order_amount,
|
|
if(cost=0,0,first_order_amount/cost) first_roi,
|
|
if(cost=0,0,first_order_amount/cost) first_roi,
|
|
first_order_user,first_order_count,
|
|
first_order_user,first_order_count,
|
|
@@ -47,16 +48,17 @@ def get_pitcher_panel_channel(pitcher,channel,start,end,page,page_size,order_by,
|
|
from dw_channel_daily where dt>='{start}' and dt<='{end}' {op1} {op2}
|
|
from dw_channel_daily where dt>='{start}' and dt<='{end}' {op1} {op2}
|
|
order by {order_by} {order}
|
|
order by {order_by} {order}
|
|
"""
|
|
"""
|
|
- return getLimitData(db.quchen_text,sql,page,page_size)
|
|
|
|
|
|
+ return getLimitData(db.quchen_text, sql, page, page_size)
|
|
|
|
+
|
|
|
|
|
|
def get_pitcher_panel_daily(pitcher, start, end, page, page_size, order_by, order):
|
|
def get_pitcher_panel_daily(pitcher, start, end, page, page_size, order_by, order):
|
|
- db=MysqlUtils()
|
|
|
|
- op1= f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
|
- op2=f" and dt>='{start}' " if start else ''
|
|
|
|
- op3=f" and dt<='{end}' " if end else ''
|
|
|
|
- op4=f" order by {order_by} {order}" if order_by and order else ''
|
|
|
|
|
|
+ db = MysqlUtils()
|
|
|
|
+ op1 = f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
|
+ op2 = f" and dt>='{start}' " if start else ''
|
|
|
|
+ op3 = f" and dt<='{end}' " if end else ''
|
|
|
|
+ op4 = f" order by {order_by} {order}" if order_by and order else ''
|
|
|
|
|
|
- sql=f"""
|
|
|
|
|
|
+ sql = f"""
|
|
select dt date,
|
|
select dt date,
|
|
pitcher,cost,
|
|
pitcher,cost,
|
|
first_order_amount,
|
|
first_order_amount,
|
|
@@ -69,7 +71,7 @@ def get_pitcher_panel_daily(pitcher, start, end, page, page_size, order_by, orde
|
|
"""
|
|
"""
|
|
print(sql)
|
|
print(sql)
|
|
|
|
|
|
- sumSql=f"""
|
|
|
|
|
|
+ sumSql = f"""
|
|
select '总计' date,sum(cost) cost,
|
|
select '总计' date,sum(cost) cost,
|
|
sum(first_order_amount) first_order_amount,sum(reg_amount) reg_amount,
|
|
sum(first_order_amount) first_order_amount,sum(reg_amount) reg_amount,
|
|
round(if(sum(cost)=0,0,sum(first_order_amount)/sum(cost)),4) first_roi,
|
|
round(if(sum(cost)=0,0,sum(first_order_amount)/sum(cost)),4) first_roi,
|
|
@@ -80,15 +82,14 @@ def get_pitcher_panel_daily(pitcher, start, end, page, page_size, order_by, orde
|
|
|
|
|
|
print(sumSql)
|
|
print(sumSql)
|
|
|
|
|
|
- return getLimitSumData(db.dm,sql,sumSql,page,page_size)
|
|
|
|
|
|
+ return getLimitSumData(db.dm, sql, sumSql, page, page_size)
|
|
|
|
|
|
|
|
|
|
def get_pitcher_panel_overview(pitcher):
|
|
def get_pitcher_panel_overview(pitcher):
|
|
- db=MysqlUtils()
|
|
|
|
- op1= f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
|
-
|
|
|
|
|
|
+ db = MysqlUtils()
|
|
|
|
+ op1 = f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
|
|
|
- sql=f"""select pitcher,
|
|
|
|
|
|
+ sql = f"""select pitcher,
|
|
total_cost cost,
|
|
total_cost cost,
|
|
total_amount amount,
|
|
total_amount amount,
|
|
if(total_cost=0,0,total_amount/total_cost) roi,
|
|
if(total_cost=0,0,total_amount/total_cost) roi,
|
|
@@ -113,8 +114,8 @@ where 1=1 {op1}
|
|
return db.dm.getData_json(sql)
|
|
return db.dm.getData_json(sql)
|
|
|
|
|
|
|
|
|
|
-def get_channel_overview(user_id,channel,pitcher,stage,book,start,end,page,page_size,order_by,order):
|
|
|
|
- db=MysqlUtils()
|
|
|
|
|
|
+def get_channel_overview(user_id, channel, pitcher, stage, book, start, end, page, page_size, order_by, order):
|
|
|
|
+ db = MysqlUtils()
|
|
if user_id in super_auth():
|
|
if user_id in super_auth():
|
|
op = ''
|
|
op = ''
|
|
else:
|
|
else:
|
|
@@ -126,15 +127,15 @@ def get_channel_overview(user_id,channel,pitcher,stage,book,start,end,page,page_
|
|
else:
|
|
else:
|
|
op = f" and channel in {str(UserAuthUtils.get_auth_channel(user_id))}"
|
|
op = f" and channel in {str(UserAuthUtils.get_auth_channel(user_id))}"
|
|
|
|
|
|
- op1 = f" and pitcher ='{pitcher}' " if pitcher else ''
|
|
|
|
|
|
+ op1 = f" and pitcher ='{pitcher}' " if pitcher else ''
|
|
op2 = f" and channel='{channel}'" if channel else ''
|
|
op2 = f" and channel='{channel}'" if channel else ''
|
|
op3 = f" and dt>='{start}' " if start else ''
|
|
op3 = f" and dt>='{start}' " if start else ''
|
|
op4 = f" and dt<='{end}' " if end else ''
|
|
op4 = f" and dt<='{end}' " if end else ''
|
|
op5 = f" order by {order_by} {order}" if order_by and order else ''
|
|
op5 = f" order by {order_by} {order}" if order_by and order else ''
|
|
- op6=f" and stage='{stage}'" if stage else ''
|
|
|
|
- op7=f" and book='{book}'" if book else ''
|
|
|
|
|
|
+ op6 = f" and stage='{stage}'" if stage else ''
|
|
|
|
+ op7 = f" and book='{book}'" if book else ''
|
|
|
|
|
|
- sql=f"""select channel,dt date,
|
|
|
|
|
|
+ sql = f"""select channel,dt date,
|
|
view_count,click_count,
|
|
view_count,click_count,
|
|
round(if(view_count=0,0,click_count/view_count),4) click_rate,
|
|
round(if(view_count=0,0,click_count/view_count),4) click_rate,
|
|
follow_user,
|
|
follow_user,
|
|
@@ -166,7 +167,7 @@ def get_channel_overview(user_id,channel,pitcher,stage,book,start,end,page,page_
|
|
from dw_channel where 1=1 {op} {op1} {op2} {op3} {op4} {op6} {op7} {op5} """
|
|
from dw_channel where 1=1 {op} {op1} {op2} {op3} {op4} {op6} {op7} {op5} """
|
|
|
|
|
|
print(sql)
|
|
print(sql)
|
|
- sumsql=f"""select '总计' date,
|
|
|
|
|
|
+ sumsql = f"""select '总计' date,
|
|
sum(view_count) view_count,
|
|
sum(view_count) view_count,
|
|
sum(click_count) click_count,
|
|
sum(click_count) click_count,
|
|
round(sum(click_count)/sum(view_count),4) click_rate,
|
|
round(sum(click_count)/sum(view_count),4) click_rate,
|
|
@@ -201,15 +202,14 @@ from ({sql}) a
|
|
|
|
|
|
"""
|
|
"""
|
|
|
|
|
|
-
|
|
|
|
- return getLimitSumData(db.dm,sql,sumsql,page,page_size)
|
|
|
|
|
|
+ return getLimitSumData(db.dm, sql, sumsql, page, page_size)
|
|
|
|
|
|
|
|
|
|
-def get_channel_again_order_trend(channel,date):
|
|
|
|
|
|
+def get_channel_again_order_trend(channel, date):
|
|
ck = CkUtils()
|
|
ck = CkUtils()
|
|
db = MysqlUtils()
|
|
db = MysqlUtils()
|
|
|
|
|
|
- sql=f"""select dt date,
|
|
|
|
|
|
+ sql = f"""select dt date,
|
|
channel,book,pitcher,stage,
|
|
channel,book,pitcher,stage,
|
|
cost,
|
|
cost,
|
|
reg_order_amount reg_amount,
|
|
reg_order_amount reg_amount,
|
|
@@ -225,7 +225,7 @@ def get_channel_again_order_trend(channel,date):
|
|
from dw_channel where channel='{channel}' and dt='{date}'
|
|
from dw_channel where channel='{channel}' and dt='{date}'
|
|
"""
|
|
"""
|
|
# print(sql)
|
|
# print(sql)
|
|
- j=db.dm.getData_json(sql)
|
|
|
|
|
|
+ j = db.dm.getData_json(sql)
|
|
|
|
|
|
if len(j) == 0:
|
|
if len(j) == 0:
|
|
return None
|
|
return None
|
|
@@ -234,7 +234,7 @@ def get_channel_again_order_trend(channel,date):
|
|
|
|
|
|
# print(json1)
|
|
# print(json1)
|
|
# print(json1)
|
|
# print(json1)
|
|
- sql2=f"""select
|
|
|
|
|
|
+ sql2 = f"""select
|
|
1 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
|
|
1 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
|
|
sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
|
|
sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
|
|
from (select count(1) count
|
|
from (select count(1) count
|
|
@@ -289,7 +289,7 @@ select
|
|
from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),6) and status=2
|
|
from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),6) and status=2
|
|
and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id) a"""
|
|
and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id) a"""
|
|
|
|
|
|
- df=ck.execute(sql2)
|
|
|
|
|
|
+ df = ck.execute(sql2)
|
|
print(df)
|
|
print(df)
|
|
# 补全
|
|
# 补全
|
|
# xx=[i[0] for i in df]
|
|
# xx=[i[0] for i in df]
|
|
@@ -301,77 +301,77 @@ select
|
|
df.sort(key=operator.itemgetter(0))
|
|
df.sort(key=operator.itemgetter(0))
|
|
print(df)
|
|
print(df)
|
|
|
|
|
|
- reg_user=json1["reg_user"]
|
|
|
|
- li=[]
|
|
|
|
- for i in range(1,6):
|
|
|
|
|
|
+ reg_user = json1["reg_user"]
|
|
|
|
+ li = []
|
|
|
|
+ for i in range(1, 6):
|
|
print(i)
|
|
print(i)
|
|
d = {}
|
|
d = {}
|
|
d["user_order_count"] = i
|
|
d["user_order_count"] = i
|
|
- d1={}
|
|
|
|
- d1["origin"]=df[0][i]
|
|
|
|
- d1["new"]=0
|
|
|
|
- d1["move"]=df[0][i+1]
|
|
|
|
- d1["now"]=d1["origin"]+d1['new']-d1["move"]
|
|
|
|
- d1["follow_order_rate"]=round(d1["now"]/df[0][1],2) if df[0][i]!=0 else 0
|
|
|
|
|
|
+ d1 = {}
|
|
|
|
+ d1["origin"] = df[0][i]
|
|
|
|
+ d1["new"] = 0
|
|
|
|
+ d1["move"] = df[0][i + 1]
|
|
|
|
+ d1["now"] = d1["origin"] + d1['new'] - d1["move"]
|
|
|
|
+ d1["follow_order_rate"] = round(d1["now"] / df[0][1], 2) if df[0][i] != 0 else 0
|
|
d['d1'] = d1
|
|
d['d1'] = d1
|
|
|
|
|
|
- d2={}
|
|
|
|
|
|
+ d2 = {}
|
|
d2["origin"] = d1["now"]
|
|
d2["origin"] = d1["now"]
|
|
- d2["new"] = df[1][i]-df[0][i]
|
|
|
|
- d2["move"] = df[1][i+1]-df[0][i+1]
|
|
|
|
- d2["now"] = df[1][i]-df[1][i+1]
|
|
|
|
- d2["follow_order_rate"] = round(d2["now"] /df[1][1], 2) if df[1][i]!=0 else 0
|
|
|
|
|
|
+ d2["new"] = df[1][i] - df[0][i]
|
|
|
|
+ d2["move"] = df[1][i + 1] - df[0][i + 1]
|
|
|
|
+ d2["now"] = df[1][i] - df[1][i + 1]
|
|
|
|
+ d2["follow_order_rate"] = round(d2["now"] / df[1][1], 2) if df[1][i] != 0 else 0
|
|
d['d2'] = d2
|
|
d['d2'] = d2
|
|
|
|
|
|
- d3={}
|
|
|
|
|
|
+ d3 = {}
|
|
d3["origin"] = d2["now"]
|
|
d3["origin"] = d2["now"]
|
|
- d3["new"] = df[2][i]-df[1][i]
|
|
|
|
- d3["move"] =df[2][i+1]-df[1][i+1]
|
|
|
|
- d3["now"] = df[2][i]-df[2][i+1]
|
|
|
|
- d3["follow_order_rate"] = round(d3["now"] / df[2][1], 2) if df[2][i]!=0 else 0
|
|
|
|
|
|
+ d3["new"] = df[2][i] - df[1][i]
|
|
|
|
+ d3["move"] = df[2][i + 1] - df[1][i + 1]
|
|
|
|
+ d3["now"] = df[2][i] - df[2][i + 1]
|
|
|
|
+ d3["follow_order_rate"] = round(d3["now"] / df[2][1], 2) if df[2][i] != 0 else 0
|
|
d['d3'] = d3
|
|
d['d3'] = d3
|
|
|
|
|
|
- d4={}
|
|
|
|
|
|
+ d4 = {}
|
|
d4["origin"] = d3["now"]
|
|
d4["origin"] = d3["now"]
|
|
- d4["new"] = df[3][i]-df[2][i]
|
|
|
|
- d4["move"] = df[3][i+1]-df[2][i+1]
|
|
|
|
- d4["now"] = df[3][i]-df[3][i+1]
|
|
|
|
- d4["follow_order_rate"] = round(d4["now"] / df[3][1], 2) if df[3][i]!=0 else 0
|
|
|
|
|
|
+ d4["new"] = df[3][i] - df[2][i]
|
|
|
|
+ d4["move"] = df[3][i + 1] - df[2][i + 1]
|
|
|
|
+ d4["now"] = df[3][i] - df[3][i + 1]
|
|
|
|
+ d4["follow_order_rate"] = round(d4["now"] / df[3][1], 2) if df[3][i] != 0 else 0
|
|
d['d4'] = d4
|
|
d['d4'] = d4
|
|
|
|
|
|
- d5={}
|
|
|
|
|
|
+ d5 = {}
|
|
d5["origin"] = d4["now"]
|
|
d5["origin"] = d4["now"]
|
|
- d5["new"] = df[4][i]-df[3][i]
|
|
|
|
- d5["move"] = df[4][i+1]-df[3][i+1]
|
|
|
|
- d5["now"] = df[4][i]-df[4][i+1]
|
|
|
|
- d5["follow_order_rate"] = round(d4["now"] / df[4][1], 2) if df[3][i]!=0 else 0
|
|
|
|
|
|
+ d5["new"] = df[4][i] - df[3][i]
|
|
|
|
+ d5["move"] = df[4][i + 1] - df[3][i + 1]
|
|
|
|
+ d5["now"] = df[4][i] - df[4][i + 1]
|
|
|
|
+ d5["follow_order_rate"] = round(d4["now"] / df[4][1], 2) if df[3][i] != 0 else 0
|
|
d['d5'] = d5
|
|
d['d5'] = d5
|
|
|
|
|
|
d6 = {}
|
|
d6 = {}
|
|
d6["origin"] = d5["now"]
|
|
d6["origin"] = d5["now"]
|
|
- d6["new"] = df[5][i]-df[4][i]
|
|
|
|
- d6["move"] = df[5][i+1]-df[4][i+1]
|
|
|
|
- d6["now"] = df[5][i]-df[5][i+1]
|
|
|
|
- d6["follow_order_rate"] = round(d6["now"] / df[5][1], 2) if df[5][i]!=0 else 0
|
|
|
|
|
|
+ d6["new"] = df[5][i] - df[4][i]
|
|
|
|
+ d6["move"] = df[5][i + 1] - df[4][i + 1]
|
|
|
|
+ d6["now"] = df[5][i] - df[5][i + 1]
|
|
|
|
+ d6["follow_order_rate"] = round(d6["now"] / df[5][1], 2) if df[5][i] != 0 else 0
|
|
d['d6'] = d6
|
|
d['d6'] = d6
|
|
|
|
|
|
d7 = {}
|
|
d7 = {}
|
|
d7["origin"] = d6["now"]
|
|
d7["origin"] = d6["now"]
|
|
- d7["new"] = df[6][i]-df[5][i]
|
|
|
|
- d7["move"] = df[6][i+1]-df[5][i+1]
|
|
|
|
- d7["now"] = df[6][i]-df[6][i+1]
|
|
|
|
- d7["follow_order_rate"] = round(d7["now"] / df[6][1], 2) if df[6][i]!=0 else 0
|
|
|
|
|
|
+ d7["new"] = df[6][i] - df[5][i]
|
|
|
|
+ d7["move"] = df[6][i + 1] - df[5][i + 1]
|
|
|
|
+ d7["now"] = df[6][i] - df[6][i + 1]
|
|
|
|
+ d7["follow_order_rate"] = round(d7["now"] / df[6][1], 2) if df[6][i] != 0 else 0
|
|
d['d7'] = d7
|
|
d['d7'] = d7
|
|
|
|
|
|
li.append(d)
|
|
li.append(d)
|
|
print(li)
|
|
print(li)
|
|
|
|
|
|
- json1['data']=li
|
|
|
|
|
|
+ json1['data'] = li
|
|
# print([json1])
|
|
# print([json1])
|
|
return [json1]
|
|
return [json1]
|
|
|
|
|
|
|
|
|
|
-def get_channel_active(user_id,channel,pitcher,start,end,page,page_size,order_by,order):
|
|
|
|
|
|
+def get_channel_active(user_id, channel, pitcher, start, end, page, page_size, order_by, order):
|
|
db = MysqlUtils()
|
|
db = MysqlUtils()
|
|
if user_id in super_auth():
|
|
if user_id in super_auth():
|
|
op = ''
|
|
op = ''
|
|
@@ -388,8 +388,7 @@ def get_channel_active(user_id,channel,pitcher,start,end,page,page_size,order_by
|
|
op4 = f" and dt<='{end}' " if end else ''
|
|
op4 = f" and dt<='{end}' " if end else ''
|
|
op5 = f" order by {order_by} {order}" if order_by and order else ''
|
|
op5 = f" order by {order_by} {order}" if order_by and order else ''
|
|
|
|
|
|
-
|
|
|
|
- sql=f"""
|
|
|
|
|
|
+ sql = f"""
|
|
select channel,dt date,book,stage,pitcher,cost,
|
|
select channel,dt date,book,stage,pitcher,cost,
|
|
reg_order_amount reg_amount,
|
|
reg_order_amount reg_amount,
|
|
dc7,dc30,
|
|
dc7,dc30,
|
|
@@ -438,24 +437,26 @@ from (select * from dw_channel where cost>0 {op} {op1} {op2} {op3} {op4}) a
|
|
left join dw_channel_user_daily b using(dt,channel) {op5}
|
|
left join dw_channel_user_daily b using(dt,channel) {op5}
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
+ data, total = getLimitData(db.dm, sql, page, page_size)
|
|
|
|
|
|
- data,total=getLimitData(db.dm,sql,page,page_size)
|
|
|
|
def parse(str):
|
|
def parse(str):
|
|
- li=str.split(',')
|
|
|
|
- li[0]=round(float(li[0]),0)
|
|
|
|
- li[1]=round(float(li[1]),2)
|
|
|
|
- li[2]=round(float(li[2]),4)
|
|
|
|
- return dict(zip(['act_user', 'act_cost_per_cost', 'act_rate'],li))
|
|
|
|
|
|
+ li = str.split(',')
|
|
|
|
+ li[0] = round(float(li[0]), 0)
|
|
|
|
+ li[1] = round(float(li[1]), 2)
|
|
|
|
+ li[2] = round(float(li[2]), 4)
|
|
|
|
+ return dict(zip(['act_user', 'act_cost_per_cost', 'act_rate'], li))
|
|
|
|
|
|
for i in data:
|
|
for i in data:
|
|
for x in i:
|
|
for x in i:
|
|
- if x in ['d1','d2','d3','d4','d5','d6','d7','d8','d9','d10',
|
|
|
|
- 'd11','d12','d13','d14','d15','d16','d17','d18','d19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30']:
|
|
|
|
- i[x]=parse(i[x]) if i[x] is not None else {}
|
|
|
|
|
|
+ if x in ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10',
|
|
|
|
+ 'd11', 'd12', 'd13', 'd14', 'd15', 'd16', 'd17', 'd18', 'd19', 'd20', 'd21', 'd22', 'd23', 'd24',
|
|
|
|
+ 'd25', 'd26', 'd27', 'd28', 'd29', 'd30']:
|
|
|
|
+ i[x] = parse(i[x]) if i[x] is not None else {}
|
|
|
|
+
|
|
|
|
+ return data, total
|
|
|
|
|
|
- return data,total
|
|
|
|
|
|
|
|
-def get_channel_order_trend(user_id,channel,pitcher,start,end,page,page_size,order_by,order):
|
|
|
|
|
|
+def get_channel_order_trend(user_id, channel, pitcher, start, end, page, page_size, order_by, order):
|
|
db = MysqlUtils()
|
|
db = MysqlUtils()
|
|
if user_id in super_auth():
|
|
if user_id in super_auth():
|
|
op = ''
|
|
op = ''
|
|
@@ -469,7 +470,7 @@ def get_channel_order_trend(user_id,channel,pitcher,start,end,page,page_size,ord
|
|
op = f" and channel in {str(UserAuthUtils.get_auth_channel(user_id))}"
|
|
op = f" and channel in {str(UserAuthUtils.get_auth_channel(user_id))}"
|
|
|
|
|
|
op1 = f" and pitcher ='{pitcher}' " if pitcher else ''
|
|
op1 = f" and pitcher ='{pitcher}' " if pitcher else ''
|
|
- if channel and len(channel)>1:
|
|
|
|
|
|
+ if channel and len(channel) > 1:
|
|
op2 = f" and channel in {str(tuple(channel))}"
|
|
op2 = f" and channel in {str(tuple(channel))}"
|
|
else:
|
|
else:
|
|
op2 = f" and channel='{channel[0]}'" if channel else ''
|
|
op2 = f" and channel='{channel[0]}'" if channel else ''
|
|
@@ -663,8 +664,7 @@ def get_channel_order_trend(user_id,channel,pitcher,start,end,page,page_size,ord
|
|
{op5}
|
|
{op5}
|
|
"""
|
|
"""
|
|
|
|
|
|
-
|
|
|
|
- sumsql=f"""select concat(date_format(min(date),'%Y/%m/%d'),'~',date_format(max(date),'%Y/%m/%d')) date,
|
|
|
|
|
|
+ sumsql = f"""select concat(date_format(min(date),'%Y/%m/%d'),'~',date_format(max(date),'%Y/%m/%d')) date,
|
|
sum(cost) cost,
|
|
sum(cost) cost,
|
|
sum(reg_amount) reg_amount,
|
|
sum(reg_amount) reg_amount,
|
|
sum(first_amount) first_amount,
|
|
sum(first_amount) first_amount,
|
|
@@ -747,38 +747,44 @@ def get_channel_order_trend(user_id,channel,pitcher,start,end,page,page_size,ord
|
|
from ({sql}) a
|
|
from ({sql}) a
|
|
"""
|
|
"""
|
|
print(sumsql)
|
|
print(sumsql)
|
|
- data,total,total_data=getLimitSumData(db.dm,sql,sumsql,page,page_size)
|
|
|
|
-
|
|
|
|
|
|
+ data, total, total_data = getLimitSumData(db.dm, sql, sumsql, page, page_size)
|
|
|
|
|
|
def parse(key_str):
|
|
def parse(key_str):
|
|
if type(key_str) is not str:
|
|
if type(key_str) is not str:
|
|
- key_str=key_str.decode('utf-8')
|
|
|
|
- li=key_str.split(',')
|
|
|
|
- li[0]=round(float(li[0]),2)
|
|
|
|
- li[1]=round(float(li[1]),4)
|
|
|
|
- li[2]=round(float(li[2]),4)
|
|
|
|
- li[3]=round(float(li[3]),2)
|
|
|
|
- return dict(zip(['order','roi','add','mult'],li))
|
|
|
|
|
|
+ key_str = key_str.decode('utf-8')
|
|
|
|
+ li = key_str.split(',')
|
|
|
|
+ li[0] = round(float(li[0]), 2)
|
|
|
|
+ li[1] = round(float(li[1]), 4)
|
|
|
|
+ li[2] = round(float(li[2]), 4)
|
|
|
|
+ li[3] = round(float(li[3]), 2)
|
|
|
|
+ return dict(zip(['order', 'roi', 'add', 'mult'], li))
|
|
|
|
|
|
for x in total_data.keys():
|
|
for x in total_data.keys():
|
|
- if x in ['d1','d2','d3','d4','d5','d6','d7','d8','d9','d10','d11','d12','d13','d14','d15','d16','d17','d18',
|
|
|
|
- 'd19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30','d31','d32','d33','d34','d35','d36','d37','d38',
|
|
|
|
- 'd39','d40','d41','d42','d43','d44','d45','d46','d47','d48','d49','d50','d51','d52','d53','d54','d55','d56','d57','d58','d59',
|
|
|
|
- 'd60','m3','m4','m5']:
|
|
|
|
- total_data[x]=parse(total_data[x]) if total_data[x] is not None else {}
|
|
|
|
|
|
+ if x in ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10', 'd11', 'd12', 'd13', 'd14', 'd15', 'd16',
|
|
|
|
+ 'd17', 'd18',
|
|
|
|
+ 'd19', 'd20', 'd21', 'd22', 'd23', 'd24', 'd25', 'd26', 'd27', 'd28', 'd29', 'd30', 'd31', 'd32',
|
|
|
|
+ 'd33', 'd34', 'd35', 'd36', 'd37', 'd38',
|
|
|
|
+ 'd39', 'd40', 'd41', 'd42', 'd43', 'd44', 'd45', 'd46', 'd47', 'd48', 'd49', 'd50', 'd51', 'd52',
|
|
|
|
+ 'd53', 'd54', 'd55', 'd56', 'd57', 'd58', 'd59',
|
|
|
|
+ 'd60', 'm3', 'm4', 'm5']:
|
|
|
|
+ total_data[x] = parse(total_data[x]) if total_data[x] is not None else {}
|
|
|
|
|
|
for i in data:
|
|
for i in data:
|
|
for x in i:
|
|
for x in i:
|
|
- if x in ['d1','d2','d3','d4','d5','d6','d7','d8','d9','d10','d11','d12','d13','d14','d15','d16','d17','d18',
|
|
|
|
- 'd19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30','d31','d32','d33','d34','d35','d36','d37','d38',
|
|
|
|
- 'd39','d40','d41','d42','d43','d44','d45','d46','d47','d48','d49','d50','d51','d52','d53','d54','d55','d56','d57','d58','d59',
|
|
|
|
- 'd60','m3','m4','m5']:
|
|
|
|
- i[x]=parse(i[x]) if i[x] is not None else {}
|
|
|
|
|
|
+ if x in ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10', 'd11', 'd12', 'd13', 'd14', 'd15',
|
|
|
|
+ 'd16', 'd17', 'd18',
|
|
|
|
+ 'd19', 'd20', 'd21', 'd22', 'd23', 'd24', 'd25', 'd26', 'd27', 'd28', 'd29', 'd30', 'd31', 'd32',
|
|
|
|
+ 'd33', 'd34', 'd35', 'd36', 'd37', 'd38',
|
|
|
|
+ 'd39', 'd40', 'd41', 'd42', 'd43', 'd44', 'd45', 'd46', 'd47', 'd48', 'd49', 'd50', 'd51', 'd52',
|
|
|
|
+ 'd53', 'd54', 'd55', 'd56', 'd57', 'd58', 'd59',
|
|
|
|
+ 'd60', 'm3', 'm4', 'm5']:
|
|
|
|
+ i[x] = parse(i[x]) if i[x] is not None else {}
|
|
# print(data)
|
|
# print(data)
|
|
- return data,total,total_data
|
|
|
|
|
|
+ return data, total, total_data
|
|
|
|
|
|
-def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,state,location,start,end):
|
|
|
|
- db=MysqlUtils()
|
|
|
|
|
|
+
|
|
|
|
+def get_channel_summary(user_id, channel, pitcher, page, page_size, order_by, order, state, location, start, end):
|
|
|
|
+ db = MysqlUtils()
|
|
|
|
|
|
if user_id in super_auth(): # 超级数据权限
|
|
if user_id in super_auth(): # 超级数据权限
|
|
op = ''
|
|
op = ''
|
|
@@ -786,18 +792,17 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
|
|
channel_li = UserAuthUtils.get_auth_channel(user_id)
|
|
channel_li = UserAuthUtils.get_auth_channel(user_id)
|
|
print(channel_li.__len__())
|
|
print(channel_li.__len__())
|
|
if len(channel_li) == 0:
|
|
if len(channel_li) == 0:
|
|
- return None,None,None
|
|
|
|
|
|
+ return None, None, None
|
|
elif len(channel_li) == 1:
|
|
elif len(channel_li) == 1:
|
|
op = f" and a.channel = '{channel_li[0]}'"
|
|
op = f" and a.channel = '{channel_li[0]}'"
|
|
else:
|
|
else:
|
|
op = f" and a.channel in {tuple(channel_li)}"
|
|
op = f" and a.channel in {tuple(channel_li)}"
|
|
|
|
|
|
- op1=f" and a.channel='{channel}'" if channel else ''
|
|
|
|
- op2=f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
|
- op5=f" and state='{state}'" if state else ''
|
|
|
|
- op6=f" and a.dt>='{start}'" if start else ''
|
|
|
|
- op7 =f" and a.dt<='{end}'" if end else ''
|
|
|
|
-
|
|
|
|
|
|
+ op1 = f" and a.channel='{channel}'" if channel else ''
|
|
|
|
+ op2 = f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
|
+ op5 = f" and state='{state}'" if state else ''
|
|
|
|
+ op6 = f" and a.dt>='{start}'" if start else ''
|
|
|
|
+ op7 = f" and a.dt<='{end}'" if end else ''
|
|
|
|
|
|
sql = f"""SELECT channel,
|
|
sql = f"""SELECT channel,
|
|
if(end>date_sub(now(),interval 10 day),'在投','停投') state,
|
|
if(end>date_sub(now(),interval 10 day),'在投','停投') state,
|
|
@@ -829,7 +834,7 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
|
|
|
|
|
|
"""
|
|
"""
|
|
print(sql)
|
|
print(sql)
|
|
- sumsql=f"""select '总计' channel,
|
|
|
|
|
|
+ sumsql = f"""select '总计' channel,
|
|
sum(total_cost) total_cost,
|
|
sum(total_cost) total_cost,
|
|
sum(total_amount) total_amount,sum(profit) profit,
|
|
sum(total_amount) total_amount,sum(profit) profit,
|
|
round(sum(total_amount)/sum(total_cost),4) roi,
|
|
round(sum(total_amount)/sum(total_cost),4) roi,
|
|
@@ -843,10 +848,11 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
|
|
|
|
|
|
"""
|
|
"""
|
|
|
|
|
|
- return getLimitSumData(db.dm,sql,sumsql,page,page_size)
|
|
|
|
|
|
+ return getLimitSumData(db.dm, sql, sumsql, page, page_size)
|
|
|
|
|
|
|
|
|
|
-def get_pitcher_channel_summary(user_id, channel, pitcher, page, page_size, order_by, order, state, location, start, end):
|
|
|
|
|
|
+def get_pitcher_channel_summary(user_id, channel, pitcher, page, page_size, order_by, order, state, location, start,
|
|
|
|
+ end):
|
|
"""投手投放号"""
|
|
"""投手投放号"""
|
|
|
|
|
|
db = MysqlUtils()
|
|
db = MysqlUtils()
|
|
@@ -914,16 +920,15 @@ def get_pitcher_channel_summary(user_id, channel, pitcher, page, page_size, orde
|
|
return getLimitSumData(db.dm, sql, sumsql, page, page_size)
|
|
return getLimitSumData(db.dm, sql, sumsql, page, page_size)
|
|
|
|
|
|
|
|
|
|
-def get_pitcher_trend(pitcher,start=None,end=None,page=None,page_size=None,order_by=None,order=None):
|
|
|
|
-
|
|
|
|
- db=MysqlUtils()
|
|
|
|
|
|
+def get_pitcher_trend(pitcher, start=None, end=None, page=None, page_size=None, order_by=None, order=None):
|
|
|
|
+ db = MysqlUtils()
|
|
|
|
|
|
- op1=f" and pitcher='{pitcher}'"
|
|
|
|
|
|
+ op1 = f" and pitcher='{pitcher}'"
|
|
op2 = f" and dt>='{start}' " if start else ''
|
|
op2 = f" and dt>='{start}' " if start else ''
|
|
op3 = f" and dt<='{end}' " if end else ''
|
|
op3 = f" and dt<='{end}' " if end else ''
|
|
op4 = f" order by {order_by} {order}" if order_by and order else ''
|
|
op4 = f" order by {order_by} {order}" if order_by and order else ''
|
|
|
|
|
|
- sql=f"""select dt,pitcher,
|
|
|
|
|
|
+ sql = f"""select dt,pitcher,
|
|
cost,
|
|
cost,
|
|
reg_amount,
|
|
reg_amount,
|
|
d1 first_amount,
|
|
d1 first_amount,
|
|
@@ -965,11 +970,16 @@ def get_pitcher_trend(pitcher,start=None,end=None,page=None,page_size=None,order
|
|
CONCAT(d27-d26,",",round((d27-d26)/cost,4),',',round(d27/cost,4)) d27,
|
|
CONCAT(d27-d26,",",round((d27-d26)/cost,4),',',round(d27/cost,4)) d27,
|
|
CONCAT(d28-d27,",",round((d28-d27)/cost,4),',',round(d28/cost,4)) d28,
|
|
CONCAT(d28-d27,",",round((d28-d27)/cost,4),',',round(d28/cost,4)) d28,
|
|
CONCAT(d29-d28,",",round((d29-d28)/cost,4),',',round(d29/cost,4)) d29,
|
|
CONCAT(d29-d28,",",round((d29-d28)/cost,4),',',round(d29/cost,4)) d29,
|
|
- CONCAT(d30-d29,",",round((d30-d29)/cost,4),',',round(d30/cost,4)) d30
|
|
|
|
|
|
+ CONCAT(d30-d29,",",round((d30-d29)/cost,4),',',round(d30/cost,4)) d30,
|
|
|
|
+ d1 as da1,d2 as da2,d3 as da3,d4 as da4,d5 as da5,d6 as da6,d7 as da7,d8 as da8,d9 as da9,d10 as da10,
|
|
|
|
+ d11 as da11,d12 as da12,d13 as da13,d14 as da14,d15 as da15,d16 as da16,d17 as da17,d18 as da18,d19 as da19,
|
|
|
|
+ d20 as da20,d21 as da21,d22 as da22,d23 as da23,d24 as da24,d25 as da25,d26 as da26,d27 as da27,d28 as da28,
|
|
|
|
+ d29 as da29,d30 as da30
|
|
|
|
+
|
|
from dw_pitcher_trend where 1=1 {op1} {op2} {op3} {op4}
|
|
from dw_pitcher_trend where 1=1 {op1} {op2} {op3} {op4}
|
|
"""
|
|
"""
|
|
|
|
|
|
- sumSql=f"""select concat(date_format(min(dt),'%Y/%m/%d'),'~',date_format(max(dt),'%Y/%m/%d')) dt,sum(cost) cost,
|
|
|
|
|
|
+ sumSql = f"""select concat(date_format(min(dt),'%Y/%m/%d'),'~',date_format(max(dt),'%Y/%m/%d')) dt,sum(cost) cost,
|
|
sum(reg_amount) reg_amount,
|
|
sum(reg_amount) reg_amount,
|
|
round(sum(first_amount)/sum(cost),4) first_roi,
|
|
round(sum(first_amount)/sum(cost),4) first_roi,
|
|
round(sum(reg_amount)/sum(cost),4) roi,
|
|
round(sum(reg_amount)/sum(cost),4) roi,
|
|
@@ -979,30 +989,69 @@ def get_pitcher_trend(pitcher,start=None,end=None,page=None,page_size=None,order
|
|
sum(reg_amount30) reg_amount30,
|
|
sum(reg_amount30) reg_amount30,
|
|
round(sum(reg_amount30)/sum(cost),4) roi30,
|
|
round(sum(reg_amount30)/sum(cost),4) roi30,
|
|
sum(expect_profit) expect_profit,
|
|
sum(expect_profit) expect_profit,
|
|
- sum(annual_expect_profit) annual_expect_profit
|
|
|
|
|
|
+ sum(annual_expect_profit) annual_expect_profit,
|
|
|
|
+ concat(sum(da1),',',sum(da1)/sum(cost),',', 0,',',1) d1,
|
|
|
|
+ concat(sum(da2)-sum(if (da2,da1,0)),',',sum(da2)/sum(if (da2,cost,0)),',', (sum(da2)-sum(if (da2,da1,0)))/sum(if (da2,cost,0)),',',if(sum(if (da2,da1,0))=0,1,sum(da2)/sum(if (da2,da1,0))) ) d2,
|
|
|
|
+ concat(sum(da3)-sum(if (da3,da2,0)),',',sum(da3)/sum(if (da3,cost,0)),',', (sum(da3)-sum(if (da3,da2,0)))/sum(if (da3,cost,0)),',',if(sum(if (da3,da1,0))=0,1,sum(da3)/sum(if (da3,da1,0))) ) d3,
|
|
|
|
+ concat(sum(da4)-sum(if (da4,da3,0)),',',sum(da4)/sum(if (da4,cost,0)),',', (sum(da4)-sum(if (da4,da3,0)))/sum(if (da4,cost,0)),',',if(sum(if (da4,da1,0))=0,1,sum(da4)/sum(if (da4,da1,0))) ) d4,
|
|
|
|
+ concat(sum(da5)-sum(if (da5,da4,0)),',',sum(da5)/sum(if (da5,cost,0)),',', (sum(da5)-sum(if (da5,da4,0)))/sum(if (da5,cost,0)),',',if(sum(if (da5,da1,0))=0,1,sum(da5)/sum(if (da5,da1,0))) ) d5,
|
|
|
|
+ concat(sum(da6)-sum(if (da6,da5,0)),',',sum(da6)/sum(if (da6,cost,0)),',', (sum(da6)-sum(if (da6,da5,0)))/sum(if (da6,cost,0)),',',if(sum(if (da6,da1,0))=0,1,sum(da6)/sum(if (da6,da1,0))) ) d6,
|
|
|
|
+ concat(sum(da7)-sum(if (da7,da6,0)),',',sum(da7)/sum(if (da7,cost,0)),',', (sum(da7)-sum(if (da7,da6,0)))/sum(if (da7,cost,0)),',',if(sum(if (da7,da1,0))=0,1,sum(da7)/sum(if (da7,da1,0))) ) d7,
|
|
|
|
+ concat(sum(da8)-sum(if (da8,da7,0)),',',sum(da8)/sum(if (da8,cost,0)),',', (sum(da8)-sum(if (da8,da7,0)))/sum(if (da8,cost,0)),',',if(sum(if (da8,da1,0))=0,1,sum(da8)/sum(if (da8,da1,0))) ) d8,
|
|
|
|
+ concat(sum(da9)-sum(if (da9,da8,0)),',',sum(da9)/sum(if (da9,cost,0)),',', (sum(da9)-sum(if (da9,da8,0)))/sum(if (da9,cost,0)),',',if(sum(if (da9,da1,0))=0,1,sum(da9)/sum(if (da9,da1,0))) ) d9,
|
|
|
|
+ concat(sum(da10)-sum(if (da10,da9,0)),',',sum(da10)/sum(if (da10,cost,0)),',', (sum(da10)-sum(if (da10,da9,0)))/sum(if (da10,cost,0)),',',if(sum(if (da10,da1,0))=0,1,sum(da10)/sum(if (da10,da1,0))) ) d10,
|
|
|
|
+ concat(sum(da11)-sum(if (da11,da10,0)),',',sum(da11)/sum(if (da11,cost,0)),',', (sum(da11)-sum(if (da11,da10,0)))/sum(if (da11,cost,0)),',',if(sum(if (da11,da1,0))=0,1,sum(da11)/sum(if (da11,da1,0))) ) d11,
|
|
|
|
+ concat(sum(da12)-sum(if (da12,da11,0)),',',sum(da12)/sum(if (da12,cost,0)),',', (sum(da12)-sum(if (da12,da11,0)))/sum(if (da12,cost,0)),',',if(sum(if (da12,da1,0))=0,1,sum(da12)/sum(if (da12,da1,0))) ) d12,
|
|
|
|
+ concat(sum(da13)-sum(if (da13,da12,0)),',',sum(da13)/sum(if (da13,cost,0)),',', (sum(da13)-sum(if (da13,da12,0)))/sum(if (da13,cost,0)),',',if(sum(if (da13,da1,0))=0,1,sum(da13)/sum(if (da13,da1,0))) ) d13,
|
|
|
|
+ concat(sum(da14)-sum(if (da14,da13,0)),',',sum(da14)/sum(if (da14,cost,0)),',', (sum(da14)-sum(if (da14,da13,0)))/sum(if (da14,cost,0)),',',if(sum(if (da14,da1,0))=0,1,sum(da14)/sum(if (da14,da1,0))) ) d14,
|
|
|
|
+ concat(sum(da15)-sum(if (da15,da14,0)),',',sum(da15)/sum(if (da15,cost,0)),',', (sum(da15)-sum(if (da15,da14,0)))/sum(if (da15,cost,0)),',',if(sum(if (da15,da1,0))=0,1,sum(da15)/sum(if (da15,da1,0))) ) d15,
|
|
|
|
+ concat(sum(da16)-sum(if (da16,da15,0)),',',sum(da16)/sum(if (da16,cost,0)),',', (sum(da16)-sum(if (da16,da15,0)))/sum(if (da16,cost,0)),',',if(sum(if (da16,da1,0))=0,1,sum(da16)/sum(if (da16,da1,0))) ) d16,
|
|
|
|
+ concat(sum(da17)-sum(if (da17,da16,0)),',',sum(da17)/sum(if (da17,cost,0)),',', (sum(da17)-sum(if (da17,da16,0)))/sum(if (da17,cost,0)),',',if(sum(if (da17,da1,0))=0,1,sum(da17)/sum(if (da17,da1,0))) ) d17,
|
|
|
|
+ concat(sum(da18)-sum(if (da18,da17,0)),',',sum(da18)/sum(if (da18,cost,0)),',', (sum(da18)-sum(if (da18,da17,0)))/sum(if (da18,cost,0)),',',if(sum(if (da18,da1,0))=0,1,sum(da18)/sum(if (da18,da1,0))) ) d18,
|
|
|
|
+ concat(sum(da19)-sum(if (da19,da18,0)),',',sum(da19)/sum(if (da19,cost,0)),',', (sum(da19)-sum(if (da19,da18,0)))/sum(if (da19,cost,0)),',',if(sum(if (da19,da1,0))=0,1,sum(da19)/sum(if (da19,da1,0))) ) d19,
|
|
|
|
+ concat(sum(da20)-sum(if (da20,da19,0)),',',sum(da20)/sum(if (da20,cost,0)),',', (sum(da20)-sum(if (da20,da19,0)))/sum(if (da20,cost,0)),',',if(sum(if (da20,da1,0))=0,1,sum(da20)/sum(if (da20,da1,0))) ) d20,
|
|
|
|
+ concat(sum(da21)-sum(if (da21,da20,0)),',',sum(da21)/sum(if (da21,cost,0)),',', (sum(da21)-sum(if (da21,da20,0)))/sum(if (da21,cost,0)),',',if(sum(if (da21,da1,0))=0,1,sum(da21)/sum(if (da21,da1,0))) ) d21,
|
|
|
|
+ concat(sum(da22)-sum(if (da22,da21,0)),',',sum(da22)/sum(if (da22,cost,0)),',', (sum(da22)-sum(if (da22,da21,0)))/sum(if (da22,cost,0)),',',if(sum(if (da22,da1,0))=0,1,sum(da22)/sum(if (da22,da1,0))) ) d22,
|
|
|
|
+ concat(sum(da23)-sum(if (da23,da22,0)),',',sum(da23)/sum(if (da23,cost,0)),',', (sum(da23)-sum(if (da23,da22,0)))/sum(if (da23,cost,0)),',',if(sum(if (da23,da1,0))=0,1,sum(da23)/sum(if (da23,da1,0))) ) d23,
|
|
|
|
+ concat(sum(da24)-sum(if (da24,da23,0)),',',sum(da24)/sum(if (da24,cost,0)),',', (sum(da24)-sum(if (da24,da23,0)))/sum(if (da24,cost,0)),',',if(sum(if (da24,da1,0))=0,1,sum(da24)/sum(if (da24,da1,0))) ) d24,
|
|
|
|
+ concat(sum(da25)-sum(if (da25,da24,0)),',',sum(da25)/sum(if (da25,cost,0)),',', (sum(da25)-sum(if (da25,da24,0)))/sum(if (da25,cost,0)),',',if(sum(if (da25,da1,0))=0,1,sum(da25)/sum(if (da25,da1,0))) ) d25,
|
|
|
|
+ concat(sum(da26)-sum(if (da26,da25,0)),',',sum(da26)/sum(if (da26,cost,0)),',', (sum(da26)-sum(if (da26,da25,0)))/sum(if (da26,cost,0)),',',if(sum(if (da26,da1,0))=0,1,sum(da26)/sum(if (da26,da1,0))) ) d26,
|
|
|
|
+ concat(sum(da27)-sum(if (da27,da26,0)),',',sum(da27)/sum(if (da27,cost,0)),',', (sum(da27)-sum(if (da27,da26,0)))/sum(if (da27,cost,0)),',',if(sum(if (da27,da1,0))=0,1,sum(da27)/sum(if (da27,da1,0))) ) d27,
|
|
|
|
+ concat(sum(da28)-sum(if (da28,da27,0)),',',sum(da28)/sum(if (da28,cost,0)),',', (sum(da28)-sum(if (da28,da27,0)))/sum(if (da28,cost,0)),',',if(sum(if (da28,da1,0))=0,1,sum(da28)/sum(if (da28,da1,0))) ) d28,
|
|
|
|
+ concat(sum(da29)-sum(if (da29,da28,0)),',',sum(da29)/sum(if (da29,cost,0)),',', (sum(da29)-sum(if (da29,da28,0)))/sum(if (da29,cost,0)),',',if(sum(if (da29,da1,0))=0,1,sum(da29)/sum(if (da29,da1,0))) ) d29,
|
|
|
|
+ concat(sum(da30)-sum(if (da30,da29,0)),',',sum(da30)/sum(if (da30,cost,0)),',', (sum(da30)-sum(if (da30,da29,0)))/sum(if (da30,cost,0)),',',if(sum(if (da30,da1,0))=0,1,sum(da30)/sum(if (da30,da1,0))) ) d30
|
|
|
|
+
|
|
|
|
+
|
|
from ({sql}) a
|
|
from ({sql}) a
|
|
"""
|
|
"""
|
|
|
|
|
|
- data,total,total_data=getLimitSumData(db.dm,sql,sumSql,page,page_size)
|
|
|
|
|
|
+ data, total, total_data = getLimitSumData(db.dm, sql, sumSql, page, page_size)
|
|
print(data)
|
|
print(data)
|
|
- def parse(str):
|
|
|
|
- li=str.split(',')
|
|
|
|
- li[0]=round(float(li[0]),2)
|
|
|
|
- li[1]=round(float(li[1]),4)
|
|
|
|
- li[2]=round(float(li[2]),4)
|
|
|
|
- return dict(zip(['amount','add','roi'],li))
|
|
|
|
-
|
|
|
|
- for i in data:
|
|
|
|
- for k,v in i.items():
|
|
|
|
- if k in ['d1','d2','d3','d4','d5','d6','d7','d8','d9','d10',
|
|
|
|
- 'd11','d12','d13','d14','d15','d16','d17','d18','d19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30']:
|
|
|
|
- i[k]= parse(v) if v else {}
|
|
|
|
|
|
|
|
- return data,total,total_data
|
|
|
|
|
|
+ def parse(key_str):
|
|
|
|
+ if type(key_str) is not str:
|
|
|
|
+ key_str = key_str.decode('utf-8')
|
|
|
|
+ li = key_str.split(',')
|
|
|
|
+ li[0] = round(float(li[0]), 2)
|
|
|
|
+ li[1] = round(float(li[1]), 4)
|
|
|
|
+ li[2] = round(float(li[2]), 4)
|
|
|
|
+ return dict(zip(['amount', 'add', 'roi'], li))
|
|
|
|
+
|
|
|
|
+ for k, v in total_data.items():
|
|
|
|
+ if k in ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10',
|
|
|
|
+ 'd11', 'd12', 'd13', 'd14', 'd15', 'd16', 'd17', 'd18', 'd19', 'd20', 'd21', 'd22', 'd23', 'd24',
|
|
|
|
+ 'd25', 'd26', 'd27', 'd28', 'd29', 'd30']:
|
|
|
|
+ total_data[k] = parse(v) if v else {}
|
|
|
|
|
|
|
|
+ for i in data:
|
|
|
|
+ for k, v in i.items():
|
|
|
|
+ if k in ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10',
|
|
|
|
+ 'd11', 'd12', 'd13', 'd14', 'd15', 'd16', 'd17', 'd18', 'd19', 'd20', 'd21', 'd22', 'd23', 'd24',
|
|
|
|
+ 'd25', 'd26', 'd27', 'd28', 'd29', 'd30']:
|
|
|
|
+ i[k] = parse(v) if v else {}
|
|
|
|
|
|
|
|
+ return data, total, total_data
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
get_pitcher_trend(pitcher="陈凯")
|
|
get_pitcher_trend(pitcher="陈凯")
|
|
-
|
|
|