Commit 399e04ee authored by 高雅喆's avatar 高雅喆

add a foo to transform tuple2

parent 021a4e92
......@@ -128,11 +128,22 @@ def get_rate_detail(platform):
db.close()
return result
def result2dict(result):
"""
result : tuple2
rtype : dict
"""
dct = {}
sum_count = 0
for i in result:
sum_count += i[1]
for i in result:
dct[i[0]] = "{}%".format(round(i[1]/sum_count*100,2))
return dct
no_click_uid_detail_all = get_rate_detail("all")
no_click_uid_detail_ios = get_rate_detail("ios")
no_click_uid_detail_android = get_rate_detail("android")
no_click_uid_detail_all = result2dict(get_rate_detail("all"))
no_click_uid_detail_ios = result2dict(get_rate_detail("ios"))
no_click_uid_detail_android = result2dict(get_rate_detail("android"))
......
......@@ -48,7 +48,7 @@ def result2file(fpath):
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 = tplt.format(i[0],i[1],i[2],"{}%".format(i[3]*100))
line = tplt.format(i[0],i[1],i[2],"{}%".format(round(i[3]*100,2)))
f.write(line)
f.write('\n')
print("1.1已将answer曝光占比存入文件")
......@@ -60,7 +60,7 @@ def result2file(fpath):
android_diary_imp_rate = get_android_diary_imp_rate()
lst = [all_diary_imp_rate,ios_diary_imp_rate,android_diary_imp_rate]
for i in lst:
line = tplt.format(i[0],i[1],i[2],"{}%".format(i[3]*100))
line = tplt.format(i[0],i[1],i[2],"{}%".format(round(i[3]*100,2)))
f.write(line)
f.write('\n')
print("1.2已将diary曝光占比存入文件")
......@@ -72,7 +72,7 @@ def result2file(fpath):
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 = tplt.format(i[0],i[1],i[2],"{}%".format(i[3]*100))
line = tplt.format(i[0],i[1],i[2],"{}%".format(round(i[3]*100,2)))
f.write(line)
f.write('\n')
print("1.3已将活跃用户点击率存入文件")
......@@ -84,7 +84,7 @@ def result2file(fpath):
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 = tplt.format(i[0],i[1],i[2],"{}%".format(i[3]*100))
line = tplt.format(i[0],i[1],i[2],"{}%".format(round(i[3]*100,2)))
f.write(line)
f.write('\n')
print("1.5已将点击answer用户占比存入文件")
......@@ -96,7 +96,7 @@ def result2file(fpath):
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 = tplt.format(i[0],i[1],i[2],"{}%".format(i[3]*100))
line = tplt.format(i[0],i[1],i[2],"{}%".format(round(i[3]*100,2)))
f.write(line)
f.write('\n')
print("1.6已将点击diary用户占比存入文件")
......@@ -108,7 +108,7 @@ def result2file(fpath):
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 = tplt.format(i[0],i[1],i[2],"{}%".format(i[3]*100))
line = tplt.format(i[0],i[1],i[2],"{}%".format(round(i[3]*100,2)))
f.write(line)
f.write('\n')
print("1.7已将无点击用户占比存入文件")
......
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