Skip to content

Commit

Permalink
reworked how tables are filled
Browse files Browse the repository at this point in the history
  • Loading branch information
razaqq committed Jul 23, 2019
1 parent 9779a59 commit 52fff52
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 67 deletions.
67 changes: 10 additions & 57 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
QToolButton, QFileDialog, QItemDelegate, QHBoxLayout, QVBoxLayout, QStatusBar
from PyQt5.QtGui import QIcon, QFont, QPixmap, QDesktopServices
from PyQt5.QtCore import QRect, Qt, QUrl, QMetaObject
from assets.colors import Orange, Purple, Cyan, Pink, LGreen, DGreen, Yellow, Red, White
from utils.config import Config
from utils.logger import Logger
from version import __version__
Expand Down Expand Up @@ -292,64 +291,18 @@ def fill_tables(self, players):
y = tables[2]
tables[2] += 1

item = QTableWidgetItem(player.player_name)
item.setFont(QFont("Segoe UI", 10))
table.setItem(y, 0, item)

item = QTableWidgetItem(player.ship_name)
item.setFont(QFont("Segoe UI", 10, QFont.Bold))
table.setItem(y, 1, item)

if not player.hidden_profile:
matches = player.matches
wr = player.winrate
avg_dmg = player.avg_dmg

c = Purple() if matches > 20000 else Cyan() if matches > 14000 else LGreen() if matches > 9000 else \
Yellow() if matches > 5000 else Orange() if matches > 2000 else Red()
item = QTableWidgetItem(str(matches))
item.setFont(QFont("Segoe UI", 12, QFont.Bold))
item.setForeground(c)
item.setTextAlignment(Qt.AlignCenter)
table.setItem(y, 2, item)

c = Purple() if wr > 65 else Pink() if wr > 60 else Cyan() if wr > 56 else DGreen() if wr > 54 else \
LGreen() if wr > 52 else Yellow() if wr > 49 else Orange() if wr > 47 else Red()
item = QTableWidgetItem(str(wr))
item.setFont(QFont("Segoe UI", 12, QFont.Bold))
item.setForeground(c)
item.setTextAlignment(Qt.AlignCenter)
table.setItem(y, 3, item)

c = Pink() if avg_dmg > 48500 else Cyan() if avg_dmg > 38000 else LGreen() if avg_dmg > 33000 else \
Yellow() if avg_dmg > 22000 else Orange() if avg_dmg > 16000 else Red()
item = QTableWidgetItem(str(avg_dmg))
item.setForeground(c)
item.setTextAlignment(Qt.AlignCenter)
item.setFont(QFont("Segoe UI", 12, QFont.Bold))
table.setItem(y, 4, item)

# ship specific stats
if player.ship_name != 'Error':
item = QTableWidgetItem(str(player.matches_ship))
item.setFont(QFont("Segoe UI", 12, QFont.Bold))
for x in range(len(player.row)):
size = 10 if x < 2 else 12
font = QFont("Segoe UI", size, QFont.Bold) if x else QFont("Segoe UI", size)
item = QTableWidgetItem(player.row[x])
item.setFont(font)
if player.colors[x]:
item.setForeground(player.colors[x])
if x > 1:
item.setTextAlignment(Qt.AlignCenter)
table.setItem(y, 5, item)

wr_ship = player.winrate_ship
c = Purple() if wr_ship > 65 else Pink() if wr_ship > 60 else Cyan() if wr_ship > 56 else \
DGreen() if wr_ship > 54 else LGreen() if wr_ship > 52 else Yellow() if wr_ship > 49 else \
Orange() if wr_ship > 47 else Red()
item = QTableWidgetItem(str(wr_ship))
item.setFont(QFont("Segoe UI", 12, QFont.Bold))
item.setForeground(c)
item.setTextAlignment(Qt.AlignCenter)
table.setItem(y, 6, item)
else:
table.setItem(y, 5, QTableWidgetItem('Error'))
table.setItem(y, 6, QTableWidgetItem('Error'))
table.setItem(y, x, item)
x += 1

# table.resizeColumnsToContents()
for y in range(tables[1], 12):
for x in range(7):
self.left_table.setItem(y, x, QTableWidgetItem(''))
Expand Down
24 changes: 14 additions & 10 deletions potatoalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,16 @@
from asyncqt import QEventLoop
from utils.api import ApiWrapper
from utils.api_errors import InvalidApplicationIdError
from utils.stat_colors import color_avg_dmg, color_battles, color_winrate
from version import __version__


@dataclass()
class Player:
player_name: str
ship_name: str
team: int
hidden_profile: bool
matches: str
winrate: str
avg_dmg: str
matches_ship: str
winrate_ship: str
team: int
row: list
colors: list
class_ship: int # for sorting we keep track of these too
tier_ship: int
nation_ship: int
Expand Down Expand Up @@ -204,8 +200,16 @@ async def get_players(self, data: List[dict]) -> List[Player]:
if battles_ship and 'wins' in ship_stats: # check that at least one match in ship
winrate_ship = round(ship_stats['wins'] / battles_ship * 100, 1)

players.append(Player(player_name, ship_name, team, hidden_profile, battles, winrate, avg_dmg, battles_ship,
winrate_ship, class_ship, tier_ship, nation_ship))
row = [player_name, ship_name]
colors = [None, None]
if not hidden_profile:
row.extend([str(battles), str(winrate), str(avg_dmg)])
colors.extend([color_battles(battles), color_winrate(winrate), color_avg_dmg(avg_dmg)])
if ship_name != 'Error':
row.extend([str(battles_ship), str(winrate_ship)])
colors.extend([None, color_winrate(winrate_ship)])
p = Player(hidden_profile, team, row, colors, class_ship, tier_ship, nation_ship)
players.append(p)

return sorted(players, key=lambda x: (x.class_ship, x.tier_ship, x.nation_ship), reverse=True)

Expand Down

0 comments on commit 52fff52

Please sign in to comment.