1、累计用户添加ad_channel为空的数据 2、新增用户统计脚本

This commit is contained in:
pengtao 2019-09-02 20:03:58 +08:00
parent dd888e9711
commit fe2ef66f17
3 changed files with 122 additions and 0 deletions

View File

@ -69,6 +69,8 @@ class Mycollect2001(GetFromTga):
for line in data:
if line:
try:
if channel == '':
tga_data['num'] = 37545 + int(line[0])
tga_data['num'] = line[0]
tga_data['ad_channel'] = channel
self.tga.put_event_data(tga_data, f'rep_{event_type}')

87
get_new_user.py Normal file
View File

@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
from ops.mtga import FromTga, GetTgaConfig
from ops.plog import define_logger
import logging
import datetime
from ops.mmysql import MysqlBase
import random
define_logger("/data/logs/init_first_ad_channel.log")
log = logging.getLogger(__name__)
TimeDelay = 10
DB = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'games_report'}
class InitFirstAD():
def __init__(self, kwargs):
self.end = kwargs.get('time')
self.begin = datetime.datetime.strftime(
datetime.datetime.strptime(self.end, '%Y-%M-%d ''%H:%M:%S') - datetime.timedelta(minutes=TimeDelay),
'%Y-%M-%d ''%H:%M:%S')
self.gameid = kwargs.get('gameid')
self.channelid = kwargs.get('channelid')
g = GetTgaConfig()
item = g.get_api_key(self.gameid)
self.url = item['url']
self.tgaid = item['tgaid']
self.suffix = item.get('suffix', 0)
self.api_key = item.get('api_key', None)
self.tga = FromTga(self.url, self.api_key)
self.mysql = MysqlBase(**DB)
self.hide = 0.8
self.tga.init_tga_write(self.tgaid)
def run(self):
users = self.get_new_user()
mark_users = self.hide(users)
table_name = "newuser"
if mark_users:
for line in mark_users:
try:
temp = {}
temp['gameid'] = self.gameid
temp['channelid'] = self.channelid
temp['accountid'], temp['register_time'] = line
self.mysql.insert(table_name, temp)
except Exception:
log.error(f"insert {line} to mysql Failed !", exc_info=True)
def hide_user(self, data):
if data:
line = len(data)
nums = int(line * self.hide)
if nums:
return random.sample(data, nums)
else:
return None
def get_new_user(self):
rdata = []
sql = f"""SELECT
"#account_id",
account_register_time
FROM
v_user_{self.suffix}
where
gameid='{self.gameid}'
AND "account_register_time" BETWEEN timestamp'{self.begin}' AND timestamp'{self.end}' """
data = self.tga.get_data(sql)
if data:
for line in data:
if line:
rdata.append(line)
return rdata
def main():
kwargs = {}
kwargs['time'] = datetime.datetime.now().strftime("%Y-%M-%d ''%H:%M:%S")
kwargs['gameid'] = 2001
kwargs['channelid'] = 6001
if __name__ == "__main__":
main()

33
init_first_ad_channel.py Normal file
View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from ops.mtga import FromTga, GetTgaConfig
from ops.plog import define_logger
import logging
define_logger("/data/logs/init_first_ad_channel.log")
log = logging.getLogger(__name__)
class InitFirstAD():
def __init__(self, kwargs):
self.date = kwargs.get('date')
self.gameid = kwargs.get('gameid')
self.channelid = kwargs.get('channelid')
g = GetTgaConfig()
item = g.get_api_key(self.gameid)
self.url = item['url']
self.tgaid = item['tgaid']
self.suffix = item.get('suffix', 0)
self.api_key = item.get('api_key', None)
self.tga = FromTga(self.url, self.api_key)
self.tga.init_tga_write(self.tgaid)
def run(self):
pass
def main():
pass
if __name__ == "__main__":
main()