fix bug
This commit is contained in:
parent
4160d63518
commit
2110d8fd7f
@ -56,45 +56,45 @@ class InitFirstAD():
|
|||||||
return ratios
|
return ratios
|
||||||
|
|
||||||
|
|
||||||
def get_ad_channel(self):
|
# def get_ad_channel(self):
|
||||||
sql = f"""SELECT
|
# sql = f"""SELECT
|
||||||
DISTINCT first_ad_channel
|
# DISTINCT first_ad_channel
|
||||||
FROM
|
# FROM
|
||||||
v_user_{self.suffix}
|
# v_user_{self.suffix}
|
||||||
where
|
# where
|
||||||
gameid='{self.gameid}'"""
|
# gameid='{self.gameid}'"""
|
||||||
temp = []
|
# temp = []
|
||||||
data = self.tga.get_data(sql)
|
# data = self.tga.get_data(sql)
|
||||||
if data:
|
# if data:
|
||||||
for line in data:
|
# for line in data:
|
||||||
try:
|
# try:
|
||||||
temp.append(line[0])
|
# temp.append(line[0])
|
||||||
except Exception:
|
# except Exception:
|
||||||
log.error(f"split data {line} failed", exc_info=True)
|
# log.error(f"split data {line} failed", exc_info=True)
|
||||||
return temp
|
# return temp
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
ad_channels = self.get_ad_channel()
|
ad_channels = self.get_ad_channel()
|
||||||
for ad_channel in ad_channels:
|
if self.ratio:
|
||||||
ratio = self.ratio.get('ad_channel', 100)
|
for ad_channel in self.ratio.keys():
|
||||||
begin = self.get_last_times(ad_channel)
|
ratio = self.ratio.get(ad_channel, 100)
|
||||||
users = self.get_new_user(begin,ad_channel)
|
begin = self.get_last_times(ad_channel)
|
||||||
#print(f"get {users} with {ad_channel} ")
|
users = self.get_new_user(begin,ad_channel)
|
||||||
if users:
|
if users:
|
||||||
mark_users = self.hide_user(users, ratio)
|
mark_users = self.hide_user(users, ratio)
|
||||||
table_name = "newuser"
|
table_name = "newuser"
|
||||||
if mark_users:
|
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!")
|
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:
|
for line in mark_users:
|
||||||
try:
|
try:
|
||||||
temp = {}
|
temp = {}
|
||||||
temp['gameid'] = self.gameid
|
temp['gameid'] = self.gameid
|
||||||
temp['channelid'] = self.channelid
|
temp['channelid'] = self.channelid
|
||||||
temp['accountid'], temp['register_time'], temp['ad_channel'] = line
|
temp['accountid'], temp['register_time'], temp['ad_channel'] = line
|
||||||
self.mysql.insert(table_name, temp)
|
self.mysql.insert(table_name, temp)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error(f"insert {line} to mysql Failed !", exc_info=True)
|
log.error(f"insert {line} to mysql Failed !", exc_info=True)
|
||||||
|
|
||||||
def get_last_times(self, ad_channel):
|
def get_last_times(self, ad_channel):
|
||||||
sql = f"""SELECT register_time FROM newuser where ad_channel='{ad_channel}' AND gameid={self.gameid} AND
|
sql = f"""SELECT register_time FROM newuser where ad_channel='{ad_channel}' AND gameid={self.gameid} AND
|
||||||
@ -107,7 +107,6 @@ class InitFirstAD():
|
|||||||
try:
|
try:
|
||||||
last_time = data[0][0]
|
last_time = data[0][0]
|
||||||
except Exception:
|
except Exception:
|
||||||
#log.error("get last time error!", exc_info=True)
|
|
||||||
last_time = "1999-09-09 00:00:00"
|
last_time = "1999-09-09 00:00:00"
|
||||||
return last_time
|
return last_time
|
||||||
|
|
||||||
@ -116,8 +115,6 @@ class InitFirstAD():
|
|||||||
if data:
|
if data:
|
||||||
line = len(data)
|
line = len(data)
|
||||||
nums = int(line * ratio / 100)
|
nums = int(line * ratio / 100)
|
||||||
if int(ratio) != int(100):
|
|
||||||
print(f"all={line} nums={nums} ratio={ratio}")
|
|
||||||
if nums:
|
if nums:
|
||||||
return random.sample(data, nums)
|
return random.sample(data, nums)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user