-
Notifications
You must be signed in to change notification settings - Fork 83
/
kl8_cash.py
186 lines (177 loc) · 8.53 KB
/
kl8_cash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# -*- coding:utf-8 -*-
"""
Author: KittenCN
"""
import pandas as pd
import argparse
from tqdm import tqdm
from config import *
from itertools import combinations
from loguru import logger
parser = argparse.ArgumentParser()
parser.add_argument('--name', default="kl8", type=str, help="lottery name")
parser.add_argument('--download', default=1, type=int, help="download data")
parser.add_argument('--cash_file_name', default="-1", type=str, help='cash_file_name')
parser.add_argument('--current_nums', default=-1, type=int, help='current nums')
parser.add_argument('--path', default="", type=str, help='path')
parser.add_argument('--simple_mode', default=0, type=int, help='simple mode')
parser.add_argument('--random_mode', default=0, type=int, help='random mode')
parser.add_argument('--cal_nums', default=10, type=int, help='cal_nums')
#--------------------------------------------------------------------------------------------------#
parser.add_argument('--limit_line', default=0, type=int, help='useless')
parser.add_argument('--total_create', default=50, type=int, help='useless')
parser.add_argument('--multiple', default=1, type=int, help='useless')
parser.add_argument('--multiple_ratio', default="1,0", type=str, help='useless')
parser.add_argument('--repeat', default=1, type=int, help='useless')
parser.add_argument('--calculate_rate', default=0, type=int, help='useless')
parser.add_argument('--calculate_rate_list', default="5", type=str, help='useless')
args = parser.parse_args()
if args.random_mode == 0:
if args.path == "":
file_path = "./results/"
else:
file_path = "./results_" + args.path + "/"
elif args.random_mode == 1:
if args.path == "":
file_path = "./random/"
else:
file_path = "./random_" + args.path + "/"
endstring = ["csv"]
name = args.name
nums_index = 0
cal_nums = int(args.cal_nums)
if args.download == 1:
from common import get_data_run
get_data_run(name=name, cq=0)
ori_data = pd.read_csv("{}{}".format(name_path[name]["path"], data_file_name))
ori_numpy = ori_data.drop(ori_data.columns[0], axis=1).to_numpy()[0][1:]
# if args.current_nums >= 0:
# index = ori_data.drop(ori_data.columns[0], axis=1).to_numpy()[0][0] - (args.current_nums + 1)
# if index >= 0:
# ori_numpy = ori_data.drop(ori_data.columns[0], axis=1).to_numpy()[index][1:]
cash_select_list = []
for i in range(0, 11):
_t = [element for element in range(i, -1, -1)]
cash_select_list.append(_t)
cash_price_list = [[5000000, 8000, 800, 80, 5, 3, 0, 0, 0, 0, 2], \
[300000, 2000, 200, 20, 5, 3, 0, 0, 0, 2], \
[50000, 800, 88, 10, 3, 0, 0, 0, 2], \
[10000, 288, 28, 4, 0, 0, 0, 2], \
[3000, 30, 10, 3, 0, 0, 0], \
[1000, 21, 3, 0, 0, 0], \
[100, 5, 3, 0, 0], \
[53, 3, 0, 0], \
[19, 0, 0], \
[4.6, 0]]
def check_lottery(cash_file_name, args, all_cash=0, all_lucky=0, path_mode=0):
global ori_numpy, nums_index, cal_nums
nums_index += 1
if args.current_nums >= ori_data.drop(ori_data.columns[0], axis=1).to_numpy()[-1][0] and args.current_nums <= ori_data.drop(ori_data.columns[0], axis=1).to_numpy()[0][0]:
index = ori_data.drop(ori_data.columns[0], axis=1).to_numpy()[0][0] - args.current_nums
if path_mode == 0:
logger.info("{}, 当前期数为{}。".format(args.path, args.current_nums))
if index >= 0:
ori_numpy = ori_data.drop(ori_data.columns[0], axis=1).to_numpy()[index][1:]
else:
if path_mode == 0:
logger.info("{}, 当前期数为{},计算期数为{}。".format(args.path, ori_data.drop(ori_data.columns[0], axis=1).to_numpy()[0][0], ori_data.drop(ori_data.columns[0], axis=1).to_numpy()[0][0]))
if path_mode == 0:
logger.info("{}, 中奖号码为:{}".format(args.path, ori_numpy))
cash_data = pd.read_csv(cash_file_name)
cash_numpy = cash_data.to_numpy()
if cal_nums >= 0:
cal_nums = cash_numpy.shape[1]
else:
cal_nums = abs(cal_nums)
cash_select = cash_select_list[cal_nums]
cash_price = cash_price_list[10 - (cal_nums)]
cash_list = [0] * len(cash_select)
x = 0
if args.simple_mode == 1:
sub_bar = tqdm(total=len(cash_numpy), leave=False)
for item in cash_numpy:
if args.simple_mode == 1:
sub_bar.update(1)
x += 1
for index in range(len(cash_select)):
ori_split = list(combinations(ori_numpy, cash_select[index]))
cash_split = list(combinations(item, cash_select[index]))
cash_set = set(ori_split) & set(cash_split)
if cash_select[index] != 0:
cash_list[index] += len(cash_set)
if cash_price[index] != 0 and len(cash_set) != 0:
if args.simple_mode == 0:
logger.info("{}, 第{}注, 号码{}中奖。".format(args.path, x, cash_set))
break
elif cash_select[index] == 0 and len(cash_set) == 0:
cash_list[index] += 1
if args.simple_mode == 0:
logger.info("{}, 第{}注, 号码{}中奖。".format(args.path, x, cash_set))
break
if args.simple_mode == 1:
sub_bar.close()
total_cash = 0
for i in range(len(cash_select)):
if args.simple_mode == 0:
logger.info("{}, 中{}个球,共{}注,奖金为{}元。".format(args.path, cash_select[i], cash_list[i], cash_list[i] * cash_price[i]))
total_cash += cash_list[i] * cash_price[i]
if args.simple_mode == 0 or (args.simple_mode == 2 and total_cash / (len(cash_numpy) * 2) * 100 >= 100):
logger.info("{}, 第{}张,本期共投入{}元,总奖金为{}元,返奖率{:.2f}%。".format(args.path, nums_index, len(cash_numpy) * 2, total_cash, total_cash / (len(cash_numpy) * 2) * 100))
all_cash += len(cash_numpy) * 2
all_lucky += total_cash
return all_cash, all_lucky
if __name__ == "__main__":
nums_index = 0
if args.path == "" or args.cash_file_name != "-1":
if args.random_mode == 0:
if args.path == "":
file_path = "./results/"
else:
file_path = "./results_" + args.path + "/"
elif args.random_mode == 1:
if args.path == "":
file_path = "./random/"
else:
file_path = "./random_" + args.path + "/"
if args.cash_file_name != "-1":
cash_file_name = file_path + args.cash_file_name + ".csv"
else:
## 寻找目录下最新的文件
import os
file_list = [_ for _ in os.listdir(file_path) if _.split('.')[1] in endstring]
file_list.sort(key=lambda fn: os.path.getmtime(file_path + fn))
cash_file_name = file_path + file_list[-1]
filename_split = file_list[-1].split('_')
if len(filename_split) == 4:
if int(filename_split[-1].split('.')[0]) > 0:
args.current_nums = int(filename_split[-1].split('.')[0])
check_lottery(cash_file_name=cash_file_name, args=args, path_mode=0)
else:
if args.random_mode == 0:
if args.path == "":
file_path = "./results/"
else:
file_path = "./results_" + args.path + "/"
elif args.random_mode == 1:
if args.path == "":
file_path = "./random/"
else:
file_path = "./random_" + args.path + "/"
all_cash, all_lucky = 0, 0
import os
file_list = [_ for _ in os.listdir(file_path) if _.split('.')[1] in endstring]
file_list.sort(key=lambda fn: os.path.getmtime(file_path + fn))
if args.simple_mode == 1:
pbar = tqdm(total=len(file_list), leave=True)
for filename in file_list:
if args.simple_mode == 1:
pbar.update(1)
cash_file_name = file_path + filename
filename_split = filename.split('_')
if len(filename_split) == 4:
if int(filename_split[-1].split('.')[0]) > 0:
args.current_nums = int(filename_split[-1].split('.')[0])
all_cash, all_lucky = check_lottery(cash_file_name=cash_file_name, args=args, all_cash=all_cash, all_lucky=all_lucky, path_mode=1)
if args.simple_mode == 1:
pbar.close()
logger.info("{}, 总投入{}元,总奖金为{}元,返奖率{:.2f}%。".format(args.path, all_cash, all_lucky, all_lucky / all_cash * 100))