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.
142 lines
4.2 KiB
142 lines
4.2 KiB
import pymysql |
|
from pymysql.cursors import DictCursor |
|
import json |
|
from blue_forecast import dict_sort, dict_rate |
|
from lottery_random import new_num |
|
|
|
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]))) |
|
|
|
# 产生随机数 |
|
red_index_list = [n[0] - 1 for n in new_num(33, 6)[0:6]] |
|
random_red = [] |
|
for index in red_index_list: |
|
random_red.append(_red_forecast_list[index]) |
|
print('随机红球推荐:') |
|
print(', '.join(sorted(random_red))) |
|
|
|
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(sorted(red_forecast_list[0:6])) |
|
conn = pymysql.connect(**db) |
|
curser = conn.cursor(DictCursor) |
|
curser.execute() |
|
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()
|
|
|