From 3cb37d04d09db63187852f679e3b113c7e715274 Mon Sep 17 00:00:00 2001 From: roger Date: Fri, 31 Mar 2023 13:10:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E5=A4=84=E7=90=86=E5=90=8E=E7=BB=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo.py | 22 -------------- lottery_random.py | 7 +++-- new_blue_forecast.py | 71 +++++++++++++++++++++++++++++++++++++++++++ real_index.py | 72 ++++++++++++++++++++++++++++++++++++++++++++ red_forecast.py | 13 +++++++- 5 files changed, 159 insertions(+), 26 deletions(-) delete mode 100644 demo.py create mode 100644 new_blue_forecast.py create mode 100644 real_index.py diff --git a/demo.py b/demo.py deleted file mode 100644 index a45318d..0000000 --- a/demo.py +++ /dev/null @@ -1,22 +0,0 @@ -from blue_forecast import dict_sort, dict_rate - -d1 = {"01": 17, "09": 17, "03": 16, "10": 16, "14": 15, "15": 15, "11": 14, "02": 14, "07": 14, "06": 12, "12": 11, "08": 10, "16": 10, "05": 9, "13": 8, "04": 8} -d2 = {"01": 43, "09": 42, "04": 39, "15": 38, "06": 37, "08": 36, "10": 34, "16": 32, "11": 32, "05": 31, "12": 31, "03": 30, "02": 29, "14": 28, "07": 27, "13": 26} -d3 = {"15": 84, "10": 72, "06": 71, "08": 71, "16": 71, "01": 71, "05": 71, "07": 69, "11": 65, "09": 64, "13": 62, "14": 61, "04": 59, "02": 57, "12": 55, "03": 48} -d4 = {"15": 120, "11": 118, "16": 113, "05": 109, "08": 103, "09": 103, "07": 103, "12": 103, "06": 102, "14": 102, "04": 100, "02": 99, "10": 95, "03": 95, "13": 94, "01": 93} -d5 = {"15": 186, "16": 179, "11": 167, "06": 164, "07": 159, "13": 157, "12": 156, "14": 155, "02": 155, "03": 153, "05": 151, "09": 146, "04": 145, "08": 143, "01": 131, "10": 130} - -data_list = [d1, d2, d3, d4, d5] - -result = {} - -for d in data_list: - for k, v in d.items(): - if k in result.keys(): - result[k] += v - else: - result[k] = v - -print("新算法") -for k, v in dict_rate(dict_sort(result, 'val', True)).items(): - print(f"{k} - {v}") diff --git a/lottery_random.py b/lottery_random.py index c370f19..cbab06a 100644 --- a/lottery_random.py +++ b/lottery_random.py @@ -49,6 +49,7 @@ def print_time(): if __name__ == "__main__": - print_time() - print_num('red', get_num(new_num(33, 6), new_num(33, 6), 6)) - print_num('blue', get_num(new_num(16, 1), new_num(16, 1), 1)) + # print_time() + # print_num('red', get_num(new_num(33, 6), new_num(33, 6), 6)) + # print_num('blue', get_num(new_num(16, 1), new_num(16, 1), 1)) + print(new_num(33, 6)[0:6]) \ No newline at end of file diff --git a/new_blue_forecast.py b/new_blue_forecast.py new file mode 100644 index 0000000..00f4d5f --- /dev/null +++ b/new_blue_forecast.py @@ -0,0 +1,71 @@ +from blue_forecast import dict_sort, dict_rate +import pymysql +import json +from functools import reduce +from pymysql.cursors import DictCursor + +db = { + 'host': 'home.rogersun.online', + 'user': 'root', + 'password': 'Sxzgx1209', + 'database': 'lottery' +} + +d1 = {"06": 18, "08": 16, "10": 15, "16": 15, "04": 13, "15": 13, "01": 13, "11": 12, "09": 11, "13": 10, "14": 10, + "05": 10, "12": 10, "03": 8, "07": 7, "02": 6} +d2 = {"09": 45, "01": 44, "07": 43, "14": 43, "15": 42, "12": 42, "02": 38, "04": 37, "10": 37, "11": 35, "05": 31, + "16": 31, "03": 29, "08": 28, "06": 28, "13": 24} +d3 = {"01": 93, "09": 80, "10": 75, "15": 72, "16": 71, "03": 70, "08": 65, "11": 64, "06": 63, "02": 62, "04": 62, + "14": 61, "12": 61, "05": 61, "07": 55, "13": 55} +d4 = {"15": 126, "01": 121, "05": 116, "14": 112, "16": 112, "09": 111, "06": 108, "11": 107, "08": 106, "07": 106, + "10": 106, "04": 103, "13": 97, "02": 96, "12": 96, "03": 83} +d5 = {"15": 185, "16": 165, "11": 165, "06": 164, "05": 160, "14": 153, "08": 152, "12": 152, "07": 149, "09": 148, + "10": 147, "02": 145, "01": 144, "13": 142, "04": 141, "03": 131} + +data_list = [d1, d2, d3, d4, d5] + + +def get_history_date_id(): + conn = pymysql.Connect(**db) + cursor = conn.cursor(DictCursor) + cursor.execute("SELECT dateId FROM lottery.blue_forecast GROUP BY dateId ") + result = cursor.fetchall() + date_id_list = [] + for d in result: + date_id_list.append(d['dateId']) + return sorted(date_id_list, reverse=True)[0:5] + + +def get_forecast_blue(_date_id_list): + conn = pymysql.Connect(**db) + cursor = conn.cursor(DictCursor) + n = 1 + _blue_list = [] + for _id in _date_id_list: + cursor.execute("SELECT blue FROM lottery.blue_forecast WHERE dateId = %s AND params = %s", (_id, n)) + r = cursor.fetchone() + _blue = json.loads(r['blue']) + _blue_list.append(_blue) + n += 1 + return _blue_list + + +def new_blue_forecast(_blue_list): + result = {} + + for d in _blue_list: + for k, v in d.items(): + if k in result.keys(): + result[k] += v + else: + result[k] = v + + print("新算法") + for k, v in dict_rate(dict_sort(result, 'val', True)).items(): + print(f"{k} - {v}") + + +if __name__ == "__main__": + date_id_list = get_history_date_id() + blue_list = get_forecast_blue(date_id_list) + new_blue_forecast(blue_list) diff --git a/real_index.py b/real_index.py new file mode 100644 index 0000000..45a6aad --- /dev/null +++ b/real_index.py @@ -0,0 +1,72 @@ +import pymysql +import json +from functools import reduce +from pymysql.cursors import DictCursor + +db = { + 'host': 'home.rogersun.online', + 'user': 'root', + 'password': 'Sxzgx1209', + 'database': 'lottery' +} + +real_blue = ["01", "04", "09", "10", "20", "33"] + + +def get_real_data(): + conn = pymysql.Connect(**db) + cursor = conn.cursor(DictCursor) + cursor.execute("SELECT * FROM lottery.history ORDER BY id DESC LIMIT 1") + history_data = cursor.fetchone() + # print(history_data) + # [{'id': 2979, 'dateId': '2023035', 'openDate': datetime.date(2023, 3, 30), 'red': '["01", "04", "09", "10", "20", "33"]', 'blue': '06'}] + return history_data + + +def general_blue_index(_history_data): + conn = pymysql.Connect(**db) + cursor = conn.cursor(DictCursor) + cursor.execute("SELECT * FROM lottery.blue_forecast WHERE dateId = %s", (str(int(_history_data['dateId']) - 1)), ) + history_blue = cursor.fetchall() + # print(history_blue) + for data in history_blue: + n = 1 + for k, v in json.loads(data['blue']).items(): + if k == _history_data['blue']: + real_index = {'real_blue': _history_data['blue'], 'real_index': n} + cursor.execute("UPDATE lottery.blue_forecast SET comment = %s WHERE id = %s", + (json.dumps(real_index), data['id'])) + break + else: + n += 1 + conn.commit() + cursor.close() + + +def general_red_index(_history_data): + conn = pymysql.Connect(**db) + cursor = conn.cursor(DictCursor) + cursor.execute("SELECT * FROM lottery.red_forecast WHERE dateId = %s", (str(int(_history_data['dateId']) - 1)), ) + history_red = cursor.fetchone() + # print(history_red) + real_red = json.loads(_history_data['red']) + real_red_index = [] + n = 1 + + for red, _ in json.loads(history_red['red_rate']).items(): + if red in real_red: + real_red_index.append(n) + n += 1 + else: + n += 1 + # print(_history_data['red'], json.dumps(real_red_index), history_red['id']) + cursor.execute("UPDATE lottery.red_forecast SET real_result = %s, comments = %s WHERE id = %s", + (_history_data['red'], json.dumps(real_red_index), history_red['id'])) + conn.commit() + cursor.close() + + +if __name__ == "__main__": + history = get_real_data() + general_blue_index(history) + general_red_index(history) diff --git a/red_forecast.py b/red_forecast.py index 7fb725b..fe27ec8 100644 --- a/red_forecast.py +++ b/red_forecast.py @@ -2,6 +2,7 @@ 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', @@ -102,8 +103,17 @@ def get_red_forecast(_all_data, _red_data_dict, _red_data, range_num=1): for _red, __ in _red_forecast_dict.items(): _red_forecast_list.append(_red) - print('红球推荐:') + 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 @@ -118,6 +128,7 @@ def update_red_forecast_db(): 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))