diff --git a/api/api_v1/endpoints/data_auth.py b/api/api_v1/endpoints/data_auth.py index 8c713a9..28c8768 100644 --- a/api/api_v1/endpoints/data_auth.py +++ b/api/api_v1/endpoints/data_auth.py @@ -145,30 +145,54 @@ async def load_prop_quotas(request: Request, 'category': settings.CK_OPERATOR.get(data_type) or [] } event_props.append(event_prop) - - 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": [] - }, - ] + if data_in.model == 'scatter': + staid_quots = [ + { + "id": "*", + "data_type": None, + "analysis": "times", + "title": "次数", + "category": [] + }, + { + "id": "*", + "data_type": None, + "analysis": "number_of_days", + "title": "天数", + "category": [] + }, + { + "id": "*", + "data_type": None, + "analysis": "number_of_hours", + "title": "小时数", + "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 = { 'props': event_props, diff --git a/api/api_v1/endpoints/query.py b/api/api_v1/endpoints/query.py index f8c7c31..ad95f8e 100644 --- a/api/api_v1/endpoints/query.py +++ b/api/api_v1/endpoints/query.py @@ -336,7 +336,7 @@ async def scatter_model_sql( @router.post("/scatter_model") -async def scatter_model_sql( +async def scatter_model( request: Request, game: str, ckdb: CKDrive = Depends(get_ck_db), @@ -355,8 +355,9 @@ async def scatter_model_sql( if analysis != 'number_of_days': max_v = int(df['values'].max()) min_v = int(df['values'].min()) - interval = (max_v - min_v) // 10 - resp = {} + interval = (max_v - min_v) // 10 or 1 + resp = {'list': dict()} + if not quota_interval_arr: 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)] @@ -373,7 +374,7 @@ async def scatter_model_sql( right=False).value_counts() bins_s.sort_index(inplace=True) 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()} return schemas.Msg(code=0, msg='ok', data=resp) @@ -381,5 +382,5 @@ async def scatter_model_sql( resp = {} for key, tmp_df in df.groupby('date'): 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) diff --git a/main.py b/main.py index a3730b7..6270829 100644 --- a/main.py +++ b/main.py @@ -54,7 +54,7 @@ class CurrentUser(BaseUser): class BasicAuth(AuthenticationBackend): 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 auth = request.headers["Authorization"] diff --git a/schemas/data_auth.py b/schemas/data_auth.py index dfd1abd..4662b37 100644 --- a/schemas/data_auth.py +++ b/schemas/data_auth.py @@ -21,4 +21,4 @@ class DataAuthSet(BaseModel): class LoadProQuotas(BaseModel): event_name: str - + model: str = None