From 468511ddd9c43f3e47c3c919feb924a56630b005 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Sat, 6 Jan 2024 19:53:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E7=90=83=E9=A2=84=E6=B5=8B=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=B8=8E=E4=B8=8A=E6=AC=A1=E6=9C=89n=E4=B8=AA?= =?UTF-8?q?=E6=95=B0=E4=B8=80=E6=A0=B7=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orm/blue_forecast.py | 15 +++++++++++---- orm/db.py | 4 +++- orm/main.py | 5 +++-- orm/orm_db.py | 16 ++++++++++++++++ orm/red_forecast.py | 38 +++++++++++++++++++++++++++++--------- 5 files changed, 62 insertions(+), 16 deletions(-) diff --git a/orm/blue_forecast.py b/orm/blue_forecast.py index 2058766..079d6f4 100644 --- a/orm/blue_forecast.py +++ b/orm/blue_forecast.py @@ -138,20 +138,24 @@ def get_interval_blue(): return dict_sort(blue_dict, 'val', True) -def print_blue_data(_history, _prv_five, _post_five, _prv_three, _post_three, _interval): +def print_blue_data(_history, _prv_five, _post_five, _prv_three, _post_three, _prv_one, _post_one, _interval): _history_list = list(_history.items()) _prv_five_list = list(_prv_five.items()) _post_five_list = list(_post_five.items()) _prv_three_list = list(_prv_three.items()) _post_three_list = list(_post_three.items()) + _prv_one_list = list(_prv_one.items()) + _post_one_list = list(_post_one.items()) _interval_list = list(_interval.items()) print('篮球数据表:') for i in range(16): print(f"{_history_list[i][0]} [{_history_list[i][1]}]\t" - f" {_prv_five_list[i][0]} [{_prv_five_list[i][1]}]\t" - f"{_post_five_list[i][0]} [{_post_five_list[i][1]}]\t" + f"{_prv_one_list[i][0]} [{_prv_one_list[i][1]}]\t" f"{_prv_three_list[i][0]} [{_prv_three_list[i][1]}]\t" + f" {_prv_five_list[i][0]} [{_prv_five_list[i][1]}]\t" + f"{_post_one_list[i][0]} [{_post_one_list[i][1]}]\t" f"{_post_three_list[i][0]} [{_post_three_list[i][1]}]\t" + f"{_post_five_list[i][0]} [{_post_five_list[i][1]}]\t" f"{_interval_list[i][0]} [{_interval_list[i][1]}]") @@ -162,10 +166,13 @@ def forecast_blue(): post_five = get_blue_forecast(get_all_data(), 'post', 5) prv_three = get_blue_forecast(get_all_data(), 'prv', 3) post_three = get_blue_forecast(get_all_data(), 'post', 3) + prv_one = get_blue_forecast(get_all_data(), 'prv', 1) + post_one = get_blue_forecast(get_all_data(), 'post', 1) interval_blue = get_interval_blue() insert_blue_data(all_data, json.dumps(history_total), json.dumps(prv_five), json.dumps(post_five), 5) insert_blue_data(all_data, json.dumps(history_total), json.dumps(prv_three), json.dumps(post_three), 3) - print_blue_data(history_total, prv_five, post_five, prv_three, post_three, interval_blue) + insert_blue_data(all_data, json.dumps(history_total), json.dumps(prv_one), json.dumps(post_one), 1) + print_blue_data(history_total, prv_five, post_five, prv_three, post_three, prv_one, post_one, interval_blue) if __name__ == "__main__": diff --git a/orm/db.py b/orm/db.py index 71ce1e4..efb0b6b 100644 --- a/orm/db.py +++ b/orm/db.py @@ -1,6 +1,6 @@ import json -from orm_db import History, BlueForecastFiveAll, BlueForecastThreeAll, RedForecastAll, IndexGroup +from orm_db import History, BlueForecastFiveAll, BlueForecastThreeAll, BlueForecastOneAll, RedForecastAll, IndexGroup from sqlalchemy import engine from sqlalchemy.orm import sessionmaker, declarative_base from sqlalchemy import select, insert, update, desc, asc, and_ @@ -75,6 +75,8 @@ def db_blue_insert(_data, _num): _table = BlueForecastFiveAll elif _num == 3: _table = BlueForecastThreeAll + elif _num == 1: + _table = BlueForecastOneAll else: print('_num值错误') blue_insert_stmt = insert(_table).values(_data) diff --git a/orm/main.py b/orm/main.py index 9685ba6..00e7901 100644 --- a/orm/main.py +++ b/orm/main.py @@ -1,8 +1,9 @@ from blue_forecast import forecast_blue -from red_forecast import red_forecast +from red_forecast import red_forecast, red_forecast_with_same from real_index import update_real_data if __name__ == "__main__": update_real_data() forecast_blue() - red_forecast() + # red_forecast() + red_forecast_with_same(2) diff --git a/orm/orm_db.py b/orm/orm_db.py index 8ab04a4..16778d5 100644 --- a/orm/orm_db.py +++ b/orm/orm_db.py @@ -54,6 +54,22 @@ class BlueForecastThreeAll(Base): history_index = Column(Integer, comment='历史中的蓝球索引') +class BlueForecastOneAll(Base): + __tablename__ = 'blue_forecast_one_all' # 定义表名 + + # 定义表结构 + id = Column(Integer, autoincrement=True, primary_key=True) + dateId = Column(String(20), nullable=False, comment='期号') + real_blue = Column(String(10), comment='真实的蓝球数据') + prv = Column(String(500), nullable=False, comment='根据当前一期的蓝球,从历史数据中往前推5期,计算蓝球出现概率') + prv_index = Column(Integer, comment='根据实际结果计算蓝球的index位置') + post = Column(String(500), nullable=False, + comment='根据当前一期的蓝球,从历史数据中往后推5期,计算蓝球出现概率') + post_index = Column(Integer, comment='根据实际结果计算蓝球的index位置') + history = Column(String(500), nullable=False, comment='根据当前一期的蓝球,从历史数据中计算每个蓝球出现的概率') + history_index = Column(Integer, comment='历史中的蓝球索引') + + class RedForecastAll(Base): __tablename__ = 'red_forecast_all' # 定义表名 diff --git a/orm/red_forecast.py b/orm/red_forecast.py index fad1d12..de067d6 100644 --- a/orm/red_forecast.py +++ b/orm/red_forecast.py @@ -78,18 +78,18 @@ def get_random_index(_mode='history', _index_type='history'): random_high, random_middle, random_low = get_index_from_db(_index_type) else: random_high, random_middle, random_low = get_random_index_group() - print('分布区间(高概率区,中概率区,低概率区):', random_high, random_middle, random_low) + # print('分布区间(高概率区,中概率区,低概率区):', random_high, random_middle, random_low) red_index_group = [int(random_high), int(random_middle), int(random_low)] high_red_index_list = [(n[0] - 1) for n in new_num(1, 11, random_high)[0:random_high]] middle_red_index_list = [(n[0] - 1) for n in new_num(12, 22, random_middle)[0:random_middle]] low_red_index_list = [(n[0] - 1) for n in new_num(23, 33, random_low)[0:random_low]] - print(high_red_index_list) - print(middle_red_index_list) - print(low_red_index_list) + # print(high_red_index_list) + # print(middle_red_index_list) + # print(low_red_index_list) red_index_list = sorted(high_red_index_list + middle_red_index_list + low_red_index_list) red_index_list = [int(n) for n in red_index_list] - print(f"排序后索引") - print(red_index_list) + # print(f"排序后索引") + # print(red_index_list) return red_index_group, red_index_list @@ -100,8 +100,7 @@ def get_forecast_red(_red_data, _index_type): for i in index_list: forecast_red_list.append(_red_data_list[i][0]) forecast_red_list = sorted(forecast_red_list) - print('随机红球推荐:') - print(forecast_red_list) + print('随机红球推荐:', forecast_red_list) return {'forecast': forecast_red_list, 'group': index_group, 'index': index_list} @@ -138,6 +137,27 @@ def red_forecast(): insert_red_data(all_data, history_red_delta, forecast_red_history_data, last_red_delta, forecast_red_last_data) +def red_forecast_with_same(_num): + all_data = get_all_data() + last_red = json.loads(db_history_get_last_data()['red']) + history_red_delta = get_all_red_delta(all_data) + # print(all_red_delta) + last_red_delta = get_last_red_delta(get_all_red_in_last(all_data)) + # print(last_red_delta) + print_data([history_red_delta, last_red_delta]) + history_switch = True + while history_switch: + forecast_red_history_data = get_forecast_red(history_red_delta, 'history') + if len(list(set(forecast_red_history_data['forecast']) & set(last_red))) == _num: + history_switch = False + last_switch = True + while last_switch: + forecast_red_last_data = get_forecast_red(last_red_delta, 'last') + if len(list(set(forecast_red_last_data['forecast']) & set(last_red))) == _num: + last_switch = False + insert_red_data(all_data, history_red_delta, forecast_red_history_data, last_red_delta, forecast_red_last_data) + + if __name__ == "__main__": # all_data = get_all_data() # history_red_delta = get_all_red_delta(all_data) @@ -148,5 +168,5 @@ if __name__ == "__main__": # forecast_red_history_data = get_forecast_red(history_red_delta, 'history') # forecast_red_last_data = get_forecast_red(last_red_delta, 'last') # insert_red_data(all_data, history_red_delta, forecast_red_history_data, last_red_delta, forecast_red_last_data) + red_forecast_with_same(2) pass -