From 2110d8fd7f80cd1a80bfe81bbfdc97194d850281 Mon Sep 17 00:00:00 2001 From: pengtao Date: Mon, 30 Sep 2019 14:07:36 +0800 Subject: [PATCH] fix bug --- get_new_user.py | 73 ++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/get_new_user.py b/get_new_user.py index ce822be..022dcaa 100644 --- a/get_new_user.py +++ b/get_new_user.py @@ -56,45 +56,45 @@ class InitFirstAD(): return ratios - def get_ad_channel(self): - sql = f"""SELECT - DISTINCT first_ad_channel - FROM - v_user_{self.suffix} - where - gameid='{self.gameid}'""" - temp = [] - data = self.tga.get_data(sql) - if data: - for line in data: - try: - temp.append(line[0]) - except Exception: - log.error(f"split data {line} failed", exc_info=True) - return temp + # def get_ad_channel(self): + # sql = f"""SELECT + # DISTINCT first_ad_channel + # FROM + # v_user_{self.suffix} + # where + # gameid='{self.gameid}'""" + # temp = [] + # data = self.tga.get_data(sql) + # if data: + # for line in data: + # try: + # temp.append(line[0]) + # except Exception: + # log.error(f"split data {line} failed", exc_info=True) + # return temp def run(self): ad_channels = self.get_ad_channel() - for ad_channel in ad_channels: - ratio = self.ratio.get('ad_channel', 100) - begin = self.get_last_times(ad_channel) - users = self.get_new_user(begin,ad_channel) - #print(f"get {users} with {ad_channel} ") - if users: - mark_users = self.hide_user(users, ratio) - table_name = "newuser" - if mark_users: - log.info(f"gameid={self.gameid},channel={self.channelid},ad_channel={ad_channel},begin={begin},get users {len(users)},write {len(mark_users)} to mysql!") - for line in mark_users: - try: - temp = {} - temp['gameid'] = self.gameid - temp['channelid'] = self.channelid - temp['accountid'], temp['register_time'], temp['ad_channel'] = line - self.mysql.insert(table_name, temp) - except Exception: - log.error(f"insert {line} to mysql Failed !", exc_info=True) + if self.ratio: + for ad_channel in self.ratio.keys(): + ratio = self.ratio.get(ad_channel, 100) + begin = self.get_last_times(ad_channel) + users = self.get_new_user(begin,ad_channel) + if users: + mark_users = self.hide_user(users, ratio) + table_name = "newuser" + if mark_users: + log.info(f"gameid={self.gameid},channel={self.channelid},ad_channel={ad_channel},ratio={ratio},begin={begin},get users {len(users)},write {len(mark_users)} to mysql!") + for line in mark_users: + try: + temp = {} + temp['gameid'] = self.gameid + temp['channelid'] = self.channelid + temp['accountid'], temp['register_time'], temp['ad_channel'] = line + self.mysql.insert(table_name, temp) + except Exception: + log.error(f"insert {line} to mysql Failed !", exc_info=True) def get_last_times(self, ad_channel): sql = f"""SELECT register_time FROM newuser where ad_channel='{ad_channel}' AND gameid={self.gameid} AND @@ -107,7 +107,6 @@ class InitFirstAD(): try: last_time = data[0][0] except Exception: - #log.error("get last time error!", exc_info=True) last_time = "1999-09-09 00:00:00" return last_time @@ -116,8 +115,6 @@ class InitFirstAD(): if data: line = len(data) nums = int(line * ratio / 100) - if int(ratio) != int(100): - print(f"all={line} nums={nums} ratio={ratio}") if nums: return random.sample(data, nums) else: