Commit 6ed8fb08 authored by 桂秋月's avatar 桂秋月

1

parent 6960865b
from recommend import *
def backBatch(gid,isuuid=None):
temp=defaultdict(list)
if isuuid:
brandname_redis="user_recall_mapping_jg_Category:"+gid
cid_redis="user_recall_mapping_jg_brand:"+gid
else:
brandname_redis="device_recall_mapping_jg_Category:"+gid
cid_redis="device_recall_mapping_jg_brand:"+gid
brandname_recallBatchUuid=getRedisValue(brandname_redis).get(brandname_redis)
cid_recallBatchUuid=getRedisValue(cid_redis).get(cid_redis)
brandname_batch_redis= '1' + ":personal_recall_product_brand:" + brandname_recallBatchUuid
brandname_recallBatchUuid=getRedisValue(brandname_batch_redis).get(brandname_batch_redis)
print("brandname的批次数据:",brandname_recallBatchUuid)
temp['brandname_batch']=brandname_recallBatchUuid
cid_batch_redis= '2' + ":personal_recall_product_brand:" + cid_recallBatchUuid
cid_recallBatchUuid=getRedisValue(cid_batch_redis).get(cid_batch_redis)
temp['cid_batch']=cid_recallBatchUuid
print("cid3的批次数据:",cid_recallBatchUuid)
return temp
def buzu():
'''
:return: 本次补足的数据和appstart触发的逻辑是一样的
'''
return appTopic()
def appTopic():
temp=defaultdict(list)
cid3_cate_brand_heat_rank_change_sql=cate_brand_heat_rank_sql+' where show_type=1 order by rank asc limit 30'
print(cid3_cate_brand_heat_rank_change_sql)
brandname_cate_brand_heat_rank_change_sql=cate_brand_heat_rank_sql+' where show_type=2 order by rank asc limit 30'
print(brandname_cate_brand_heat_rank_change_sql)
cid3_df=execmysl(119,cid3_cate_brand_heat_rank_change_sql)
brandname_df=execmysl(119,brandname_cate_brand_heat_rank_change_sql)
temp['apptopic_cid3']=cid3_df['show_id'].to_list() if not cid3_df.empty else []
temp['apptopic_brandname']=cid3_df['show_id'].to_list() if not cid3_df.empty else []
temp['apptopic_brandname']=brandname_df['show_id'].to_list() if not cid3_df.empty else []
return temp
def clickTopic(skuno,cid3=None,brandid=None):
def clickTopic(skuno=None,cid3=None,brandid=None,cid2=None,cid1=None):
temp=defaultdict()
from recommend.publicFunc import skuinfo
if skuno:
sku_infos=skuinfo(skuno)
if cid3 and brandid:
else:
sku_infos={}
if cid3 and brandid and cid1 and cid2:
sku_infos['cid3']=cid3
sku_infos['brand_id']=brandid
sku_infos['brand_id']=int(brandid)
sku_infos['cid2']=cid2
sku_infos['cid1']=cid1
print(sku_infos)
cid3_intention_change_sql=concatSql(cate_brand_intention_score_sql,
**{"show_id":[sku_infos.get('cid3'),sku_infos.get('cid2'),sku_infos.get('cid1')]})
**{"category_id":[sku_infos.get('cid3'),sku_infos.get('cid2'),sku_infos.get('cid1')]})
cid3_intention_change_sql+=" or brand_id='{}'".format(sku_infos.get('brand_id'))
print('cicktopic 转换后的sql:',cid3_intention_change_sql)
cid3brandname_df=execmysl(119,cid3_intention_change_sql)#.sort_values(by=['rank'])['']
print('cicktopic的结果:',cid3brandname_df.head(1))
##cid3+brandid
temp['clicktopic_cid3']=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid3'))
temp['clicktopic_cid3']=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid3'))
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid2+brandid
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid2'))
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid2'))
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid1+brandid
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid1'))
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid1'))
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid3+无名品牌分
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid3'))
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid3'))
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==-1)] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid2+无名品牌分
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid2'))
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid2'))
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==-1)] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid1+无名品牌分
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid1'))
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid1'))
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==-1)] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##无品类分+品牌分
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['show_id']==-1)
temp['clicktopic_cid3']+=cid3brandname_df[(cid3brandname_df['category_id']==-1)
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
temp['clicktopic_cid3']=removeRepeat(temp['clicktopic_cid3'])[:30]
##cid3+brandid
temp['clicktopic_brandname']=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid3'))
temp['clicktopic_brandname']=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid3'))
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid2+brandid
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid2'))
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid2'))
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid1+brandid
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid1'))
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid1'))
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid3+无名品牌分
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid3'))
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid3'))
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==-1)] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid2+无名品牌分
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid2'))
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid2'))
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==-1)] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##cid1+无名品牌分
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid1'))
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid1'))
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==-1)] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
##无品类分+品牌分
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['show_id']==-1)
temp['clicktopic_brandname']+=cid3brandname_df[(cid3brandname_df['category_id']==-1)
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['show_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
.sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
temp['clicktopic_brandname']=removeRepeat(temp['clicktopic_brandname'])[:30]
......@@ -90,47 +130,68 @@ def clickTopic(skuno,cid3=None,brandid=None):
def searchTopic():
temp=defaultdict(list)
from recommend.searchTopic import getseed,step1
top10_sku,_=step1()
#top10_sku,_=step1()
top10_sku=['108385546803201', '257610058310145', '255342753613825', '253183834981889', '261761672684545', '253184857873409', '310400617292289', '276970748256769', '100007743035', '7261582']
sku_infos=getseed(top10_sku)
cid3_intention_change_sql=concatSql(cate_brand_intention_score_sql,
**{"show_id":sku_infos.get('cid3')})
cid3_intention_change_sql+=" or brand_id='{}'".format(sku_infos.get('brand_id'))
cid3brandname_df=execmysl(119,cid3_intention_change_sql)
temp['searchtopic_cid3']=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid3'))
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
temp['searchtopic_cid3']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid3'))
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==-1)] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
temp['searchtopic_cid3']+=cid3brandname_df[(cid3brandname_df['show_id']==-1)
& (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
temp['searchtopic_brandname']=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid3'))
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
temp['searchtopic_brandname']+=cid3brandname_df[(cid3brandname_df['show_id']==sku_infos.get('cid3'))
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==-1)] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
temp['searchtopic_brandname']+=cid3brandname_df[(cid3brandname_df['show_id']==-1)
& (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
.sort_values(by=['rank'])['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
temp['searchtopic_cid3']=removeRepeat(temp['searchtopic_cid3'])[:30]
temp['searchtopic_brandname']=removeRepeat(temp['searchtopic_brandname'])[:30]
print(sku_infos)
temp=clickTopic(cid3=sku_infos.get('cid3'),brandid=sku_infos.get('brand_id'),cid1=9987,cid2=653)
return temp
# cid3_intention_change_sql=concatSql(cate_brand_intention_score_sql,
# **{"category_id":sku_infos.get('cid3')})
# cid3_intention_change_sql+=" or brand_id='{}'".format(sku_infos.get('brand_id'))
# print("sql==",cid3_intention_change_sql)
# cid3brandname_df=execmysl(119,cid3_intention_change_sql)
# print("sql结果:",cid3brandname_df)
# cid3brandname_df['category_id']=cid3brandname_df['category_id'].astype('string')
# cid3brandname_df['brand_id']=cid3brandname_df['brand_id'].astype('string')
#
# temp['searchtopic_cid3']=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid3'))
# & (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
# .sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
#
# temp['searchtopic_cid3']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid3'))
# & (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']=='-1')] \
# .sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
#
# temp['searchtopic_cid3']+=cid3brandname_df[(cid3brandname_df['category_id']=='-1')
# & (cid3brandname_df['show_type']==1) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
# .sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
# print(temp)
# temp['searchtopic_brandname']=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid3'))
# & (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
# .sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
#
# temp['searchtopic_brandname']+=cid3brandname_df[(cid3brandname_df['category_id']==sku_infos.get('cid3'))
# & (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']=='-1')] \
# .sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
#
# temp['searchtopic_brandname']+=cid3brandname_df[(cid3brandname_df['category_id']=='-1')
# & (cid3brandname_df['show_type']==2) &(cid3brandname_df['brand_id']==sku_infos.get('brand_id'))] \
# .sort_values(by=['final_score'],ascending=False)['show_id'].to_list()[:30] if not cid3brandname_df.empty else []
# temp['searchtopic_cid3']=removeRepeat(temp['searchtopic_cid3'])[:30]
# temp['searchtopic_brandname']=removeRepeat(temp['searchtopic_brandname'])[:30]
# return temp
def allrun(skuno):
t=appTopic()
tt=clickTopic()
print(t)
if __name__ == '__main__':
print(clickTopic('179240378044417'))
#print(clickTopic('179240378044417'))
#print(allrun())
gid='479610b6-f346-474f-8d3a-e4de04db8f6e-002'
gid1='479610b6-f346-474f-8d3a-e4de04db8f6e-001'
print('批次:',backBatch(gid,isuuid=0))
print("***"*50)
print('批次:',backBatch(gid1,isuuid=1))
#skuno='201782177569280'
#print(clickTopic(skuno))
#print(searchTopic())
......
......@@ -53,7 +53,7 @@ def payRecall(skuno,num=100):
chaji=subtraction(subtraction(final_skus,temp.get('70011')),temp.get('70012'))
temp['70013']=chaji
print("加购图关联表召回stop")
return temp
#return temp
print("ALS相关表召回start",'**'*50)
als_correlation_change_redis=als_correlation_redis.format(sku_no=skuno).strip()
......
......@@ -39,6 +39,24 @@ def minPriceFill(skus,num=100):
return temp[:num]
def execCondition(df,condition,needcolums,orderby=None):
'''
:param df: dataframe格式
:param condition: 字符串,筛选条件
:param needcolums: 字符串,需要从df拿到的字段
:param orderby: 默认dict格式,如果为空,则不排序。
{'ordercolums':XX,'type':XX}.ordercolums表示按照某个字段排序,type表示正排还是倒排
:return: 条件筛选后并返回数据
'''
if orderby:
col=orderby.get('ordercolums')
isasc=orderby.get('type') or 1
return df[eval(condition)].sort_values(by=[col],ascending=isasc)[needcolums].to_list()
else:
return df[eval(condition)][needcolums].to_list()
def skuinfo(sku):
change_sql=concatSql(skuinfo_sql,**{"sku_no":sku})
sku_df=execmysl(119,change_sql)
......
......@@ -3,6 +3,12 @@ dapan_sql='''
select id,sku_no,price,cid1,cid2,cid3,brand_name,brand_id from
offline_recommend.recommend_same_product
'''
##根据cid3获取cid2,cid1等数据
cid1_3_sql="""
select distinct c_id1,c_id2,c_id3 from kdsp.t_sku_info
"""
##商品表
skuinfo_sql='''
select id,sku_no,sku_name,price,cid1,cid2,cid3,brand_name,brand_id,source_type from
......
......@@ -21,9 +21,12 @@ def getseed(top10_sku):
print(sql)
df=execmysl(119,sql)
df['cid3']=df['cid3'].astype('string')
df['brand_id']=df['brand_id'].astype('string')
cid3=df.groupby(by=['cid3']).groups.__repr__()#['cid3']#.max()
brandname=df.groupby(by=['brand_name']).groups.__repr__()
brandid=df.groupby(by=['brand_id']).groups.__repr__()
# print('--',brandid,type(brandid))
# print('--',brandname,type(brandid))
result['cid3']=maxdict(**json.loads(cid3.replace("'",'"')))
result['brand_name']=maxdict(**json.loads(brandname.replace("'",'"')))
result['brand_id']=maxdict(**json.loads(brandid.replace("'",'"')))
......
......@@ -14,7 +14,7 @@ def modifyPasseord(name,namespace):
salt_df=pd.read_sql(get_salt,con=conn_db_11)
temp=salt_df.to_dict(orient='records')
if not temp:
print('[name] is not exist'.format(name=name))
print('[{name}] is not exist'.format(name=name))
return 0
salt=temp[0]['salt'].encode()
#salt=b'UwKESe3cvf703Z30' #t_sys_user.salt
......@@ -28,4 +28,4 @@ def modifyPasseord(name,namespace):
print("this is update")
if __name__ == '__main__':
modifyPasseord('haiyuan.wen','qa')
\ No newline at end of file
modifyPasseord('dong.chao','qa')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment