基本完成代码,待测试调试

main
roger_home_pc 1 year ago
parent 528e5d426a
commit b0199e676a
  1. 16
      orm/blue_forecast.py
  2. 14
      orm/db.py
  3. 8
      orm/main.py
  4. 1
      orm/orm_db.py
  5. 53
      orm/real_index.py
  6. 32
      orm/red_forecast.py
  7. 1
      orm/util.py

@ -126,6 +126,7 @@ def print_blue_data(_history, _prv_five, _post_five, _prv_three, _post_three):
_post_five_list = list(_post_five.items()) _post_five_list = list(_post_five.items())
_prv_three_list = list(_prv_three.items()) _prv_three_list = list(_prv_three.items())
_post_three_list = list(_post_three.items()) _post_three_list = list(_post_three.items())
print('篮球数据表:')
for i in range(16): for i in range(16):
print(f"{_history_list[i][0]} [{_history_list[i][1]}]\t" print(f"{_history_list[i][0]} [{_history_list[i][1]}]\t"
f" {_prv_five_list[i][0]} [{_prv_five_list[i][1]}]\t" f" {_prv_five_list[i][0]} [{_prv_five_list[i][1]}]\t"
@ -134,7 +135,7 @@ def print_blue_data(_history, _prv_five, _post_five, _prv_three, _post_three):
f"{_post_three_list[i][0]} [{_post_three_list[i][1]}]") f"{_post_three_list[i][0]} [{_post_three_list[i][1]}]")
if __name__ == "__main__": def forecast_blue():
all_data = get_all_data() all_data = get_all_data()
history_total = get_delta_blue(get_all_blue(all_data)) history_total = get_delta_blue(get_all_blue(all_data))
prv_five = get_blue_forecast(get_all_data(), 'prv', 5) prv_five = get_blue_forecast(get_all_data(), 'prv', 5)
@ -144,3 +145,16 @@ if __name__ == "__main__":
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_five), json.dumps(post_five), 5)
insert_blue_data(all_data, json.dumps(history_total), json.dumps(prv_three), json.dumps(post_three), 3) 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) print_blue_data(history_total, prv_five, post_five, prv_three, post_three)
if __name__ == "__main__":
# all_data = get_all_data()
# history_total = get_delta_blue(get_all_blue(all_data))
# prv_five = get_blue_forecast(get_all_data(), 'prv', 5)
# 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)
# 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)
pass

@ -140,6 +140,9 @@ def db_red_insert(_data):
def db_red_update(_id, _date_id, _data): def db_red_update(_id, _date_id, _data):
try: try:
print(_id)
print(_date_id)
print(_data)
update_stmt = update(RedForecastAll).where( update_stmt = update(RedForecastAll).where(
and_(RedForecastAll.dateId == _date_id, RedForecastAll.id == _id)).values(_data) and_(RedForecastAll.dateId == _date_id, RedForecastAll.id == _id)).values(_data)
update_result = db_session.execute(update_stmt).rowcount update_result = db_session.execute(update_stmt).rowcount
@ -161,6 +164,15 @@ def db_index_get_index_group(_type):
return index_list return index_list
def db_index_get_last_date_id(_type):
index_stmt = select(IndexGroup.dateId).where(IndexGroup.type == _type).order_by(desc(IndexGroup.id))
index_result = db_session.execute(index_stmt).scalars()
date_id_list = []
for row in index_result:
date_id_list.append(row.date_id)
return date_id_list
def db_index_insert_index_group(_data): def db_index_insert_index_group(_data):
try: try:
index_stmt = insert(IndexGroup).values(_data) index_stmt = insert(IndexGroup).values(_data)
@ -169,6 +181,7 @@ def db_index_insert_index_group(_data):
db_session.commit() db_session.commit()
else: else:
db_session.rollback() db_session.rollback()
return index_result
except Exception as e: except Exception as e:
print(e) print(e)
@ -227,6 +240,7 @@ def red_scalars(_scalars):
_data['history_random'] = row.history_random _data['history_random'] = row.history_random
_data['history_random_index'] = row.history_random_index _data['history_random_index'] = row.history_random_index
_data['history_random_index_group'] = row.history_random_index_group _data['history_random_index_group'] = row.history_random_index_group
_data['last'] = row.last
_data['last_random'] = row.last_random _data['last_random'] = row.last_random
_data['last_random_index'] = row.last_random_index _data['last_random_index'] = row.last_random_index
_data['last_random_index_group'] = row.last_random_index_group _data['last_random_index_group'] = row.last_random_index_group

@ -0,0 +1,8 @@
from blue_forecast import forecast_blue
from red_forecast import red_forecast
from real_index import update_real_data
if __name__ == "__main__":
update_real_data()
forecast_blue()
red_forecast()

@ -80,6 +80,7 @@ class IndexGroup(Base):
# 定义表结构 # 定义表结构
id = Column(Integer, primary_key=True, comment='主键') id = Column(Integer, primary_key=True, comment='主键')
dateId = Column(String(20), nullable=False, comment='对应history中的dateId')
type = Column(Enum('history', 'last'), default='history', nullable=False, comment='索引类型') type = Column(Enum('history', 'last'), default='history', nullable=False, comment='索引类型')
index_group = Column(String(100), nullable=False, comment='用于手机索引组数据') index_group = Column(String(100), nullable=False, comment='用于手机索引组数据')

@ -1,15 +1,18 @@
from db import * from db import *
from blue_forecast import forecast_blue
from red_forecast import red_forecast
import json import json
def general_red_index(_real_red, _forecast_data): def general_red_index(_real_red, _forecast_data):
index_list = [] index_list = []
for _red in _forecast_data.keys(): data_list = list(_forecast_data.keys())
for _red in data_list:
if _red in _real_red: if _red in _real_red:
index_list.append(_forecast_data.keys().index(_red) + 1) index_list.append(data_list.index(_red) + 1)
index_group = [0, 0, 0] index_group = [0, 0, 0]
for index in index_group: for index in index_list:
if index <= 11: if 1 <= index <= 11:
index_group[0] += 1 index_group[0] += 1
elif 11 < index <= 22: elif 11 < index <= 22:
index_group[1] += 1 index_group[1] += 1
@ -24,6 +27,20 @@ def general_blue_index(_real_blue, _forecast_data):
return list(_forecast_data.keys()).index(_real_blue) + 1 return list(_forecast_data.keys()).index(_real_blue) + 1
def insert_index_group(_date_id, _type, _index_group):
if _date_id not in db_index_get_last_date_id(_type):
_data = {
'dateId': _date_id,
'type': _type,
'index_group': _index_group
}
result = db_index_insert_index_group(_data)
if result > 0:
print(f'插入index_group成功 {_index_group}')
else:
print('插入index_group失败')
def update_real_data(): def update_real_data():
new_history_date_id, old_history_date_id = db_history_get_last_open_id() new_history_date_id, old_history_date_id = db_history_get_last_open_id()
blue_date_id = db_blue_get_last_one_open_id() blue_date_id = db_blue_get_last_one_open_id()
@ -40,37 +57,33 @@ def update_real_data():
history_index_list, history_index_group = general_red_index(real_red, json.loads(data['history'])) history_index_list, history_index_group = general_red_index(real_red, json.loads(data['history']))
last_index_list, last_index_group = general_red_index(real_red, json.loads(data['last'])) last_index_list, last_index_group = general_red_index(real_red, json.loads(data['last']))
update_data = { update_data = {
'real_red': real_red, 'real_red': json.dumps(real_red),
'real_red_index_history': history_index_list, 'real_red_index_history': json.dumps(history_index_list),
'real_red_index_group_history': history_index_group, 'real_red_index_group_history': json.dumps(history_index_group),
'real_red_index_last': last_index_list, 'real_red_index_last': json.dumps(last_index_list),
'real_red_index_group_last': last_index_group 'real_red_index_group_last': json.dumps(last_index_group)
} }
db_red_update(_id, red_date_id, update_data) db_red_update(_id, red_date_id, update_data)
# 插入 IndexGroup index_group # 插入 IndexGroup index_group
db_index_insert_index_group({'type': 'history', 'index_group': json.dumps(history_index_group)}) insert_index_group(
db_index_insert_index_group({'type': 'last', 'index_group': json.dumps(last_index_group)}) {'dateId': red_date_id, 'type': 'history', 'index_group': json.dumps(history_index_group)})
insert_index_group({'dateId': red_date_id, 'type': 'last', 'index_group': json.dumps(last_index_group)})
if blue_date_id['five'] == old_history_date_id: if blue_date_id['five'] == old_history_date_id:
# 插入 real_blue, prv_index, post_index, history_index # 插入 real_blue, prv_index, post_index, history_index
real_blue = all_data[-1]['blue'] real_blue = all_data[-1]['blue']
forecast_blue_data = db_blue_get_data_by_date_id(blue_date_id['five'], 5) forecast_blue_data = db_blue_get_data_by_date_id(blue_date_id['five'], 5)
for data in forecast_blue_data: for data in forecast_blue_data:
print(data)
_id = data['id'] _id = data['id']
prv_index = general_blue_index(real_blue, json.loads(data['prv'])) prv_index = general_blue_index(real_blue, json.loads(data['prv']))
post_index = general_blue_index(real_blue, json.loads(data['post'])) post_index = general_blue_index(real_blue, json.loads(data['post']))
history_index = general_blue_index(real_blue, json.loads(data['history'])) history_index = general_blue_index(real_blue, json.loads(data['history']))
print(prv_index)
print(post_index)
print(history_index)
update_data = { update_data = {
'real_blue': real_blue, 'real_blue': real_blue,
'prv_index': prv_index, 'prv_index': prv_index,
'post_index': post_index, 'post_index': post_index,
'history_index': history_index 'history_index': history_index
} }
print(update_data)
db_blue_update(blue_date_id['five'], update_data, _id, 5) db_blue_update(blue_date_id['five'], update_data, _id, 5)
if blue_date_id['three'] == old_history_date_id: if blue_date_id['three'] == old_history_date_id:
@ -92,9 +105,11 @@ def update_real_data():
# 插入预测数据 # 插入预测数据
def general_forecast_data(): def general_forecast_data():
pass forecast_blue()
red_forecast()
if __name__ == "__main__": if __name__ == "__main__":
update_real_data() # update_real_data()
general_forecast_data() # general_forecast_data()
pass

