This repository was archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
195 lines (158 loc) · 7.45 KB
/
main.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
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLineEdit, QListWidget, QLabel, QFormLayout, QVBoxLayout, QFileDialog, QCheckBox, QSpinBox, QComboBox
from PyQt5.QtGui import QIcon, QPixmap
import matplotlib.pyplot as plt
import pandas as pd
import requests
from PyQt5 import QtWidgets
class HiveStatsGUI(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# Widgets
self.player_name_input = QLineEdit()
self.game_input = QComboBox()
self.game_input.addItems(['wars', 'dr', 'hide', 'sg', 'murder', 'sky', 'ctf', 'drop', 'ground', 'build', 'party', 'bridge', 'grav'])
self.year_input = QLineEdit()
self.stats_checkboxes = []
self.num_months_spinbox = QSpinBox()
self.num_months_spinbox.setRange(1, 12)
self.num_months_spinbox.setValue(6)
self.graph_type_combo = QComboBox()
self.graph_type_combo.addItems(['line', 'bar'])
self.get_stats_button = QPushButton('Get Stats')
self.download_button = QPushButton('Download Graph')
self.graph_label = QLabel()
# Layout
self.form_layout = QFormLayout()
self.form_layout.addRow('Player Name', self.player_name_input)
self.form_layout.addRow('Game', self.game_input)
self.form_layout.addRow('Year', self.year_input)
vbox = QVBoxLayout()
vbox.addLayout(self.form_layout)
self.stats_vbox = QVBoxLayout()
vbox.addLayout(self.stats_vbox)
vbox.addWidget(self.num_months_spinbox)
vbox.addWidget(self.graph_type_combo)
vbox.addWidget(self.get_stats_button)
vbox.addWidget(self.download_button)
vbox.addWidget(self.graph_label)
self.setLayout(vbox)
# Connect signals
self.game_input.currentTextChanged.connect(self.update_stats)
self.get_stats_button.clicked.connect(self.get_stats)
self.download_button.clicked.connect(self.download_graph)
# Set window icon and settings
icon = QIcon('HiveLogo.png')
self.setWindowIcon(icon)
self.setGeometry(300, 300, 300, 500)
self.setWindowTitle('Hive Graphs')
self.show()
# Initialize with default stats
self.update_stats()
def update_stats(self):
# Remove old checkboxes
for checkbox in self.stats_checkboxes:
self.stats_vbox.removeWidget(checkbox)
checkbox.deleteLater()
self.stats_checkboxes.clear()
# Add checkboxes based on game
game = self.game_input.currentText()
if game == 'wars':
stats = ['kills', 'deaths', 'played', 'xp', 'victories', 'treasure_destroyed', 'final_kills', 'prestige', 'uncapped_xp']
elif game == 'dr':
stats = ['kills', 'deaths', 'played', 'xp', 'victories', 'activated', 'uncapped_xp']
elif game == 'hide':
stats = ['seeker_kills', 'hider_kills', 'deaths', 'played', 'xp', 'victories']
elif game == 'sg':
stats = ['kills', 'deaths', 'played', 'xp', 'victories', 'uncapped_xp']
elif game == 'murder':
stats = ['kills', 'deaths', 'played', 'xp', 'victories', 'prestige', 'uncapped_xp', 'murderer_eliminations', 'murders', 'coins']
elif game == 'sky':
stats = ['kills', 'deaths', 'played', 'xp', 'victories', 'mystery_chests_destroyed', 'uncapped_xp', 'spells_used', 'ores_mined']
elif game == 'ctf':
stats = ['kills', 'deaths', 'played', 'xp', 'victories', 'flags_returned', 'flags_captured', 'assists']
elif game == 'drop':
stats = ['vaults_used', 'deaths', 'played', 'xp', 'victories', 'powerups_collected', 'blocks_destroyed']
elif game == 'ground':
stats = ['kills', 'deaths', 'played', 'xp', 'victories', 'projectiles_fired', 'blocks_placed', 'blocks_destroyed']
elif game == 'build':
stats = ['rating_great_received', 'rating_okay_received', 'rating_meh_received', 'rating_love_received', 'rating_good_received', 'uncapped_xp', 'victories']
elif game == 'party':
stats = ['rounds_survived', 'played', 'xp', 'victories', 'powerups_collected']
elif game == 'bridge':
stats = ['kills', 'goals', 'deaths', 'played', 'xp', 'victories']
elif game == 'grav':
stats = ['maps_completed', 'maps_completed_without_dying', 'deaths', 'played', 'xp', 'victories']
for stat in stats:
checkbox = QCheckBox(stat)
self.stats_checkboxes.append(checkbox)
self.stats_vbox.addWidget(checkbox)
def download_graph(self):
path, _ = QFileDialog.getSaveFileName(self, 'Save Graph', 'graph.png', 'PNG(*.png)')
if path:
self.pixmap.save(path)
def get_stats(self):
# Validate input
if not self.game_input.currentText():
self.show_error("Game is required")
return
if not self.year_input.text():
self.show_error("Year is required")
return
# Get inputs
self.player_name = self.player_name_input.text()
game = self.game_input.currentText()
year = self.year_input.text()
num_months = self.num_months_spinbox.value()
# Get checked stats
stats = [cb.text() for cb in self.stats_checkboxes if cb.isChecked()]
# Get graph type
graph_type = self.graph_type_combo.currentText()
# Initialize data storage
monthly_data = []
# Get data for each month
for month in range(0, num_months+1):
url = f'https://api.playhive.com/v0/game/monthly/player/{game}/{self.player_name}/{year}/{month}'
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
except:
# Handle error
print(f"Error for {month}/{year}")
monthly_data.append({})
continue
if any(stat not in data for stat in stats):
# Data incomplete
print(f"Incomplete data for {month}/{year}")
monthly_data.append({})
else:
# Add actual data
monthly_data.append(data)
# Create DataFrame
df = pd.DataFrame(monthly_data)
# Generate graph
if graph_type == 'line':
ax = df[stats].plot.line(markevery=range(len(df)))
elif graph_type == 'bar':
ax = df[stats].plot.bar()
# Graph customization
ax.set_xlabel('Month')
ax.set_ylabel('Count')
fig = ax.get_figure()
fig.suptitle(f"{self.player_name} - {game} {year}", y=0.92)
fig.savefig('graph.png')
plt.close(fig)
# Display graph
self.pixmap = QPixmap('graph.png')
self.graph_label.setPixmap(self.pixmap)
def show_error(self, error_msg):
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage(error_msg)
error_dialog.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
gui = HiveStatsGUI()
sys.exit(app.exec_())