import sys from typing import Any, Dict, List, Optional, Union from pydantic import AnyHttpUrl, BaseSettings, EmailStr, HttpUrl, validator from sqlalchemy import func, and_ class Settings(BaseSettings): PROJECT_NAME: str = 'X数据分析后台' API_V1_STR: str = '/api/v1' BACKEND_CORS_ORIGINS: List[str] = ['*'] CASBIN_COLL: str = 'casbin_rule' SUPERUSER_EMAIL: str = '15392746632@qq.com' SUPERUSER_PASSWORD: str = '123456' SUPERUSER_NAME: str = 'root' SUPERUSER_NICKNAME: str = 'root' ACCOUNT_COMMON_PASSWORD = 'AWDMIPOUEQfO3q84' DEFAULT_PASSWORD = '123456' ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 SECRET_KEY: str = 'ZaFX6EypK6PtuhGv11q4DLRvAb0csiLx4dbKUwLwCe8' REDIS_CONF = { 'host': '139.159.159.3', 'port': 6378, 'password': 'd1Gh*zp5', 'db': 1, 'decode_responses': 'utf-8', } #本地Redis,测试用 # REDIS_CONF = { # 'host': '127.0.0.1', # 'port': 6379, # 'db': 1, # 'decode_responses': 'utf-8', # } CK_CONFIG = {'host': '139.159.159.3', 'port': 9654, 'user': 'legu', 'password': 'gncPASUwpYrc' } CK_CALC_SYMBO = { '==': lambda col, *val: col == val[0], '>=': lambda col, *val: col >= val[0], '<=': lambda col, *val: col <= val[0], '>': lambda col, *val: col > val[0], '<': lambda col, *val: col < val[0], 'is not null': lambda col, *val: col.isnot(None), 'is null': lambda col, *val: col.is_(None), 'like': lambda col, *val: col.like(f'%{val[0]}%'), 'not like': lambda col, *val: col.notlike(f'%{val[0]}%'), 'in': lambda col, *val: col.in_(val[0]), 'not in': lambda col, *val: col.notin_(val[0]), '!=': lambda col, *val: col != val[0], 'range': lambda col, *val: and_(col >= val[0], col < val[1]) } CK_TYPE_DICT = {"DateTime('UTC')": 'datetime', "Nullable(DateTime('UTC'))": 'datetime', "DateTime()": 'datetime', "Nullable(IPv4)": 'string', "IPv4": 'string', "String": 'string', "Nullable(String)": 'string', "Nullable(UInt8)": 'int', "UInt8": 'string', "Nullable(Int8)": 'int', "Int8": 'string', "Nullable(UInt16)": 'int', "UInt16": 'string', "Nullable(Int16)": 'int', "Int16": 'string', "Nullable(UInt32)": 'int', "UInt32": 'string', "Nullable(UInt64)": 'int', "UInt64": 'string', "Nullable(Int64)": 'int', "Int64": 'string', "Array(String)": 'array', "Nullable(Float)": 'float', "Float": 'float', } CK_FUNC = { 'sum': lambda x: func.sum(x), 'avg': lambda x: func.round(func.avg(x), 2), 'median': lambda x: func.median(x), 'max': lambda x: func.max(x), 'min': lambda x: func.min(x), 'distinct_count': lambda x: func.uniqExact(x), 'uniqExact': lambda x: func.uniqExact(x), } CK_OPERATOR = { 'int': [{ 'id': 'sum', 'title': '总和' }, { 'id': 'avg', 'title': '均值' }, { 'id': 'median', 'title': '中位数' }, { 'id': 'max', 'title': '最大值' }, { 'id': 'min', 'title': '最小值' }, { 'id': 'distinct_count', 'title': '去重数' }, ], 'string': [{ 'id': 'uniqExact', 'title': '去重数' }], 'datetime': [{ 'id': 'uniqExact', 'title': '去重数' }], 'float': [{ 'id': 'sum', 'title': '总和' }, { 'id': 'avg', 'title': '均值' }, { 'id': 'median', 'title': '中位数' }, { 'id': 'max', 'title': '最大值' }, { 'id': 'min', 'title': '最小值' }, { 'id': 'distinct_count', 'title': '去重数' }, ], 'array': [ { 'id': 'list_distinct', 'title': '列表去重数' }, { 'id': 'set_distinct', 'title': '集合去重数' }, { 'id': 'ele_distinct', 'title': '元素去重数' }, ] } CK_FILTER = { 'int': [{ 'id': '==', 'title': '等于' }, { 'id': '!=', 'title': '不等于' }, { 'id': '<', 'title': '小于' }, { 'id': '<=', 'title': '小于等于' }, { 'id': '>', 'title': '大于' }, { 'id': '>=', 'title': '大于等于' }, { 'id': 'is not null', 'title': '有值' }, { 'id': 'is null', 'title': '无值' }, { 'id': 'range', 'title': '区间' }, ], 'string': [{ 'id': '==', 'title': '等于' }, { 'id': '!=', 'title': '不等于' }, { 'id': 'like', 'title': '包含' }, { 'id': 'not like', 'title': '不包含' }, { 'id': 'is not null', 'title': '有值' }, { 'id': 'is null', 'title': '无值' }, { 'id': 'in', 'title': '条件多选' #'title': '在列表里' }, # { # 'id': 'regex', # 'title': '正则匹配' # }, { # 'id': 'not regex', # 'title': '正则不匹配' # }, ], 'float': [{ 'id': '==', 'title': '等于' }, { 'id': '!=', 'title': '不等于' }, { 'id': '<', 'title': '小于' }, { 'id': '>', 'title': '大于' }, { 'id': 'is not null', 'title': '有值' }, { 'id': 'is null', 'title': '无值' }, # { # 'id': 'range', # 'title': '区间' # }, ], 'datetime': [ { 'id': '>', 'title': '大于' }, { 'id': '>=', 'title': '大于等于' }, { 'id': '<', 'title': '小于' }, { 'id': '<=', 'title': '小于等于' }, { 'id': 'is not null', 'title': '有值' }, { 'id': 'is null', 'title': '无值' }, ], 'user_label': [ { 'id': 'in', 'title': '是' }, { 'id': 'not in', 'title': '不是' }, ], 'array': [ { 'id': 'is not null', 'title': '有值' }, { 'id': 'is null', 'title': '无值' } ] } ARITHMETIC = { '+': lambda x, y: x + y, '-': lambda x, y: x - y, '*': lambda x, y: x * y, '/': lambda x, y: x / y, #'%': lambda x, y:(x)-int(x/y)*(y) 取模用 } PROPHET_TIME_GRAIN_MAP = { "PT1S": "S", "PT1M": "min", "PT5M": "5min", "PT10M": "10min", "PT15M": "15min", "PT0.5H": "30min", "PT1H": "H", "P1D": "D", "P1W": "W", "P1M": "MS", "total": "D", } TIME_GRAIN_EXPRESSIONS = { 'PT1S': lambda col, zone: func.toStartOfSecond(func.addHours(col, zone)).label('date'), 'PT1M': lambda col, zone: func.toStartOfMinute(func.addHours(col, zone)).label('date'), 'PT5M': lambda col, zone: func.toStartOfFiveMinute(func.addHours(col, zone)).label('date'), 'PT10M': lambda col, zone: func.toStartOfTenMinutes(func.addHours(col, zone)).label('date'), 'PT15M': lambda col, zone: func.toStartOfFifteenMinutes(func.addHours(col, zone)).label('date'), 'PT1H': lambda col, zone: func.toStartOfHour(func.addHours(col, zone)).label('date'), 'P1D': lambda col, zone: func.toDate(func.addHours(col, zone)).label('date'), 'total': lambda col, zone: func.toStartOfDay(func.addHours(col, zone)).label('date'), 'P1W': lambda col, zone: func.toStartOfWeek(func.addHours(col, zone)).label('date'), 'P1M': lambda col, zone: func.toStartOfMonth(func.addHours(col, zone)).label('date'), 'HOUR': lambda col, zone: func.toHour(func.addHours(col, zone)).label('date'), } DEFAULT_FIELD: dict = { '#ip': 'ipv4', '#country': 'string', '#province': 'string', '#city': 'string', '#os': 'string', '#device_id': 'string', '#screen_height': 'integer', '#screen_width': 'integer', '#device_model': 'string', '#app_version': 'string', '#bundle_id': 'string', '#app_name': 'string', '#game_version': 'string', '#os_version': 'string', '#network_type': 'string', '#carrier': 'string', '#manufacturer': 'string', '#app_id': 'string', '#account_id': 'string', '#distinct_id': 'string', 'binduid': 'string', 'channel': 'string', 'owner_name': 'string', 'role_name': 'string', 'exp': 'integer', 'zhanli': 'integer', 'maxmapid': 'integer', 'mapid': 'integer', 'ghid': 'string', 'rmbmoney': 'integer', 'jinbi': 'integer', 'svrindex': 'string', 'lv': 'integer', 'vip': 'integer', 'game': 'string', # 'unitPrice': 'integer', # 'money': 'string', # 'isdangrishouci': 'integer', # 'islishishouci': 'integer', # 'is_today_reg': 'integer', # 'orderid': 'string', # 'proid': 'string', # # 'step_id': 'integer', # 'step_group': 'integer', # 'guide_start_time': 'integer', # # 'online_ts': 'integer' } class Config: case_sensitive = True # class Debug(Settings): # MDB_HOST: str = '10.0.0.9' # MDB_PORT: int = 27017 # MDB_USER: str = 'root' # MDB_PASSWORD: str = 'iamciniao' # MDB_DB: str = 'xdata' # # DATABASE_URI = f'mongodb://{MDB_USER}:{MDB_PASSWORD}@{MDB_HOST}:{MDB_PORT}/admin' #本地MongoDB的库测试 class Debug(Settings): MDB_HOST: str = '127.0.0.1' MDB_PORT: int = 27017 MDB_DB: str = 'xdata' DATABASE_URI = f'mongodb://{MDB_HOST}:{MDB_PORT}/admin' class Produce(Settings): MDB_HOST: str = '127.0.0.1' MDB_PORT: int = 27017 MDB_USER: str = 'root' MDB_PASSWORD: str = 'iamciniao' MDB_DB: str = 'xdata' DATABASE_URI = f'mongodb://{MDB_USER}:{MDB_PASSWORD}@{MDB_HOST}:{MDB_PORT}/admin' if sys.platform == 'linux': settings = Produce() else: settings = Debug()