This commit is contained in:
wuaho 2021-09-14 19:57:22 +08:00
parent fe40edac4d
commit 1a0b076ee6
2 changed files with 48 additions and 0 deletions

View File

@ -708,6 +708,28 @@ async def user_property_sql(
data = analysis.property_model()
return schemas.Msg(code=0, msg='ok', data=[data])
@router.post("/user_property_model_export")
async def user_property_model_export(
request: Request,
game: str,
ckdb: CKDrive = Depends(get_ck_db),
analysis: UserAnalysis = Depends(UserAnalysis),
current_user: schemas.UserDB = Depends(deps.get_current_user)
):
"""用户属性 导出"""
await analysis.init(data_where=current_user.data_where)
data = analysis.property_model()
file_name = quote(f'用户属性.xlsx')
mime = mimetypes.guess_type(file_name)[0]
sql = data['sql']
df = await ckdb.query_dataframe(sql)
df_to_stream = DfToStream((df, '用户属性'))
with df_to_stream as d:
export = d.to_stream()
return StreamingResponse(export, media_type=mime, headers={'Content-Disposition': f'filename="{file_name}"'})
@router.post("/user_property_model")
async def user_property_model(

26
sql/huiliu.sql Normal file
View File

@ -0,0 +1,26 @@
with Date(now()) as end_date,
'2021-08-20' as start_date
select
login_date, days, count() as num
from (
select `#account_id`, arrayJoin(log2) log3, log3.1 as login_date, log3.2 as days
from (select `#account_id`,
login_date,
arrayMap((x, y)->dateDiff('day', x, y) - 1, arraySlice(login_date, 1, length(login_date) - 1),
arraySlice(login_date, 2, length(login_date) - 1)) log1,
arrayMap((x, y)-> (x, y), arraySlice(login_date, 1, length(login_date) - 1), log1) log2
from (select `#account_id`, arraySort(groupArray(date)) login_date
from (
with toDate(addHours(`#event_time`, 8)) as date
select date, `#account_id`
from zhengba.event
where `#event_name` = 'login'
and date >= start_date
and date <= end_date
group by date, `#account_id`
)
group by `#account_id`
having length(login_date) > 1)))
group by login_date,days
order by login_date,days