from db import * from util import * # last_data = get_last_data() # print(last_data) # # date_id_data = get_data_by_date_id('2023068') # print(date_id_data) # 获取全部数据 def get_all_data(): return db_get_all_data() # 获取所有篮球的统计数据 def get_all_blue(): all_blue = dict() all_data = db_get_all_data() if all_data is not False: for data in all_data: if data['blue'] in all_blue.keys(): all_blue[data['blue']] += 1 else: all_blue[data['blue']] = 1 return dict_sort(all_blue) else: return False # 获取蓝球统计次数与平均值的额偏差 def get_delta_blue(_blue_data): total = 0 if _blue_data is not False: for _num in _blue_data.values(): total += _num average = total / len(_blue_data.keys()) print(average) _delta_blue_dict = dict() for _key, _val in _blue_data.items(): _delta_blue_dict[_key] = _blue_data[_key] - average return _delta_blue_dict print(get_delta_blue(get_all_blue())) def get_all_prv_blue_list(_all_data, _last_blue_list, _num): all_prv_blue_list = [] min_id, max_id = 1, _all_data[-1]['id'] # 获取最大和最小id for n in range(len(_last_blue_list)): # print(_last_blue_list[n]) for _data in _all_data: if _data['blue'] == _last_blue_list[n]: _id = _data['id'] + _num - n if min_id <= _id <= max_id: # print(f"{_data['id']} - {_id}") all_prv_blue_list.append(_id) return sorted(set(all_prv_blue_list)) # 获取预测的数据 def get_blue_forecast(_all_data, _method, _num): last_blue = db_get_last_data()['blue'] if last_blue is False: return False blue_id_list = [] for _data in _all_data: if _data['blue'] == last_blue: blue_id_list.append(_data['id']) print(blue_id_list) min_id, max_id = 1, _all_data[-1]['id'] # 获取最大和最小id """ 当_num=3时 先取当前一期的蓝球号码,然后计算历史上相同蓝球出现的后一期蓝球 然后往前推一期,取这一期蓝球号码,统计这个号码后两期的蓝球(不包含后一期) 然后再往前推一期,取这一期蓝球号码,统计这个号码后三期的蓝球(不包含后一期和后两期) """ if _method == 'prv': # 当前一期往前推num期,包含此期数据 recent_blue_id_list = [d['blue'] for d in _all_data[-_num:]] prv_blue_id_list = get_all_prv_blue_list(_all_data, recent_blue_id_list, _num) print(prv_blue_id_list) elif _method == 'post': # 当前一期往后num期,不包含此期的数据 pass else: return False get_blue_forecast(get_all_data(), 'prv', 5)