@ -58,7 +58,10 @@ def get_last_red_delta(_last_red):
def get_index_from_db(_index_type): def get_index_from_db(_index_type):
index_list = db_index_get_index_group(_index_type) index_list = db_index_get_index_group(_index_type)
if len(index_list) > 0:
return random.choice(index_list) return random.choice(index_list)
else:
return get_random_index_group()
def get_random_index_group(): def get_random_index_group():
@ -72,10 +75,10 @@ def get_random_index_group():
def get_random_index(_mode='history', _index_type='history'): def get_random_index(_mode='history', _index_type='history'):
# 产生随机数 # 产生随机数
if _mode == 'random': if _mode == 'history':
random_high, random_middle, random_low = get_random_index_group()
else:
random_high, random_middle, random_low = get_index_from_db(_index_type) 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)] 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]] high_red_index_list = [(n[0] - 1) for n in new_num(1, 11, random_high)[0:random_high]]
@ -86,7 +89,7 @@ def get_random_index(_mode='history', _index_type='history'):
print(low_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 = sorted(high_red_index_list + middle_red_index_list + low_red_index_list)
red_index_list = [int(n) for n in red_index_list] red_index_list = [int(n) for n in red_index_list]
print(f"排序后结果") print(f"排序后索引")
print(red_index_list) print(red_index_list)
return red_index_group, red_index_list return red_index_group, red_index_list
@ -104,8 +107,6 @@ def get_forecast_red(_red_data, _index_type):
def insert_red_data(_all_data, _history, _history_random, _last, _last_random): def insert_red_data(_all_data, _history, _history_random, _last, _last_random):
print(_history_random)
print(_last_random)
_insert_data = dict() _insert_data = dict()
_insert_data['dateId'] = _all_data[-1]['dateId'] _insert_data['dateId'] = _all_data[-1]['dateId']
_insert_data['history'] = json.dumps(_history) _insert_data['history'] = json.dumps(_history)
@ -116,15 +117,17 @@ def insert_red_data(_all_data, _history, _history_random, _last, _last_random):
_insert_data['last_random'] = json.dumps(_last_random['forecast']) _insert_data['last_random'] = json.dumps(_last_random['forecast'])
_insert_data['last_random_index'] = json.dumps(_last_random['index']) _insert_data['last_random_index'] = json.dumps(_last_random['index'])
_insert_data['last_random_index_group'] = json.dumps(_last_random['group']) _insert_data['last_random_index_group'] = json.dumps(_last_random['group'])
print(_insert_data)
result = db_red_insert(_insert_data) result = db_red_insert(_insert_data)
print('预测红球数据:')
print(_insert_data['history_random'])
print(_insert_data['last_random'])
if result > 0: if result > 0:
print(f"输入数据成功,插入{result}条数据") print(f"输入数据成功,插入{result}条数据")
else: else:
print("数据插入失败") print("数据插入失败")
if __name__ == "__main__": def red_forecast():
all_data = get_all_data() all_data = get_all_data()
history_red_delta = get_all_red_delta(all_data) history_red_delta = get_all_red_delta(all_data)
# print(all_red_delta) # print(all_red_delta)
@ -135,3 +138,16 @@ if __name__ == "__main__":
forecast_red_last_data = get_forecast_red(last_red_delta, 'last') 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) 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)
# # 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])
# 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)
pass

@ -28,6 +28,7 @@ def get_analysis_data(_raw_dict):
def print_data(_data_list): def print_data(_data_list):
new_data_list = [list(d.items()) for d in _data_list] new_data_list = [list(d.items()) for d in _data_list]
print('红球数据表:')
for i in range(len(new_data_list[0])): for i in range(len(new_data_list[0])):
print_str = f"" print_str = f""
for data in new_data_list: for data in new_data_list:

Loading…
Cancel
Save