Files
DeepLottery/2_FilterTestReview_22.py
dsyoon c611b400ae init
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-25 18:32:11 +09:00

94 lines
3.3 KiB
Python

import os
import time
import datetime
import pandas as pd
import itertools
from BallFilter_22 import BallFilter
class FilterTestReview:
ballFilter = None
def __init__(self, resources_path):
lottoHistoryFileName = os.path.join(resources_path, 'lotto_history.json')
self.ballFilter = BallFilter(lottoHistoryFileName)
return
def validate(self, df_ball, nos=None):
win_history = {}
for no in nos:
print("[{} 회차]".format(no))
balls = df_ball[df_ball['no'] == no].values.tolist()[0]
answer = balls[1:7]
bonus = balls[7]
final_candidates = []
win_dic = {1: [], 2: [], 3: [], 4: [], 5: []}
generation_balls = list(range(1, 46))
nCr = list(itertools.combinations(generation_balls, 6))
for idx, ball in enumerate(nCr):
if idx % 1000000 == 0:
print(" - {} processed...".format(idx))
ball = list(ball)
filter_type = self.ballFilter.filter(ball=ball, no=no, until_end=False, df=df_ball)
filter_size = len(filter_type)
if 0 < filter_size:
continue
final_candidates.append(ball)
match = len(set(ball) & set(answer))
if match == 6:
win_history[no] = answer
win_dic[1].append(ball)
else:
if match == 3:
win_dic[5].append(ball)
elif match == 4:
win_dic[4].append(ball)
elif match == 5:
answer.append(bonus)
if len(set(ball) & set(answer)) == 6:
win_dic[2].append(ball)
else:
win_dic[3].append(ball)
print("no: {}, answer: {}, size: {}".format(no, str(answer), len(final_candidates)))
print(" > 1등: {}, 2등: {}, 3등: {}, 4등: {}, 5등: {}".format(len(win_dic[1]), len(win_dic[2]), len(win_dic[3]), len(win_dic[4]), len(win_dic[5])))
return win_history
if __name__ == '__main__':
PROJECT_HOME = '.'
resources_path = os.path.join(PROJECT_HOME, 'resources')
lottoHistoryFileName = os.path.join(resources_path, 'lotto_history.txt')
df_ball = pd.read_csv(lottoHistoryFileName, header=None)
df_ball.columns = ['no', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'bn']
filterTestReview = FilterTestReview(resources_path)
start = time.time()
#win_history = filterTest.validate(df_ball, nos =[1046,1022,1004,900,869,816,797,696,574,524,523,461,356,324,303,289,147,71], filter_ball = [1,2,4,6,10,11,11,17,18,20,21,22,23,24,26,27,28,30,31,32,33,34,37,38,39,40,42,44])
win_history = filterTestReview.validate(
df_ball,
#nos=range(1126, 21, -1),
nos=[1165,1164,1163,1162,1161,1160,1159,1158,1157,1156,1155,1154,1153,1152,1151,1150,1149,1148,1147,1146])
process_time = datetime.timedelta(seconds=time.time() - start)
print("process_time: ", process_time)
print("{} 회 당첨".format(len(win_history)))
sorted_win_history = sorted(win_history.keys())
for i in range(len(sorted_win_history)):
print("\t>{} > {}".format(sorted_win_history[i], str(win_history[sorted_win_history[i]])))