This commit is contained in:
wuaho 2021-06-25 15:28:35 +08:00
parent c1c2f64390
commit 201bccefe2
4 changed files with 56 additions and 31 deletions

View File

@ -145,30 +145,54 @@ async def load_prop_quotas(request: Request,
'category': settings.CK_OPERATOR.get(data_type) or [] 'category': settings.CK_OPERATOR.get(data_type) or []
} }
event_props.append(event_prop) event_props.append(event_prop)
if data_in.model == 'scatter':
staid_quots = [ staid_quots = [
{ {
"id": "*", "id": "*",
"data_type": None, "data_type": None,
"analysis": "total_count", "analysis": "times",
"title": "总次数", "title": "次数",
"category": [] "category": []
}, },
{ {
"id": "*", "id": "*",
"analysis": "touch_user_count", "data_type": None,
"data_type": None, "analysis": "number_of_days",
"title": "触发用户数", "title": "天数",
"category": [] "category": []
}, },
{ {
"id": "*", "id": "*",
"analysis": "touch_user_avg", "data_type": None,
"data_type": None, "analysis": "number_of_hours",
"title": "人均次数", "title": "小时数",
"category": [] "category": []
}, },
] ]
else:
staid_quots = [
{
"id": "*",
"data_type": None,
"analysis": "total_count",
"title": "总次数",
"category": []
},
{
"id": "*",
"analysis": "touch_user_count",
"data_type": None,
"title": "触发用户数",
"category": []
},
{
"id": "*",
"analysis": "touch_user_avg",
"data_type": None,
"title": "人均次数",
"category": []
},
]
res = { res = {
'props': event_props, 'props': event_props,

View File

@ -336,7 +336,7 @@ async def scatter_model_sql(
@router.post("/scatter_model") @router.post("/scatter_model")
async def scatter_model_sql( async def scatter_model(
request: Request, request: Request,
game: str, game: str,
ckdb: CKDrive = Depends(get_ck_db), ckdb: CKDrive = Depends(get_ck_db),
@ -355,8 +355,9 @@ async def scatter_model_sql(
if analysis != 'number_of_days': if analysis != 'number_of_days':
max_v = int(df['values'].max()) max_v = int(df['values'].max())
min_v = int(df['values'].min()) min_v = int(df['values'].min())
interval = (max_v - min_v) // 10 interval = (max_v - min_v) // 10 or 1
resp = {} resp = {'list': dict()}
if not quota_interval_arr: if not quota_interval_arr:
resp['label'] = [f'[{i},{i + interval})' for i in range(min_v, max_v, interval)] resp['label'] = [f'[{i},{i + interval})' for i in range(min_v, max_v, interval)]
bins = [i for i in range(min_v, max_v + interval, interval)] bins = [i for i in range(min_v, max_v + interval, interval)]
@ -373,7 +374,7 @@ async def scatter_model_sql(
right=False).value_counts() right=False).value_counts()
bins_s.sort_index(inplace=True) bins_s.sort_index(inplace=True)
total = int(bins_s.sum()) total = int(bins_s.sum())
resp[key.strftime('%Y-%m-%d')] = {'n': bins_s.to_list(), 'total': total, resp['list'][key.strftime('%Y-%m-%d')] = {'n': bins_s.to_list(), 'total': total,
'p': round(bins_s * 100 / total, 2).to_list()} 'p': round(bins_s * 100 / total, 2).to_list()}
return schemas.Msg(code=0, msg='ok', data=resp) return schemas.Msg(code=0, msg='ok', data=resp)
@ -381,5 +382,5 @@ async def scatter_model_sql(
resp = {} resp = {}
for key, tmp_df in df.groupby('date'): for key, tmp_df in df.groupby('date'):
total = int(tmp_df['values'].sum()) total = int(tmp_df['values'].sum())
resp[key.strftime('%Y-%m-%d')] = {'n': total, 'total': total, 'p': 100} resp['list'][key.strftime('%Y-%m-%d')] = {'n': total, 'total': total, 'p': 100}
return schemas.Msg(code=0, msg='ok', data=resp) return schemas.Msg(code=0, msg='ok', data=resp)

View File

@ -54,7 +54,7 @@ class CurrentUser(BaseUser):
class BasicAuth(AuthenticationBackend): class BasicAuth(AuthenticationBackend):
async def authenticate(self, request): async def authenticate(self, request):
if "Authorization" not in request.headers: if "Authorization" not in request.headers or request.scope.get('path') == '/api/v1/user/login':
return None return None
auth = request.headers["Authorization"] auth = request.headers["Authorization"]

View File

@ -21,4 +21,4 @@ class DataAuthSet(BaseModel):
class LoadProQuotas(BaseModel): class LoadProQuotas(BaseModel):
event_name: str event_name: str
model: str = None