today dau
This commit is contained in:
parent
60538bdda6
commit
9f6757b08c
|
@ -0,0 +1,61 @@
|
|||
from lib.all import *
|
||||
|
||||
|
||||
# 今日dau
|
||||
|
||||
class S:
|
||||
def __init__(self):
|
||||
self.mysql_db_bi = Mysql(
|
||||
"172.31.37.71", 3306, "bi", "root", "Wishpal@2023"
|
||||
)
|
||||
self.myodps = new_my_odps()
|
||||
|
||||
def __del__(self):
|
||||
self.mysql_db_bi.close()
|
||||
|
||||
# 获取dau
|
||||
def get_today_dau_data(self):
|
||||
sql = '''
|
||||
SELECT device,
|
||||
COUNT(DISTINCT mid) AS dau
|
||||
FROM
|
||||
(
|
||||
SELECT mid,
|
||||
MAX(CONCAT(frominfo,"_",GET_JSON_OBJECT(opt,'$.dt'))) AS device
|
||||
FROM actionlog
|
||||
WHERE CONCAT(ym,day) = "{}"
|
||||
AND type="auth" AND stype="token"
|
||||
AND mid>0 AND frominfo!=""
|
||||
GROUP BY mid
|
||||
)
|
||||
GROUP BY device
|
||||
'''.format(get_time_str_by_ts(get_today_zero_time(), "%Y%m%d"))
|
||||
print(sql)
|
||||
|
||||
dau_app_android = 0
|
||||
dau_app_ios = 0
|
||||
dau_h5 = 0
|
||||
docs = self.myodps.exec_odps_and_to_diclist(sql)
|
||||
for doc in docs:
|
||||
device = safe_get_str(doc, "device")
|
||||
dau = safe_get_int(doc, "dau")
|
||||
if device == "production_0":
|
||||
dau_app_android += dau
|
||||
elif device == "production_1":
|
||||
dau_app_ios += dau
|
||||
elif device.find("h5") >= 0:
|
||||
dau_h5 += dau
|
||||
dau_total = dau_app_android + dau_app_ios + dau_h5
|
||||
|
||||
print(
|
||||
dau_total, dau_app_android, dau_app_ios, dau_h5
|
||||
)
|
||||
|
||||
# 写入
|
||||
sql_u = "update today_dau set app_android=%s, app_ios=%s, h5_android=%s, total=%s where id=1"
|
||||
ret = self.mysql_db_bi.exec(sql_u, (dau_app_android, dau_app_ios, dau_h5, dau_total))
|
||||
print("update finish, ret: {}".format(ret))
|
||||
|
||||
|
||||
s = S()
|
||||
s.get_today_dau_data()
|
|
@ -3,3 +3,4 @@ from lib.log import *
|
|||
from lib.util import *
|
||||
from lib.mongo import *
|
||||
from lib.mysql import *
|
||||
from lib.odps import *
|
||||
|
|
17
lib/odps.py
17
lib/odps.py
|
@ -6,3 +6,20 @@ odps_secret_key = 'O7xAsKMnnWHwrlfvka30v6yr13Qxa3'
|
|||
|
||||
def get_odps_db(project="tiefen_bigdata"):
|
||||
return ODPS(odps_access_id, odps_secret_key, project)
|
||||
|
||||
|
||||
def new_my_odps(project="tiefen_bigdata"):
|
||||
return MyODPS(project=project)
|
||||
|
||||
|
||||
class MyODPS:
|
||||
def __init__(self, project="tiefen_bigdata"):
|
||||
self.odps = ODPS(odps_access_id, odps_secret_key, project)
|
||||
|
||||
def exec_odps_and_to_diclist(self, sql):
|
||||
records = list()
|
||||
with self.odps.execute_sql(sql).open_reader() as reader:
|
||||
print('finish run sql')
|
||||
for record in reader:
|
||||
records.append(dict(record))
|
||||
return records
|
||||
|
|
Loading…
Reference in New Issue