99 lines
3.7 KiB
Python
99 lines
3.7 KiB
Python
import os
|
|
import time
|
|
import datetime
|
|
import pandas as pd
|
|
import itertools
|
|
from filter_model_3 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 = {}
|
|
win_history_size = {}
|
|
|
|
for no in nos:
|
|
|
|
print("[{} 회차]".format(no))
|
|
balls = df_ball[df_ball['no'] == no].values.tolist()[0]
|
|
answer = balls[1:7].copy() # copy()로 복사
|
|
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:
|
|
if no not in win_history: # 중복 방지
|
|
win_history[no] = answer.copy() # copy()로 복사
|
|
if ball not in win_dic[1]: # 같은 조합 중복 방지
|
|
win_dic[1].append(ball.copy()) # copy()로 복사
|
|
|
|
else:
|
|
if match == 3:
|
|
win_dic[5].append(ball)
|
|
elif match == 4:
|
|
win_dic[4].append(ball)
|
|
elif match == 5:
|
|
# 2등 판별: 5개 맞고 보너스 번호 포함
|
|
if bonus in ball:
|
|
win_dic[2].append(ball)
|
|
else:
|
|
win_dic[3].append(ball)
|
|
|
|
win_history_size[no] = len(final_candidates)
|
|
|
|
print("no: {}, answer: {}, size: {}".format(no, 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, win_history_size
|
|
|
|
|
|
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, win_history_size = filterTestReview.validate(
|
|
df_ball,
|
|
#nos=range(1126, 21, -1),
|
|
nos=[1057,1046,1022,900,841,816,696,593,574,426,356,324,303,245,147,139,71])
|
|
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], win_history[sorted_win_history[i]], win_history_size[sorted_win_history[i]])) |