From 7d7a3801c378098d9bbce4c207f0b07da8a6cdd6 Mon Sep 17 00:00:00 2001 From: wuaho Date: Sat, 18 Sep 2021 15:24:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=BD=93=E6=97=A5=E7=95=99?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/api_v1/authz/authz.py | 6 ++++-- api/api_v1/endpoints/query.py | 20 ++++++++++---------- models/behavior_analysis.py | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/api/api_v1/authz/authz.py b/api/api_v1/authz/authz.py index d199aee..fab9d73 100644 --- a/api/api_v1/authz/authz.py +++ b/api/api_v1/authz/authz.py @@ -91,7 +91,8 @@ async def add_policy( res = 0 for path in data_id.path_list: res = casbin_enforcer.add_policy(data_id.role_id, data_id.game, path, data_id.act) - casbin_enforcer.load_model() + # casbin_enforcer.load_model() + casbin_enforcer.load_policy() return schemas.Msg(code=0, msg='ok', data=res) @@ -105,7 +106,8 @@ async def remove_policy( """ res = casbin_enforcer.remove_policy(data_id.role_id, data_id.game, data_id.path, data_id.act) - casbin_enforcer.load_model() + # casbin_enforcer.load_model() + casbin_enforcer.load_policy() return schemas.Msg(code=0, msg='ok', data=res) diff --git a/api/api_v1/endpoints/query.py b/api/api_v1/endpoints/query.py index a024fb2..8e0df31 100644 --- a/api/api_v1/endpoints/query.py +++ b/api/api_v1/endpoints/query.py @@ -293,7 +293,7 @@ async def retention_model(request: Request, for i in set(date_range) - set(df.index): df.loc[i] = 0 df.sort_index(inplace=True) - days = [i for i in range(unit_num + 1)] + days = [i for i in range(1,unit_num + 1)] summary_values = {} today = datetime.datetime.today().date() @@ -304,7 +304,7 @@ async def retention_model(request: Request, tmp['n'] = [] tmp['p_outflow'] = [] tmp['n_outflow'] = [] - for i in range((today - date).days + 1): + for i in range(1, (today - date).days + 1): if i > unit_num: break p = float(getattr(value, f'p{i + 1}')) @@ -661,14 +661,14 @@ async def scatter_model( resp['list'][key.strftime('%Y-%m-%d')] = {'n': total, 'total': total, 'p': 100} return schemas.Msg(code=0, msg='ok', data=resp) - # bins_s = pd.cut(tmp_df['values'], bins=bins, - # right=False).value_counts() - # bins_s.sort_index(inplace=True) - # total = int(bins_s.sum()) - # resp['list'][key.strftime('%Y-%m-%d')] = dict() - # resp['list'][key.strftime('%Y-%m-%d')]['总体'] = {'n': bins_s.to_list(), 'total': total, - # 'p': round(bins_s * 100 / total, 2).to_list(), - # 'title': '总体'} + # bins_s = pd.cut(tmp_df['values'], bins=bins, + # right=False).value_counts() + # bins_s.sort_index(inplace=True) + # total = int(bins_s.sum()) + # resp['list'][key.strftime('%Y-%m-%d')] = dict() + # resp['list'][key.strftime('%Y-%m-%d')]['总体'] = {'n': bins_s.to_list(), 'total': total, + # 'p': round(bins_s * 100 / total, 2).to_list(), + # 'title': '总体'} @router.post("/trace_model_sql") diff --git a/models/behavior_analysis.py b/models/behavior_analysis.py index c4a99c7..edac96e 100644 --- a/models/behavior_analysis.py +++ b/models/behavior_analysis.py @@ -801,7 +801,7 @@ ORDER BY values desc""" days = (arrow.get(self.end_date).date() - arrow.get(self.start_date).date()).days keep = [] cnt = [] - for i in range(days + 1): + for i in range(1,days + 1): keep.append( f"""cnt{i + 1},round(cnt{i + 1} * 100 / cnt0, 2) as `p{i + 1}`""") cnt.append(f"""sum(if(dateDiff('day',a.reg_date,b.visit_date)={i},1,0)) as cnt{i + 1}""")