104 lines
3.4 KiB
Python
104 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from mytask.tga import FromTga
|
|
from config.config_real import influx_meas
|
|
from ops.myinflux import Myinflux
|
|
|
|
|
|
class RealData(FromTga):
|
|
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.get_data(sql_new_user)
|
|
out_login = self.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.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
|
|
rd = RealData(**kwargs)
|
|
rd.event_user()
|
|
|
|
|
|
def real_event_share(kwargs):
|
|
# share_by_people,share_nums
|
|
rd = RealData(**kwargs)
|
|
rd.event_share()
|