update
This commit is contained in:
parent
d5487e6e64
commit
28e60e4c54
@ -469,7 +469,7 @@ async def trace_model_sql(
|
||||
return schemas.Msg(code=0, msg='ok', data=data)
|
||||
|
||||
|
||||
@router.post("/user_property_sql")
|
||||
@router.post("/user_property_model_sql")
|
||||
async def user_property_sql(
|
||||
request: Request,
|
||||
game: str,
|
||||
@ -494,13 +494,29 @@ async def user_property_model(
|
||||
await analysis.init()
|
||||
res = analysis.property_model()
|
||||
sql = res['sql']
|
||||
quota = res['quota']
|
||||
groupby = res['groupby']
|
||||
df = await ckdb.query_dataframe(sql)
|
||||
# 没有分组
|
||||
data = {'groupby': groupby}
|
||||
if not groupby:
|
||||
data['总体'] = df['values'][0]
|
||||
else:
|
||||
data = df.groupby(groupby).sum().to_dict()
|
||||
title = []
|
||||
|
||||
return schemas.Msg(code=0, msg='ok', data=data)
|
||||
if not groupby:
|
||||
data['总体'] = int(df['values'][0])
|
||||
title = ['总体', quota]
|
||||
|
||||
else:
|
||||
sum_s = df.groupby(groupby)['values'].sum().sort_values(ascending=False)
|
||||
data = dict()
|
||||
for key, val in sum_s.items():
|
||||
if isinstance(key, tuple):
|
||||
key = ','.join([str(i) for i in key])
|
||||
else:
|
||||
key = str(key)
|
||||
data[key] = val
|
||||
title = ['.'.join(groupby), quota]
|
||||
|
||||
return schemas.Msg(code=0, msg='ok', data={
|
||||
'value': data,
|
||||
'title': title
|
||||
})
|
||||
|
@ -92,7 +92,7 @@ class UserAnalysis:
|
||||
return where
|
||||
|
||||
def property_model(self):
|
||||
event = self.events[0]
|
||||
event = self.events
|
||||
selectd = getattr(self.user_tbl.c, event['quota'])
|
||||
qry = sa.select(selectd)
|
||||
|
||||
@ -122,6 +122,7 @@ class UserAnalysis:
|
||||
print(sql)
|
||||
result = {'sql': sql,
|
||||
'groupby': [i.key for i in self.groupby],
|
||||
'quota':event['quota']
|
||||
}
|
||||
|
||||
return result
|
||||
|
Loading…
Reference in New Issue
Block a user