尝试新的算法

main
roger 2 years ago
parent b683b58f0e
commit 64317e3c93
  1. 2
      blue_forecast.py
  2. 39
      blue_total_rate.py
  3. 131
      red_forecast.py

@ -142,7 +142,7 @@ def get_blue_suggest(_range):
result[k] += 0 result[k] += 0
else: else:
result[k] = data[k] result[k] = data[k]
print('推荐的篮球结果:') print(f'推荐的篮球结果,未来{str(_range)}期历史数据统计总和')
for k,v in dict_rate(dict_sort(result, 'val', True)).items(): for k,v in dict_rate(dict_sort(result, 'val', True)).items():
print(f"{k} - {v}") print(f"{k} - {v}")

@ -0,0 +1,39 @@
import pymysql
import json
from functools import reduce
from blue_forecast import dict_sort, dict_rate
from pymysql.cursors import DictCursor
db = {
'host': 'home.rogersun.online',
'user': 'root',
'password': 'Sxzgx1209',
'database': 'lottery'
}
def get_all_data():
conn = pymysql.connect(**db)
cursor = conn.cursor(DictCursor)
cursor.execute("SELECT * FROM history")
all_data = cursor.fetchall()
# print(all_data)
return all_data
def get_all_blue_rate():
all_blue = {}
all_data = get_all_data()
for data in all_data:
if data['blue'] in all_blue.keys():
all_blue[data['blue']] += 1
else:
all_blue[data['blue']] = 1
print(all_blue)
print('历史中篮球总概率:')
for k, v in dict_rate(dict_sort(all_blue, 'val', True)).items():
print(f"{k} - {v}")
if __name__ == "__main__":
get_all_blue_rate()

@ -0,0 +1,131 @@
import pymysql
from pymysql.cursors import DictCursor
import json
from blue_forecast import dict_sort, dict_rate
db = {
'host': 'home.rogersun.online',
'user': 'root',
'password': 'Sxzgx1209',
'database': 'lottery'
}
def get_all_data():
conn = pymysql.connect(**db)
curser = conn.cursor(DictCursor)
curser.execute("SELECT * FROM history")
_all_data = curser.fetchall()
# print(all_data)
return _all_data
def get_all_red():
_all_data = get_all_data()
_red_data = []
for data in _all_data:
_red_data.append(json.loads(data['red']))
return _red_data
def get_all_red_with_id():
_all_data = get_all_data()
_red_data_dict = {}
for data in _all_data:
_red_data_dict[data['id']] = json.loads(data['red'])
return _red_data_dict
def get_last_red(_red_data):
return _red_data[-1]
def get_last_id(_all_data):
return _all_data[-1]['id']
def get_all_data_rate(_all_red_data):
_red = {}
for _red_list in _all_red_data:
for r in _red_list:
if r in _red.keys():
_red[r] += 1
else:
_red[r] = 1
print("历史红球的出现概率:")
for k, v in dict_rate(dict_sort(_red, 'val', True)).items():
print(f"{k}: {v}")
def get_red_forecast(_all_data, _red_data_dict, _red_data, range_num=1):
print("红球预期数据:")
_last_red = get_last_red(_red_data)
_last_id = get_last_id(_all_data)
_id_dict = {}
for _red in _last_red:
for _id, _red_list in _red_data_dict.items():
if _id == _last_id:
break
if _red in _red_list:
if _red in _id_dict.keys():
_id_dict[_red].append(_id + 1)
else:
_id_dict[_red] = [_id + 1]
# for k, v in _id_dict.items():
# print(f"{k}-{v}")
_red_dict = {}
for _red, _id_list in _id_dict.items():
# print(f"{_red}-{_id_list}")
_red_temp_dict = {}
for _id in _id_list:
for _r in _red_data_dict[_id]:
if _r in _red_temp_dict.keys():
_red_temp_dict[_r] += 1
else:
_red_temp_dict[_r] = 1
_red_dict[_red] = _red_temp_dict
# for k, v in _red_dict.items():
# print(f"{k}-{dict_rate(dict_sort(v,'val', True))}")
_red_forecast_dict = {}
for _red, _red_list in _red_dict.items():
for _r, _sum in _red_list.items():
if _r in _red_forecast_dict.keys():
_red_forecast_dict[_r] += _sum
else:
_red_forecast_dict[_r] = _sum
_red_forecast_dict = dict_rate(dict_sort(_red_forecast_dict, 'val', True))
for k, v in _red_forecast_dict.items():
print(f"{k}-{v}")
_red_forecast_list = []
for _red, __ in _red_forecast_dict.items():
_red_forecast_list.append(_red)
print('红球推荐:')
print(', '.join(sorted(_red_forecast_list[0:6])))
return _red_forecast_dict, _red_forecast_list
def update_red_forecast_db():
all_data = get_all_data()
red_data = get_all_red()
red_data_dict = get_all_red_with_id()
red_forecast_dict, red_forecast_list = get_red_forecast(all_data, red_data_dict, red_data)
date_id = all_data[-1]['dateId']
params = 1
red_rate = json.dumps(red_forecast_dict)
red_suggest = json.dumps(red_forecast_list[0:6])
conn = pymysql.connect(**db)
curser = conn.cursor(DictCursor)
curser.execute(
"INSERT INTO lottery.red_forecast (`dateId`, `params`, `red_rate`, `red_suggest`) VALUES (%s, %s, %s, %s)",
(date_id, params, red_rate, red_suggest))
conn.commit()
curser.close()
if __name__ == "__main__":
# 实现获取含有这个数的下一期或几期中数字的概率
# 实现获取含有所以数据的总出现概率
update_red_forecast_db()
Loading…
Cancel
Save