datacollect/real_task/tasks_base_real.py
2019-08-19 17:01:12 +08:00

106 lines
3.5 KiB
Python

# -*- coding: utf-8 -*-
from mytask.tga import GetFromTga
from config.config_real import influx_meas
from ops.myinflux import Myinflux
class RealData(GetFromTga):
def event_user(self):
sql_new_user = f"""select
count(DISTINCT "#account_id") ,
ad_channel
from
v_event_{self.suffix}
where
"$part_event"='event_11_1'
and gameid='{self.gameid}'
and channel='{self.channelid}'
and "account_register_date" between timestamp'{self.b_time}' and timestamp'{self.e_time}'
GROUP BY ad_channel"""
sql_login_user = f"""select
count(1),
count(distinct "#account_id") ,
ad_channel
from
v_event_{self.suffix}
where
"$part_event"='event_11_1'
and gameid='{self.gameid}'
and channel='{self.channelid}'
and "#server_time" between timestamp'{self.b_time}' and timestamp'{self.e_time}'
GROUP BY ad_channel"""
out_new = self.tga.get_data(sql_new_user)
out_login = self.tga.get_data(sql_login_user)
data = {}
try:
for line in out_new:
new_user, ad_channel = line
data[ad_channel]['new_user'] = new_user
except:
pass
try:
for l in out_login:
logins, login_user, ad_channel = l
data[ad_channel]['logins'] = logins
data[ad_channel]['login_user'] = login_user
except:
pass
for key in data.keys():
body = [{"measurement": influx_meas,
"tags": {"bengin": self.b_time, "end": self.e_time, "gameid": self.gameid, "type": "real_event_user",
"channelid": self.channelid},
"fields": {"new_user": data[key]['new_user'], "logins": data[key]['logins'],
"login_user": data[key]['login_user']}}]
influx = Myinflux()
influx.write(body)
def event_share(self):
sql = f"""select
count(1),
count(distinct "#account_id"),
ad_channel
from
v_event_{self.suffix}
where
"$part_event"='event_11_10'
and gameid='{self.gameid}'
and channel='{self.channelid}'
and "#server_time" between timestamp'{self.b_time}' and timestamp'{self.e_time}'
group by
ad_channel"""
out = self.tga.get_data(sql)
data = {}
for line in out:
try:
shares, share_people, ad_channel = line
data[ad_channel]['shares'] = shares
data[ad_channel]['share_people'] = share_people
except:
pass
for key in data.keys():
body = [{"measurement": influx_meas,
"tags": {"bengin": self.b_time, "end": self.e_time, "gameid": self.gameid, "type": "real_event_share",
"channelid": self.channelid},
"fields": {"shares": data[key]['shares'], "share_people": data[key]['share_people']}}]
influx = Myinflux()
influx.write(body)
def real_event_user(kwargs):
# new_user,active_user,login_user
print(f"2 {kwargs}")
rd = RealData(**kwargs)
rd.event_user()
def real_event_share(kwargs):
# share_by_people,share_nums
print(f"3 {kwargs}")
rd = RealData(**kwargs)
rd.event_share()