Commit 59409dca authored by 高雅喆's avatar 高雅喆

pretty output of recommended_indexs

parent 3fcaa79f
......@@ -31,12 +31,13 @@ def get_click_times_to_count_uid_df():
def df2file(df,fpath):
with open(fpath,"w") as f:
tplt = "{0:^10}\t{1:^10}\n"
f.write("#2. Top特征\n")
f.write("=================================================================\n")
f.write("2.1用户点击次数分布(第一列:用户点击次数;第二列:独立用户数量)\n")
f.write("click_times"+"\t"+"count_uid"+"\n")
f.write(tplt.format("click_times","count_uid"))
for row in df.iterrows():
line = str(row[1][0]) + "\t" + str(row[1][1]) + "\n"
line = tplt.format(row[1][0],row[1][1])
f.write(line)
f.write("\n\n")
......
......@@ -15,78 +15,63 @@ def get_yesterday_date():
def result2file(fpath):
with open(fpath,'w') as f:
tplt = "{0:<6}\t{1:^10}\t{2:^10}\t{3:^10}\n"
f.write("#注意:以下数据都是首页的\n")
f.write("#1. 比例特征\n")
f.write("=================================================================\n")
f.write("#1.1answer曝光占比(=answer被曝光数/总cid被曝光数)\n")
f.write("平台"+"\t"+"answer被曝光数"+"\t"+"总cid被曝光数"+"\t"+"answer被曝光数占比\n")
f.write(tplt.format("平台","answer被曝光数","总cid被曝光数","answer被曝光数占比"))
all_answer_imp_rate = get_all_answer_imp_rate()
ios_answer_imp_rate = get_ios_answer_imp_rate()
android_answer_imp_rate = get_android_answer_imp_rate()
lst = [all_answer_imp_rate,ios_answer_imp_rate,android_answer_imp_rate]
for i in lst:
line = ""
for j in i:
line += str(j) + '\t'
line = line[:-1]+'\n'
line = tplt.format(i[0],i[1],i[2],i[3])
f.write(line)
print("1.1已将answer曝光占比存入文件")
f.write("#1.2有点击用户点击率(=有点击用户点击次数/有点击用户曝光次数)\n")
f.write("平台"+"\t"+"有点击用户点击次数"+"\t"+"有点击用户曝光次数"+"\t"+"有点击用户点击率\n")
f.write("#1.2活跃用户点击率(=活跃用户点击次数/活跃用户曝光次数)\n")
f.write(tplt.format("平台","活跃用户点击次数","活跃用户曝光次数","活跃用户点击率"))
all_click_one_rate = get_all_click_one_rate()
ios_click_one_rate = get_ios_click_one_rate()
android_click_one_rate = get_android_click_one_rate()
lst = [all_click_one_rate,ios_click_one_rate,android_click_one_rate]
for i in lst:
line = ""
for j in i:
line += str(j) + '\t'
line = line[:-1]+'\n'
line = tplt.format(i[0],i[1],i[2],i[3])
f.write(line)
print("1.2已将有点击用户点击率存入文件")
print("1.2已将活跃用户点击率存入文件")
f.write("#1.3点击answer用户占比(=点击answer用户数/曝光answer用户数)\n")
f.write("平台"+"\t"+"点击answer用户数"+"\t"+"曝光answer用户数"+"\t"+"点击answer用户占比\n")
f.write(tplt.format("平台","点击answer用户数","曝光answer用户数","击answer用户占比"))
all_click_answer_rate = get_all_click_answer_rate()
ios_click_answer_rate = get_ios_click_answer_rate()
android_click_answer_rate = get_android_click_answer_rate()
lst = [all_click_answer_rate,ios_click_answer_rate,android_click_answer_rate]
for i in lst:
line = ""
for j in i:
line += str(j) + '\t'
line = line[:-1]+'\n'
line = tplt.format(i[0],i[1],i[2],i[3])
f.write(line)
print("1.3已将点击answer用户占比存入文件")
f.write("#1.4点击diary用户占比(=点击diary用户数/曝光diary用户数)\n")
f.write("平台"+"\t"+"点击diary用户数"+"\t"+"曝光diary用户数"+"\t"+"点击diary用户占比\n")
f.write(tplt.format("平台","点击diary用户数","曝光diary用户数","击diary用户占比"))
all_click_diary_rate = get_all_click_diary_rate()
ios_click_diary_rate = get_ios_click_diary_rate()
android_click_diary_rate = get_android_click_diary_rate()
lst = [all_click_diary_rate,ios_click_diary_rate,android_click_diary_rate]
for i in lst:
line = ""
for j in i:
line += str(j) + '\t'
line = line[:-1]+'\n'
line = tplt.format(i[0],i[1],i[2],i[3])
f.write(line)
print("1.4已将点击diary用户占比存入文件")
f.write("#1.5无点击用户占比(=无点击用户数/有曝光用户数)\n")
f.write("平台"+"\t"+"无点击用户数"+"\t"+"有曝光用户数"+"\t"+"无点击用户占比\n")
f.write(tplt.format("平台","无点击用户数","有曝光用户数","无点击用户占比"))
all_click_zero_rate = get_all_click_zero_rate()
ios_click_zero_rate = get_ios_click_zero_rate()
android_click_zero_rate = get_android_click_zero_rate()
lst = [all_click_zero_rate,ios_click_zero_rate,android_click_zero_rate]
for i in lst:
line = ""
for j in i:
line += str(j) + '\t'
line = line[:-1]+'\n'
line = tplt.format(i[0],i[1],i[2],i[3])
f.write(line)
f.write('\n\n')
print("1.5已将无点击用户占比存入文件")
......
......@@ -20,20 +20,16 @@ def tuple2dict(tuple_result):
def result2file(result_lst,fpath):
with open(fpath,'w') as f:
header = "平台"+'\t'+"answer_id"+'\t'+"answer被点击数"+'\t'+"answer被曝光数"+'\t'+"answer被点击率"+'\t'+"answer链接"+'\n'
tplt = "{0:<6}\t{1:<10}\t{2:^10}\t{3:^10}\t{4:^10}\t{5:<10}\n"
f.write("Top 100 Answer\n")
f.write("=================================================================\n")
f.write(header)
f.write(tplt.format("平台","answer_id","answer被点击数","answer被曝光数","answer被点击率","answer链接"))
for i in result_lst:
for j in i:
line = ""
for k in j:
line += str(k) + '\t'
line = line[:-1] + '\n'
f.write(line)
f.write(tplt.format(j[0],j[1],j[2],j[3],j[4],j[5]))
f.write("=================================================================\n")
if i != result_lst[-1]:
f.write(header)
f.write(tplt.format("平台","answer_id","answer被点击数","answer被曝光数","answer被点击率","answer链接"))
f.write("\n\n")
......
......@@ -20,20 +20,16 @@ def tuple2dict(tuple_result):
def result2file(result_lst,fpath):
with open(fpath,'w') as f:
header = "平台"+'\t'+"diary_id"+'\t'+"diary被点击数"+'\t'+"diary被曝光数"+'\t'+"diary被点击率"+'\t'+"diary链接"+'\n'
tplt = "{0:<6}\t{1:<10}\t{2:^10}\t{3:^10}\t{4:^10}\t{5:<10}\n"
f.write("Top 100 diary\n")
f.write("=================================================================\n")
f.write(header)
f.write(tplt.format("平台","diary_id","diary被点击数","diary被曝光数","diary被点击率","diary链接"))
for i in result_lst:
for j in i:
line = ""
for k in j:
line += str(k) + '\t'
line = line[:-1] + '\n'
f.write(line)
f.write(tplt.format(j[0],j[1],j[2],j[3],j[4],j[5]))
f.write("=================================================================\n")
if i != result_lst[-1]:
f.write(header)
f.write(tplt.format("平台","diary_id","diary被点击数","diary被曝光数","diary被点击率","diary链接"))
f.write("\n\n")
......
......@@ -20,20 +20,16 @@ def tuple2dict(tuple_result):
def result2file(result_lst,fpath):
with open(fpath,'w') as f:
header = "平台"+'\t'+"question_id"+'\t'+"question被点击数"+'\t'+"question被曝光数"+'\t'+"question被点击率"+'\t'+"question链接"+'\n'
f.write("Top 100 question\n")
tplt = "{0:<6}\t{1:<10}\t{2:^10}\t{3:^10}\t{4:^10}\t{5:<10}\n"
f.write("Top 100 Question\n")
f.write("=================================================================\n")
f.write(header)
f.write(tplt.format("平台","question_id","question被点击数","question被曝光数","question被点击率","question链接"))
for i in result_lst:
for j in i:
line = ""
for k in j:
line += str(k) + '\t'
line = line[:-1] + '\n'
f.write(line)
f.write(tplt.format(j[0],j[1],j[2],j[3],j[4],j[5]))
f.write("=================================================================\n")
if i != result_lst[-1]:
f.write(header)
f.write(tplt.format("平台","question_id","question被点击数","question被曝光数","question被点击率","question链接"))
f.write("\n\n")
......
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