# -*- coding: utf-8 -*- from mytask.tga import GetFromTga from config.config_real import influx_meas from ops.myinflux import Myinflux import pdb 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 item = {} item['new_user'] = new_user data[ad_channel] = item except: pass try: for lin in out_login: logins, login_user, ad_channel = lin item = {} item['logins'] = logins item['login_user'] = login_user data[ad_channel].update(item) 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", "ad_channel": key, "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: share, share_people, ad_channel = line item = {} item['share'] = share item['share_people'] = share_people data[ad_channel] = item 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", "ad_channel": key, "channelid": self.channelid}, "fields": {"shares": data[key]['share'], "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()