Commit 0f7d0c23 authored by 桂秋月's avatar 桂秋月

新增简单版打分

parent 676c0ac4
...@@ -13,8 +13,11 @@ def requestsend(uuid,deviceid,searchContent,selectedActivitie,page=1,searchtype= ...@@ -13,8 +13,11 @@ def requestsend(uuid,deviceid,searchContent,selectedActivitie,page=1,searchtype=
:param env: 环境 :param env: 环境
:return: :return:
""" """
if env not in ['test','pro']: if env not in ['test','pro','online']:
raise Exception('env[{}]只能:test|pro'.format(env)) raise Exception('env[{}]只能:test|pro'.format(env))
if env=='online':
baseurl="http://caesar-gateway.q-gp.com"
else:
baseurl="http://open-search-engine.ec-{env}.qg-rc.net".format(env=env) if env=='test' \ baseurl="http://open-search-engine.ec-{env}.qg-rc.net".format(env=env) if env=='test' \
else "http://open-search-engine.qg-{env}.qgwebservice.com".format(env=env) else "http://open-search-engine.qg-{env}.qgwebservice.com".format(env=env)
url=baseurl+"/search" url=baseurl+"/search"
...@@ -68,12 +71,15 @@ def requestsend(uuid,deviceid,searchContent,selectedActivitie,page=1,searchtype= ...@@ -68,12 +71,15 @@ def requestsend(uuid,deviceid,searchContent,selectedActivitie,page=1,searchtype=
page_size = jsonpath.jsonpath(t.json(), '$..totalPage')[0] page_size = jsonpath.jsonpath(t.json(), '$..totalPage')[0]
search_id = jsonpath.jsonpath(t.json(), '$..searchId')[0] search_id = jsonpath.jsonpath(t.json(), '$..searchId')[0]
total_skus=jsonpath.jsonpath(t.json(), '$..totalCount')[0] total_skus=jsonpath.jsonpath(t.json(), '$..totalCount')[0]
cid3s=jsonpath.jsonpath(t.json(), '$..cid3') or ['null']
brandnames=jsonpath.jsonpath(t.json(), '$..brandId') or ['null']
request_time = t.elapsed.total_seconds() request_time = t.elapsed.total_seconds()
tttt=','.join(spu_nos) tttt=','.join(spu_nos)
#print(tttt,type(tttt)) #print(tttt,type(tttt))
# with open('sku_result_3.txt', 'a+') as file: # with open('sku_result_3.txt', 'a+') as file:
# file.write('搜索词:' + searchContent + ";result:" + ','.join(sku_names) + "\n") # file.write('搜索词:' + searchContent + ";result:" + ','.join(sku_names) + "\n")
return page_size, ','.join(spu_nos), str(request_time), search_id,','.join(sku_names),searchContent,total_skus return page_size, ','.join(spu_nos), str(request_time), search_id,','.join(sku_names),searchContent,\
total_skus,cid3s,brandnames
except: except:
print('搜索接口报错:',searchContent,t.text) print('搜索接口报错:',searchContent,t.text)
...@@ -107,7 +113,7 @@ def totalrun(selectedActivitie=1, type='txt', num=0,isFirstPage=False,sheetname= ...@@ -107,7 +113,7 @@ def totalrun(selectedActivitie=1, type='txt', num=0,isFirstPage=False,sheetname=
flag=1 flag=1
try: try:
page_size, spu_nos, \ page_size, spu_nos, \
request_time, search_id,sku_names,searchContent,total_skus=\ request_time, search_id,sku_names,searchContent,total_skus,*info=\
requestsend(uuid,deviceid,searchContents[random_value],selectedActivitie,flag,type) requestsend(uuid,deviceid,searchContents[random_value],selectedActivitie,flag,type)
result_temp["nowtime"]=str(timenow) result_temp["nowtime"]=str(timenow)
result_temp["deviceid"]=deviceid result_temp["deviceid"]=deviceid
...@@ -123,7 +129,7 @@ def totalrun(selectedActivitie=1, type='txt', num=0,isFirstPage=False,sheetname= ...@@ -123,7 +129,7 @@ def totalrun(selectedActivitie=1, type='txt', num=0,isFirstPage=False,sheetname=
while flag<=page_size and not isFirstPage: while flag<=page_size and not isFirstPage:
result_temp={} result_temp={}
page_size, spu_nos, \ page_size, spu_nos, \
request_time, search_id,sku_names,searchContent= \ request_time, search_id,sku_names,searchContent,total_skus,*info= \
requestsend(uuid,deviceid,searchContents[random_value],selectedActivitie,flag,type) requestsend(uuid,deviceid,searchContents[random_value],selectedActivitie,flag,type)
result_temp["nowtime"]=timenow result_temp["nowtime"]=timenow
result_temp["searchcontent"]=searchContent result_temp["searchcontent"]=searchContent
......
from search import *
from search.abSearch import requestsend
def fileData():
fcolums=['id','query','expect_cid3','commit']
filename=os.path.join(data_file_path,'Top1000关键词测评.xlsx')
df=readRenameColums(filename,fcolums)
df['commit']=df['commit'].fillna(9999)
return df
def compareResult():
df=fileData()
temp_score=[]
for i in df.itertuples():
print(i)
id=i.__getattribute__('Index')
query_context=i.__getattribute__('query')
expect_cid3=str(i.__getattribute__('expect_cid3'))
commit=i.__getattribute__('commit')
temp_expect_cid3=expect_cid3.split(',') if expect_cid3 else []
uuid,deviceid=genUuidDeviceid()
# uuid,deviceid,searchContent,selectedActivitie,page=1,searchtype='txt',env='pro'
*info,cid3s,brandnames=\
requestsend(uuid,deviceid,query_context,selectedActivitie=1,page=1,env='pro')
if commit=='1' or commit==1:
score=[1 for i in temp_expect_cid3 if i in brandnames ]
temp_score.append(score)
df.loc[id,'score']=sum(score)
try:
df.loc[id,'actual_cid3']=','.join(brandnames)
except:
#print(brandnames,type(brandnames))
brandnames=[str(i) for i in brandnames]
df.loc[id,'actual_cid3']=','.join(brandnames)
elif commit=='9999' or commit==9999:
score=[1 for i in temp_expect_cid3 if i in cid3s or str(i) in cid3s]
print('比对得分',score)
#print(score,id,type(id),df.loc(id))
#temp_score.append(score)
df.loc[id,'score']=sum(score)
df.loc[id,'actual_cid3']=','.join(cid3s)
#df.iloc[0,'score']=sum(score)
#i.__setattr__('score',sum(score))
else:
df.loc[id,'score']=0
#df['score']=temp_score
return df
def saveResult():
df=compareResult()
reportname=filePath(file_path,'compareResult')
#df['skunos']=df['skunos'].astype('string')
df.to_excel(reportname,index=0,encoding = 'utf-8')
def anasfile(filename=None):
result=[]
filename=filename if filename \
else os.popen("cd {};ls -t |grep -v 'init' |head -1".format(file_path)).read(100)
filename_path=os.path.join(file_path,filename.strip())
print('解析文件名:',filename_path)
df=readFile(filename_path)
temp_df=df[(df['commit']!=2) &(~ df['expect_cid3'].isna()) &(~ df['expect_cid3'].isna())]
temp_df['expect_cid3_len']=(temp_df['expect_cid3'].astype(str)+',').str.split(',')
print('有效数据总数,',temp_df.shape[0])
temp_df['final_score']=temp_df['score']/(temp_df['expect_cid3_len'].apply(len)-1)
print("准确率",temp_df['final_score'].mean())
print('通过率',temp_df[temp_df['final_score']>0.6]['final_score'].mean())
print('无效数据总数',df[(df['commit']==2) | (df['commit']=='2')].shape[0])
print('实际结果和预期结果都为空的总数',df[(df['commit']!=2) & ((df['expect_cid3'].isna()) | ( df['expect_cid3'].isna()))].shape[0])
#round(df['score']/df['expect_cid3'].str.split(','),2)
#print(temp_df['final_score'].head(2))
reportname=filePath(file_path,'final_result')
#df['skunos']=df['skunos'].astype('string')
temp_df.to_excel(reportname,index=0,encoding = 'utf-8')
if __name__ == '__main__':
#print(saveResult())
print('1112',anasfile())
\ No newline at end of file
...@@ -28,4 +28,4 @@ def modifyPasseord(name,namespace): ...@@ -28,4 +28,4 @@ def modifyPasseord(name,namespace):
print("this is update") print("this is update")
if __name__ == '__main__': if __name__ == '__main__':
modifyPasseord('chao.dong','vcc3') modifyPasseord('haiyuan.wen','qa')
\ No newline at end of file \ No newline at end of file
...@@ -5,7 +5,7 @@ def genUuidDeviceid(): ...@@ -5,7 +5,7 @@ def genUuidDeviceid():
:return: :return:
""" """
uuid,deviced=codeuuid.uuid4().urn.split(':')[-1],codeuuid.uuid4().urn.split(':')[-1] uuid,deviced=codeuuid.uuid4().urn.split(':')[-1],codeuuid.uuid4().urn.split(':')[-1]
uuid='c0c27ffb-f2da-4650-8855-2da2191ce772' #uuid='c0c27ffb-f2da-4650-8855-2da2191ce772'
deviced='guiqiuyue_'+str(deviced) deviced='guiqiuyue_'+str(deviced)
return uuid,deviced return uuid,deviced
......
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