This commit is contained in:
wuaho 2021-09-08 16:23:56 +08:00
parent cdc54ca137
commit fc5a9a83a3
5 changed files with 29 additions and 6 deletions

View File

@ -45,7 +45,7 @@ async def event_model_sql(
) -> schemas.Msg:
""" 事件分析模型 sql"""
await analysis.init()
await analysis.init(data_where=current_user.data_where)
data = analysis.event_model_sql()
return schemas.Msg(code=0, msg='ok', data=data)

View File

@ -39,10 +39,13 @@ async def login(
'nickname': user.nickname,
'email': user.email,
'tel': user.tel,
'token': security.create_access_token(
expires_delta=access_token_expires, _id=str(user.id), email=user.email,
nickname=user.nickname,
is_superuser=user.is_superuser, name=user.name
is_superuser=user.is_superuser, name=user.name,
data_where=user.data_where,
),
"token_type": "bearer",
@ -50,7 +53,7 @@ async def login(
'access_token': security.create_access_token(
expires_delta=access_token_expires, _id=str(user.id), email=user.email,
nickname=user.nickname,
is_superuser=user.is_superuser, name=user.name
is_superuser=user.is_superuser, name=user.name,data_where= user.data_where
),
"token_type": "bearer",

View File

@ -33,8 +33,8 @@ class Settings(BaseSettings):
CK_CONFIG = {'host': '139.159.159.3',
'port': 9654,
'user':'legu',
'password':'gncPASUwpYrc'
'user': 'legu',
'password': 'gncPASUwpYrc'
}
CK_TYPE_DICT = {"DateTime('UTC')": 'datetime',
@ -191,6 +191,9 @@ class Settings(BaseSettings):
}, {
'id': 'is null',
'title': '无值'
}, {
'id': 'in',
'title': '在列表里'
},
# {
# 'id': 'regex',

View File

@ -101,7 +101,8 @@ class BehaviorAnalysis:
self.unit_num = None
self.report_name = None
async def init(self):
async def init(self, *args, **kwargs):
if self.data_in.report_id:
db = get_database()
report = await crud.report.get(db, id=self.data_in.report_id)
@ -132,6 +133,10 @@ class BehaviorAnalysis:
self.groupby = self._get_group_by()
self.unit_num = self._get_unit_num()
# 用户自带过滤
if 'data_where' in kwargs:
self.global_filters.extend(kwargs['data_where'].get(self.game, []))
def _get_time_particle_size(self):
return self.event_view.get('timeParticleSize') or 'P1D'
@ -218,6 +223,17 @@ class BehaviorAnalysis:
elif comparator == 'is null':
where.append(col.is_(None))
elif comparator == 'like':
where.append(col.like(f'%{ftv[0]}%'))
elif comparator == 'not like':
where.append(col.notlike(f'%{ftv[0]}%'))
elif comparator == 'in':
where.append(col.in_(ftv))
elif comparator == '!=':
where.append(col != ftv[0])

View File

@ -61,6 +61,7 @@ class UserDB(DBBase):
nickname: str = ''
tel: Any = ''
last_login_ts: str = '尚未登录'
data_where: dict = dict()
class UserDBRW(UserDB):