forked from arturino009/POEcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PoeCluster.py
221 lines (196 loc) · 7.25 KB
/
PoeCluster.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from updateClusterData import updateClusterData
import priceGetter
import time
from itertools import combinations
import webbrowser
import os
import json
import ctypes
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
def toggle_console(a):
# hiding the console
kernel32 = ctypes.WinDLL('kernel32')
user32 = ctypes.WinDLL('user32')
SW_HIDE = a
hWnd = kernel32.GetConsoleWindow()
if hWnd:
user32.ShowWindow(hWnd, SW_HIDE)
def open_link(q):
id = q.id
webbrowser.open('https://www.pathofexile.com/trade/search/' +
priceGetter.current_league + '/' + id)
class Dialog(QDialog):
def __init__(self, file_dir, parent=None):
super(Dialog, self).__init__(parent)
layout = QGridLayout()
self.setLayout(layout)
countbutton1 = QRadioButton("Single notable")
countbutton1.setChecked(True)
countbutton1.type = 1
countbutton1.layout = layout
layout.addWidget(countbutton1, 0, 0)
countbutton2 = QRadioButton("Double notable")
# radiobutton.setChecked(True)
countbutton2.type = 0
countbutton2.layout = layout
layout.addWidget(countbutton2, 0, 1)
clustersizebutton1 = QRadioButton("Small cluster jewels")
# radiobutton.setChecked(True)
clustersizebutton1.type = 1
clustersizebutton1.layout = layout
clustersizebutton1.toggled.connect(self.onClicked)
layout.addWidget(clustersizebutton1, 1, 0)
clustersizebutton2 = QRadioButton("Medium cluster jewels")
clustersizebutton2.type = 0
clustersizebutton2.layout = layout
clustersizebutton2.toggled.connect(self.onClicked)
layout.addWidget(clustersizebutton2, 1, 1)
self.btngroup1 = QButtonGroup()
self.btngroup2 = QButtonGroup()
self.btngroup1.addButton(countbutton1)
self.btngroup1.addButton(countbutton2)
self.btngroup2.addButton(clustersizebutton1)
self.btngroup2.addButton(clustersizebutton2)
def deleteAllWidgetsUntil(self, a):
layout = self.layout
for i in reversed(range(layout.count())):
layout.itemAt(i).widget().setParent(None)
if i == a:
break
def onClicked(self):
clustersizebutton = self.sender()
layout = clustersizebutton.layout
if clustersizebutton.type == 1:
location = file_dir + "/small.json"
else:
location = file_dir + "/medium.json"
with open(location) as json_file:
all_lists = json.load(json_file)
count = 1
if layout.count() > 4:
self.layout = layout
self.deleteAllWidgetsUntil(4)
for category in all_lists:
count += 1
clusterbox = QCheckBox(category['clusterName'])
clusterbox.setChecked(True)
clusterbox.type = category['clusterName']
layout.addWidget(clusterbox, count, 0)
executebutton = QPushButton("Execute")
executebutton.layout = layout
executebutton.clicked.connect(self.onExecute)
layout.addWidget(executebutton, layout.count(), 0)
def onExecute(self):
button = self.sender()
layout = button.layout
if layout.itemAt(1).widget().isChecked() and layout.itemAt(2).widget().isChecked():
print("Can't get double notables for small cluster jewels!")
return
result = []
for i in range(layout.count()):
widget = layout.itemAt(i).widget()
if widget.isChecked():
result.append(widget.type)
if len(result) == 2:
print("No categories selected!")
return
self.result = result
self.accept()
try:
file_dir = "data/" + priceGetter.current_league
if (os.path.exists(file_dir) == False):
print("Didn't find data for current league. Updating...")
updateClusterData()
app = QApplication([])
dialog = Dialog(file_dir)
dialog.show()
if dialog.exec_():
resultList = dialog.result
try:
query = resultList[0]
except NameError:
sys.exit()
inp = resultList[1]
if query == 1:
location = file_dir + "/small.json" if inp == 1 else file_dir + "/medium.json"
else:
location = file_dir + "/medium.json"
all_lists = list()
# import all the data from file to memory
with open(location) as json_file:
all_lists = json.load(json_file)
finalfinallist = []
for item in all_lists:
if item['clusterName'] in resultList:
finalfinallist.append(item)
all_lists = finalfinallist
# start the timer for program execution
start_time = time.time()
levelBreakpoints = [1,50,68,75]
levelRequests = len(levelBreakpoints) * len(all_lists)
notableRequests = 0
if query == 2:
for a in all_lists:
notableRequests += a['clusterNotableCombinationCount']
else:
for a in all_lists:
notableRequests += a['clusterNotableCount']
print("Requests to make: " + str((levelRequests + notableRequests)))
# list of all values that I will get
all_averages = list()
for a in all_lists:
if query == 1:
comb = a['clusterNotables']
else:
# make a list of all possible combinations of items in each category
comb = list(combinations(a['clusterNotables'], 2))
lvlPrice = list()
for lvl in levelBreakpoints:
x = {
'lvl': lvl,
'price': priceGetter.get_category_jewel_price(a, lvl)
}
lvlPrice.append(x)
a['breakpointPrices'] = lvlPrice
for b in comb:
if query == 1:
min_lvl = b['notableLevel']
else:
seq = [x['notableLevel'] for x in b]
min_lvl = max(seq)
for item in a['breakpointPrices']:
if item['lvl'] == min_lvl:
jewel_price = item['price']
break
notableData = priceGetter.getNotablePrice(a, b, query, inp, jewel_price)
if notableData != 0:
all_averages.append(notableData)
toggle_console(0)
#print(all_averages)
keys_to_remove = ["request", "category_full", "notable_full"]
for item in all_averages:
for key in keys_to_remove:
del item[key]
tableWidget = QTableWidget()
row_count = len(all_averages)
column_count = len(all_averages[0])
tableWidget.setColumnCount(column_count)
tableWidget.setRowCount(row_count)
tableWidget.setHorizontalHeaderLabels((list(all_averages[0].keys())))
for row in range(row_count): # add items from array to QTableWidget
for column in range(column_count):
item = QTableWidgetItem()
item.id = list(all_averages[row].values())[11]
item.setData(Qt.EditRole, (list(all_averages[row].values())[column]))
tableWidget.setItem(row, column, item)
tableWidget.setColumnHidden(11, True)
tableWidget.setSortingEnabled(True)
tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
tableWidget.itemDoubleClicked.connect(open_link)
tableWidget.show()
app.exec_()
except Exception as e:
print(e)
stop = int(input())