Commit 64fa9ca5 authored by 高雅喆's avatar 高雅喆

getTopFeatures.py/get_result reduce args

parent 5f2f7a0b
...@@ -42,7 +42,7 @@ class TopFeatures(object): ...@@ -42,7 +42,7 @@ class TopFeatures(object):
imp_times = tuple2dict(con_sql(sql)) imp_times = tuple2dict(con_sql(sql))
return imp_times return imp_times
def get_result(self, platform, clk={}, imp={}, clk_n=2, result_types="ctr"): def get_result(self, platform, clk_n=2, result_types="ctr"):
""" """
platform : "所有";"苹果","安卓" #方便显示 platform : "所有";"苹果","安卓" #方便显示
cid_type : 'diary';'answer';'question';"everything"... #方便显示 cid_type : 'diary';'answer';'question';"everything"... #方便显示
...@@ -52,6 +52,8 @@ class TopFeatures(object): ...@@ -52,6 +52,8 @@ class TopFeatures(object):
result_types : sorted by ["clk","imp","ctr"] result_types : sorted by ["clk","imp","ctr"]
rtype : list rtype : list
""" """
clk = self.get_click_times()
imp = self.get_impression_times()
topn = [] topn = []
#获取topN的点击 #获取topN的点击
if imp == {} or result_types == "clk": if imp == {} or result_types == "clk":
...@@ -87,7 +89,6 @@ class TopFeatures(object): ...@@ -87,7 +89,6 @@ class TopFeatures(object):
def result2file(self, result_lst, fpath): def result2file(self, result_lst, fpath):
""" """
cid_type : 'diary';'answer';'question';"everything"... #方便显示
result_lst : [all_result,ios_result,android_result] result_lst : [all_result,ios_result,android_result]
fpath : output filename fpath : output filename
rtype : none rtype : none
...@@ -115,19 +116,13 @@ def main(): ...@@ -115,19 +116,13 @@ def main():
#1. Top diary #1. Top diary
top_diary_all = TopFeatures("all", "diary", 100) top_diary_all = TopFeatures("all", "diary", 100)
clk_diary_times_all = top_diary_all.get_click_times() clk_diary_ctr_all = top_diary_all.get_result("所有", 4, "ctr")
imp_diary_times_all = top_diary_all.get_impression_times()
clk_diary_ctr_all = top_diary_all.get_result("所有",clk_diary_times_all, imp_diary_times_all, 4, "ctr")
top_diary_ios = TopFeatures("ios", "diary", 100) top_diary_ios = TopFeatures("ios", "diary", 100)
clk_diary_times_ios = top_diary_ios.get_click_times() clk_diary_ctr_ios = top_diary_ios.get_result("苹果", 4, "ctr")
imp_diary_times_ios = top_diary_ios.get_impression_times()
clk_diary_ctr_ios = top_diary_ios.get_result("苹果",clk_diary_times_ios, imp_diary_times_ios, 4, "ctr")
top_diary_android = TopFeatures("android", "diary", 100) top_diary_android = TopFeatures("android", "diary", 100)
clk_diary_times_android = top_diary_android.get_click_times() clk_diary_ctr_android = top_diary_android.get_result("安卓", 4, "ctr")
imp_diary_times_android = top_diary_android.get_impression_times()
clk_diary_ctr_android = top_diary_android.get_result("安卓",clk_diary_times_android, imp_diary_times_android, 4, "ctr")
result_lst = [clk_diary_ctr_all, clk_diary_ctr_ios, clk_diary_ctr_android] result_lst = [clk_diary_ctr_all, clk_diary_ctr_ios, clk_diary_ctr_android]
output_path = DIRECTORY_PATH + "top100_ctr_diary_{}.txt".format(get_yesterday_date()) output_path = DIRECTORY_PATH + "top100_ctr_diary_{}.txt".format(get_yesterday_date())
...@@ -136,19 +131,13 @@ def main(): ...@@ -136,19 +131,13 @@ def main():
#2. Top answer #2. Top answer
top_answer_all = TopFeatures("all", "answer", 100) top_answer_all = TopFeatures("all", "answer", 100)
clk_answer_times_all = top_answer_all.get_click_times() clk_answer_ctr_all = top_answer_all.get_result("所有", 2, "ctr")
imp_answer_times_all = top_answer_all.get_impression_times()
clk_answer_ctr_all = top_answer_all.get_result("所有",clk_answer_times_all, imp_answer_times_all, 2, "ctr")
top_answer_ios = TopFeatures("ios", "answer", 100) top_answer_ios = TopFeatures("ios", "answer", 100)
clk_answer_times_ios = top_answer_ios.get_click_times() clk_answer_ctr_ios = top_answer_ios.get_result("苹果", 2, "ctr")
imp_answer_times_ios = top_answer_ios.get_impression_times()
clk_answer_ctr_ios = top_answer_ios.get_result("苹果",clk_answer_times_ios, imp_answer_times_ios, 2, "ctr")
top_answer_android = TopFeatures("android", "answer", 100) top_answer_android = TopFeatures("android", "answer", 100)
clk_answer_times_android = top_answer_android.get_click_times() clk_answer_ctr_android = top_answer_android.get_result("安卓", 2, "ctr")
imp_answer_times_android = top_answer_android.get_impression_times()
clk_answer_ctr_android = top_answer_android.get_result("安卓",clk_answer_times_android, imp_answer_times_android, 2, "ctr")
result_lst = [clk_answer_ctr_all, clk_answer_ctr_ios, clk_answer_ctr_android] result_lst = [clk_answer_ctr_all, clk_answer_ctr_ios, clk_answer_ctr_android]
output_path = DIRECTORY_PATH + "top100_ctr_answer_{}.txt".format(get_yesterday_date()) output_path = DIRECTORY_PATH + "top100_ctr_answer_{}.txt".format(get_yesterday_date())
...@@ -158,19 +147,13 @@ def main(): ...@@ -158,19 +147,13 @@ def main():
#3. Top question #3. Top question
top_question_all = TopFeatures("all", "question", 100) top_question_all = TopFeatures("all", "question", 100)
clk_question_times_all = top_question_all.get_click_times() clk_question_ctr_all = top_question_all.get_result("所有", 2, "ctr")
imp_question_times_all = top_question_all.get_impression_times()
clk_question_ctr_all = top_question_all.get_result("所有",clk_question_times_all, imp_question_times_all, 2, "ctr")
top_question_ios = TopFeatures("ios", "question", 100) top_question_ios = TopFeatures("ios", "question", 100)
clk_question_times_ios = top_question_ios.get_click_times() clk_question_ctr_ios = top_question_ios.get_result("苹果", 2, "ctr")
imp_question_times_ios = top_question_ios.get_impression_times()
clk_question_ctr_ios = top_question_ios.get_result("苹果",clk_question_times_ios, imp_question_times_ios, 2, "ctr")
top_question_android = TopFeatures("android", "question", 100) top_question_android = TopFeatures("android", "question", 100)
clk_question_times_android = top_question_android.get_click_times() clk_question_ctr_android = top_question_android.get_result("安卓", 2, "ctr")
imp_question_times_android = top_question_android.get_impression_times()
clk_question_ctr_android = top_question_android.get_result("安卓",clk_question_times_android, imp_question_times_android, 2, "ctr")
result_lst = [clk_question_ctr_all, clk_question_ctr_ios, clk_question_ctr_android] result_lst = [clk_question_ctr_all, clk_question_ctr_ios, clk_question_ctr_android]
output_path = DIRECTORY_PATH + "top100_ctr_question_{}.txt".format(get_yesterday_date()) output_path = DIRECTORY_PATH + "top100_ctr_question_{}.txt".format(get_yesterday_date())
......
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