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,7 +145,31 @@ async def load_prop_quotas(request: Request,
'category': settings.CK_OPERATOR.get(data_type) or []
}
event_props.append(event_prop)
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": "*",

View File

@ -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)

View File

@ -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"]

View File

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