xbackend/core/config.py
2021-09-07 20:30:04 +08:00

312 lines
8.1 KiB
Python

import sys
from typing import Any, Dict, List, Optional, Union
from pydantic import AnyHttpUrl, BaseSettings, EmailStr, HttpUrl, validator
from sqlalchemy import func
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'
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',
}
CK_CONFIG = {'host': '139.159.159.3',
'port': 9654,
'user':'legu',
'password':'gncPASUwpYrc'
}
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.uniqCombined(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': 'uniqCombined',
'title': '去重数'
}],
'datetime': [{
'id': 'uniqCombined',
'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': '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': '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': '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,
}
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'),
}
class Config:
case_sensitive = True
class Debug(Settings):
MDB_HOST: str = '10.0.0.7'
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'
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()