-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_parser.py
100 lines (87 loc) · 3.3 KB
/
data_parser.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
from collections import OrderedDict
def countX(lst, x):
count = 0
for ele in lst:
if (ele == x):
count = count + 1
return count
class DataParser:
def __init__(self, data: dict):
self.data = data
def most_common_white_numbers(self):
list_dict = {
'list_first': [],
'list_second': [],
'list_third': [],
'list_fourth': [],
'list_fifth': [],
# 'list_pb': []
}
for draw in self.data['data']:
list_dict['list_first'].append(draw['FirstNumber'])
list_dict['list_second'].append(draw['SecondNumber'])
list_dict['list_third'].append(draw['ThirdNumber'])
list_dict['list_fourth'].append(draw['FourthNumber'])
list_dict['list_fifth'].append(draw['FifthNumber'])
# list_dict['list_pb'].append(draw['PowerBall'])
final = []
for lst in list_dict:
for x in list_dict[lst]:
dup = 0
# print(x)
if not final:
single_data = {
'number': x,
'occurrences': countX(list_dict[lst], x)
}
final.append(single_data)
else:
for item in final:
# print(f'Item: {item}')
if x == item['number']:
dup += 1
if dup == 0:
single_data = {
'number': x,
'occurrences': countX(list_dict[lst], x)
}
final.append(single_data)
# print('{} has occurred {} times'.format(x, countX(list_dict[lst], x)))
dict1 = sorted(final, key=lambda d: d['occurrences'], reverse=True)
print(f'White: {dict1[0:5]}')
def most_common_pb_numbers(self):
list_dict = {
'list_pb': []
}
for draw in self.data['data']:
list_dict['list_pb'].append(draw['PowerBall'])
final = []
for lst in list_dict:
for x in list_dict[lst]:
dup = 0
# print(x)
if not final:
single_data = {
'number': x,
'occurrences': countX(list_dict[lst], x)
}
final.append(single_data)
else:
for item in final:
# print(f'Item: {item}')
if x == item['number']:
dup += 1
if dup == 0:
single_data = {
'number': x,
'occurrences': countX(list_dict[lst], x)
}
final.append(single_data)
# print('{} has occurred {} times'.format(x, countX(list_dict[lst], x)))
dict1 = sorted(final, key=lambda d: d['occurrences'], reverse=True)
print(f'PB: {dict1[0]}')
def compare_my_numbers(self, mynumbers: list):
matched = {}
count = 1
res = [x for x in self.data['data'] + mynumbers if x not in self.data['data'] or x not in mynumbers]
print(res)