You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.9 KiB
80 lines
3.9 KiB
1 year ago
|
import sqlalchemy
|
||
|
from sqlalchemy import create_engine
|
||
|
from sqlalchemy.orm import declarative_base
|
||
|
from sqlalchemy import Column, Integer, String, DATE
|
||
|
|
||
|
# 创建数据引擎
|
||
|
DB_URI = "mysql+pymysql://root:Sxzgx1209@home.rogersun.cn:3306/lottery"
|
||
|
engine = create_engine(DB_URI, echo=True)
|
||
|
|
||
|
# 生成基类
|
||
|
Base = declarative_base()
|
||
|
|
||
|
|
||
|
# 生成数据表对象
|
||
|
class History(Base):
|
||
|
__tablename__ = 'history' # 定义表名
|
||
|
|
||
|
# 定义表结构
|
||
|
id = Column(Integer, autoincrement=True, primary_key=True)
|
||
|
dateId = Column(String(20), nullable=False)
|
||
|
openDate = Column(DATE, nullable=False)
|
||
|
red = Column(String(200), nullable=False)
|
||
|
blue = Column(String(10), nullable=False)
|
||
|
|
||
|
|
||
|
class BlueForecastFiveAll(Base):
|
||
|
__tablename__ = 'blue_forecast_five_all' # 定义表名
|
||
|
|
||
|
# 定义表结构
|
||
|
id = Column(Integer, autoincrement=True, primary_key=True)
|
||
|
dateId = Column(String(20), nullable=False, comment='期号')
|
||
|
real_blue = Column(String(10), comment='真实的蓝球数据')
|
||
|
prv_five = Column(String(500), nullable=False, comment='根据当前一期的蓝球,从历史数据中往前推5期,计算蓝球出现概率')
|
||
|
prv_index = Column(Integer, comment='根据实际结果计算蓝球的index位置')
|
||
|
post_five = Column(String(500), nullable=False, comment='根据当前一期的蓝球,从历史数据中往后推5期,计算蓝球出现概率')
|
||
|
post_index = Column(Integer, comment='根据实际结果计算蓝球的index位置')
|
||
|
history_total = Column(String(500), nullable=False, comment='根据当前一期的蓝球,从历史数据中计算每个蓝球出现的概率')
|
||
|
history_index = Column(Integer, comment='历史中的蓝球索引')
|
||
|
|
||
|
|
||
|
class BlueForecastThreeAll(Base):
|
||
|
__tablename__ = 'blue_forecast_three_all' # 定义表名
|
||
|
|
||
|
# 定义表结构
|
||
|
id = Column(Integer, autoincrement=True, primary_key=True)
|
||
|
dateId = Column(String(20), nullable=False, comment='期号')
|
||
|
real_blue = Column(String(10), comment='真实的蓝球数据')
|
||
|
prv_three = Column(String(500), nullable=False, comment='根据当前一期的蓝球,从历史数据中往前推5期,计算蓝球出现概率')
|
||
|
prv_index = Column(Integer, comment='根据实际结果计算蓝球的index位置')
|
||
|
post_three = Column(String(500), nullable=False,
|
||
|
comment='根据当前一期的蓝球,从历史数据中往后推5期,计算蓝球出现概率')
|
||
|
post_index = Column(Integer, comment='根据实际结果计算蓝球的index位置')
|
||
|
history_total = Column(String(500), nullable=False, comment='根据当前一期的蓝球,从历史数据中计算每个蓝球出现的概率')
|
||
|
history_index = Column(Integer, comment='历史中的蓝球索引')
|
||
|
|
||
|
|
||
|
class RedForecastAll(Base):
|
||
|
__tablename__ = 'red_forecast_all' # 定义表名
|
||
|
|
||
|
# 定义表结构
|
||
|
id = Column(Integer, autoincrement=True, primary_key=True)
|
||
|
dateId = Column(String(20), nullable=False, comment='期号-指预测数据根据哪一期数据计算')
|
||
|
red_rate = Column(String(500), nullable=False, comment='根据上一期红球结果计算历史中红球的出现概率')
|
||
|
random_red_num = Column(String(256), comment='随机计算的红球数据')
|
||
|
random_red_index = Column(String(256), comment='预测红球数据对应的index')
|
||
|
random_red_index_group = Column(String(256), comment='预测红球数据对应的index分布')
|
||
|
real_red = Column(String(256), comment='下一期的真实的红球数据')
|
||
|
real_red_index = Column(String(100), comment='真实红球在此次预测中的索引位置')
|
||
|
real_red_index_group = Column(String(100), comment='真实红球在此次预测中的索引位置的分布')
|
||
|
|
||
|
|
||
|
# 创建数据表,下面部分没有联想
|
||
|
Base.metadata.create_all(engine)
|
||
|
|
||
|
|
||
|
from sqlalchemy.orm import sessionmaker
|
||
|
|
||
|
Session_class = sessionmaker(bind=engine) # 创建与数据引擎的绑定会话类
|
||
|
session = Session_class() # 实例化session连接
|