采集新用户脚本 添加显示比例获取数据
This commit is contained in:
parent
c3ed6ff789
commit
6b71e73679
@ -6,13 +6,14 @@ import logging
|
|||||||
import datetime
|
import datetime
|
||||||
from ops.mmysql import MysqlBase
|
from ops.mmysql import MysqlBase
|
||||||
import random
|
import random
|
||||||
|
import requests
|
||||||
import pdb
|
import pdb
|
||||||
define_logger("/data/logs/init_first_ad_channel.log")
|
define_logger("/data/logs/init_first_ad_channel.log")
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
TimeDelay = 60*60
|
TimeDelay = 60*60
|
||||||
|
|
||||||
DB = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'games_report'}
|
# DB = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'games_report'}
|
||||||
|
DB = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'test'}
|
||||||
|
|
||||||
|
|
||||||
class InitFirstAD():
|
class InitFirstAD():
|
||||||
@ -22,6 +23,7 @@ class InitFirstAD():
|
|||||||
# minutes=TimeDelay)).strftime('%Y-%m-%d %H:%M:%S')
|
# minutes=TimeDelay)).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
self.gameid = kwargs.get('gameid')
|
self.gameid = kwargs.get('gameid')
|
||||||
self.channelid = kwargs.get('channelid')
|
self.channelid = kwargs.get('channelid')
|
||||||
|
self.ratio = self.get_ratio()
|
||||||
g = GetTgaConfig()
|
g = GetTgaConfig()
|
||||||
item = g.get_api_key(self.gameid)
|
item = g.get_api_key(self.gameid)
|
||||||
self.url = item['url']
|
self.url = item['url']
|
||||||
@ -33,6 +35,27 @@ class InitFirstAD():
|
|||||||
self.hide = 0.8
|
self.hide = 0.8
|
||||||
self.tga.init_tga_write(self.tgaid)
|
self.tga.init_tga_write(self.tgaid)
|
||||||
|
|
||||||
|
|
||||||
|
def get_ratio(self):
|
||||||
|
# url="https://mp-test.kingsome.cn/api/open/ad-uid?gameid=8002&channelid=6001"
|
||||||
|
ratios = dict()
|
||||||
|
|
||||||
|
url = f"https://mp.kingsome.cn/api/open/ad-uid?gameid={self.gameid}&channelid={self.channelid}"
|
||||||
|
r = requests.get(url)
|
||||||
|
if r.status_code == 200:
|
||||||
|
data = r.json().get('result', [])
|
||||||
|
else:
|
||||||
|
log.error(f"get {url} from mp was {r.status_code}", exc_info=True)
|
||||||
|
data = None
|
||||||
|
if data:
|
||||||
|
for line in data:
|
||||||
|
try:
|
||||||
|
ratios[line['adChannel']] = line['ratio']
|
||||||
|
except Exception:
|
||||||
|
log.error(f"{line} split 'adChannel','ratio' failed! ", exc_info=True)
|
||||||
|
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
|
||||||
@ -54,12 +77,12 @@ class InitFirstAD():
|
|||||||
def run(self):
|
def run(self):
|
||||||
ad_channels = self.get_ad_channel()
|
ad_channels = self.get_ad_channel()
|
||||||
for ad_channel in ad_channels:
|
for ad_channel in ad_channels:
|
||||||
|
ratio = self.ratio.get('ad_channel', 100)
|
||||||
begin = self.get_last_times(ad_channel)
|
begin = self.get_last_times(ad_channel)
|
||||||
users = self.get_new_user(begin,ad_channel)
|
users = self.get_new_user(begin,ad_channel)
|
||||||
#print(f"get {users} with {ad_channel} ")
|
#print(f"get {users} with {ad_channel} ")
|
||||||
if users:
|
if users:
|
||||||
mark_users = self.hide_user(users)
|
mark_users = self.hide_user(users, ratio)
|
||||||
table_name = "newuser"
|
table_name = "newuser"
|
||||||
if mark_users:
|
if mark_users:
|
||||||
log.info(f"get users {len(users)},write {len(mark_users)} to mysql!")
|
log.info(f"get users {len(users)},write {len(mark_users)} to mysql!")
|
||||||
@ -89,10 +112,10 @@ class InitFirstAD():
|
|||||||
return last_time
|
return last_time
|
||||||
|
|
||||||
|
|
||||||
def hide_user(self, data):
|
def hide_user(self, data, ratio):
|
||||||
if data:
|
if data:
|
||||||
line = len(data)
|
line = len(data)
|
||||||
nums = int(line * self.hide)
|
nums = int(line * 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