Commit ce50f559 authored by 高雅喆's avatar 高雅喆

fix bug in stat_date sql

parent 9fbc4300
...@@ -23,12 +23,12 @@ class CidRate(object): ...@@ -23,12 +23,12 @@ class CidRate(object):
rtype : list rtype : list
""" """
sql_cid = "select count(cid) from data_feed_click2 \ sql_cid = "select count(cid) from data_feed_click2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1} \ and device_type{1} \
and cid_type='{2}'".format(get_yesterday_date(),self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform,self.cid_type) and cid_type='{2}'".format(get_yesterday_date(),self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform,self.cid_type)
cid_clk_count = con_sql(sql_cid)[0][0] cid_clk_count = con_sql(sql_cid)[0][0]
sql_all = "select count(cid) from data_feed_click2 \ sql_all = "select count(cid) from data_feed_click2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1}".format(get_yesterday_date(), self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform) and device_type{1}".format(get_yesterday_date(), self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform)
all_clk_count = con_sql(sql_all)[0][0] all_clk_count = con_sql(sql_all)[0][0]
cid_clk_rate = round(cid_clk_count/all_clk_count,4) cid_clk_rate = round(cid_clk_count/all_clk_count,4)
...@@ -41,11 +41,11 @@ class CidRate(object): ...@@ -41,11 +41,11 @@ class CidRate(object):
rtype : list rtype : list
""" """
sql_cid = "select count(cid) from data_feed_exposure2 \ sql_cid = "select count(cid) from data_feed_exposure2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1} and cid_type='{2}'".format(get_yesterday_date(),self.platform,self.cid_type) and device_type{1} and cid_type='{2}'".format(get_yesterday_date(),self.platform,self.cid_type)
cid_imp_count = con_sql(sql_cid)[0][0] cid_imp_count = con_sql(sql_cid)[0][0]
sql_all = "select count(cid) from data_feed_exposure2 \ sql_all = "select count(cid) from data_feed_exposure2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1}".format(get_yesterday_date(), self.platform) and device_type{1}".format(get_yesterday_date(), self.platform)
all_imp_count = con_sql(sql_all)[0][0] all_imp_count = con_sql(sql_all)[0][0]
cid_imp_rate = round(cid_imp_count/all_imp_count,4) cid_imp_rate = round(cid_imp_count/all_imp_count,4)
......
...@@ -25,13 +25,13 @@ class ClkCidUidRate(object): ...@@ -25,13 +25,13 @@ class ClkCidUidRate(object):
rtype : list rtype : list
""" """
sql_clk = "select count(distinct(device_id)) from data_feed_click2 \ sql_clk = "select count(distinct(device_id)) from data_feed_click2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1} \ and device_type{1} \
and cid_type{2}".format(get_yesterday_date(),self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform,self.cid_type) and cid_type{2}".format(get_yesterday_date(),self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform,self.cid_type)
clk_count = con_sql(sql_clk)[0][0] clk_count = con_sql(sql_clk)[0][0]
sql_imp = "select count(distinct(device_id)) from data_feed_exposure2 \ sql_imp = "select count(distinct(device_id)) from data_feed_exposure2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1} \ and device_type{1} \
and cid_type{2}".format(get_yesterday_date(),self.platform,self.cid_type) and cid_type{2}".format(get_yesterday_date(),self.platform,self.cid_type)
imp_count = con_sql(sql_imp)[0][0] imp_count = con_sql(sql_imp)[0][0]
......
...@@ -17,14 +17,14 @@ def get_activate_uid_ctr(platform): ...@@ -17,14 +17,14 @@ def get_activate_uid_ctr(platform):
else: else:
platform = " is not null" platform = " is not null"
sql_clk = "select count(device_id) from data_feed_click2 \ sql_clk = "select count(device_id) from data_feed_click2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1}".format(get_yesterday_date(), platform.replace(' ','') if platform[-2]=='e' else platform) and device_type{1}".format(get_yesterday_date(), platform.replace(' ','') if platform[-2]=='e' else platform)
clk_count = con_sql(sql_clk)[0][0] clk_count = con_sql(sql_clk)[0][0]
sql_imp = "select count(device_id) from data_feed_exposure2 \ sql_imp = "select count(device_id) from data_feed_exposure2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_id in \ and device_id in \
(select device_id from data_feed_click2 \ (select device_id from data_feed_click2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1}) \ and device_type{1}) \
and device_type{2}".format(get_yesterday_date(), platform.replace(' ','') if platform[-2]=='e' else platform, platform) and device_type{2}".format(get_yesterday_date(), platform.replace(' ','') if platform[-2]=='e' else platform, platform)
imp_count = con_sql(sql_imp)[0][0] imp_count = con_sql(sql_imp)[0][0]
...@@ -48,15 +48,15 @@ def get_activate_uid_imp_times(city): ...@@ -48,15 +48,15 @@ def get_activate_uid_imp_times(city):
else: else:
city = " is not null" city = " is not null"
sql_uid = "select count(distinct(device_id)) from data_feed_click2 \ sql_uid = "select count(distinct(device_id)) from data_feed_click2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and city_id{1}".format(get_yesterday_date(),city) and city_id{1}".format(get_yesterday_date(),city)
sql_uid_count = con_sql(sql_uid)[0][0] sql_uid_count = con_sql(sql_uid)[0][0]
sql_imp = "select count(device_id) from data_feed_exposure2 \ sql_imp = "select count(device_id) from data_feed_exposure2 \
where device_id in \ where device_id in \
(select device_id from data_feed_click2 \ (select device_id from data_feed_click2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and city_id{1}) \ and city_id{1}) \
and stat_date > '{0}' \ and stat_date = '{0}' \
and city_id{1}".format(get_yesterday_date(),city) and city_id{1}".format(get_yesterday_date(),city)
sql_imp_times = con_sql(sql_imp)[0][0] sql_imp_times = con_sql(sql_imp)[0][0]
if city == "='beijing'": if city == "='beijing'":
......
...@@ -23,7 +23,7 @@ class TopFeatures(object): ...@@ -23,7 +23,7 @@ class TopFeatures(object):
def get_click_times(self): def get_click_times(self):
# rtype : dict # rtype : dict
sql = "select cid,count(cid) from data_feed_click2 \ sql = "select cid,count(cid) from data_feed_click2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1} and cid_type='{2}' \ and device_type{1} and cid_type='{2}' \
group by cid \ group by cid \
order by count(cid) desc".format(get_yesterday_date(), self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform, self.cid_type) order by count(cid) desc".format(get_yesterday_date(), self.platform.replace(' ','') if self.platform[-2]=='e' else self.platform, self.cid_type)
...@@ -34,7 +34,7 @@ class TopFeatures(object): ...@@ -34,7 +34,7 @@ class TopFeatures(object):
def get_impression_times(self): def get_impression_times(self):
# rtype : dict # rtype : dict
sql = "select cid,count(cid) from data_feed_exposure2 \ sql = "select cid,count(cid) from data_feed_exposure2 \
where stat_date > '{0}' \ where stat_date = '{0}' \
and device_type{1} and cid_type='{2}' \ and device_type{1} and cid_type='{2}' \
group by cid order by count(cid) desc".format(get_yesterday_date(), self.platform, self.cid_type) group by cid order by count(cid) desc".format(get_yesterday_date(), self.platform, self.cid_type)
imp_times = tuple2dict(con_sql(sql)) imp_times = tuple2dict(con_sql(sql))
......
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