12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- # coding:utf-8
- from sqlalchemy import create_engine
- from sqlalchemy.ext.declarative import declarative_base
- from sqlalchemy import Column, String, Integer, Float, DATETIME
- Base = declarative_base()
- class AnnotatedData(Base):
- # 训练数据对照表
- __tablename__ = 'annotatedData'
- id = Column(Integer, primary_key=True)
- tenantID = Column(Integer, comment="租户ID")
- projectId = Column(Integer, comment="项目ID")
- infoId = Column(String(100), comment="信息ID")
- label = Column(String(255), comment="标签标识")
- createTime = Column(DATETIME, comment="创建时间")
- class Model(Base):
- # 模型表
- __tablename__ = 'model'
- id = Column(Integer, primary_key=True)
- createperson = Column(String(100), comment="创建人")
- createTime = Column(DATETIME, comment='创建时间')
- sampleData = Column(Integer, comment='模型数据量')
- recallRate = Column(Float(11, 2), comment='召回率')
- precision = Column(Float(11, 2), comment='精度')
- accuracyRate = Column(Float(11, 2), comment='准确率')
- state = Column(Integer(), comment='是否是默认模型 0 不是 1 是')
- modelFile = Column(String(255), comment='模型文件(oss存储)')
- projectId = Column(Integer, comment='项目标识')
- class Project(Base):
- # 项目表
- __tablename__ = 'project'
- id = Column(Integer, primary_key=True)
- name = Column(String(255), comment="项目名称")
- labels = Column(String(255), comment='标签集')
- type = Column(Integer, comment='多标签')
- userId = Column(Integer, comment='用户id')
- model = Column(Integer, comment='模型ID')
- focusField = Column(String(255), comment='模型文件(oss存储)')
- createTime = Column(DATETIME, comment='创建时间')
- totalCount = Column(Integer, comment="总数")
- def init_db(mysql_config):
- """
- 根据类创建数据库表
- :return:
- """
- db = mysql_config.get("db")
- ip = mysql_config.get("ip")
- port = mysql_config.get("port")
- user = mysql_config.get("user")
- pwd = mysql_config.get("pwd")
- charset = mysql_config.get("charset")
- engine = create_engine(
- f"mysql+pymysql://{user}:{pwd}@{ip}:{port}/{db}?charset={charset}",
- max_overflow=0, # 超过连接池⼤⼩外最多创建的连接
- pool_size=5, # 连接池⼤⼩
- pool_timeout=30, # 池中没有线程最多等待的时间,否则报错
- pool_recycle=-1 # 多久之后对线程池中的线程进⾏⼀次连接的回收
- )
- return engine
|