mirror of
https://github.com/yusufipk/deste-hearthstone-linux-tracker.git
synced 2026-09-11 18:56:12 +00:00
Match history and win rate
Every finished match goes into a small sqlite database: mode, deck, both classes, result, turn count and who started. The result tag arrives in the last turn of the match, so the record is written then, not when the game object is closed (that only happens once the next match starts). The unique key is the session directory plus the match start time, so importing old session logs into the same database can be repeated without duplicates. The new window (from the menu) shows the totals, the win rate by deck and by opponent class, and the recent matches. Classes are drawn as hero portraits cut from the card render, with the class colour as a placeholder until the image is downloaded. Every table sorts by any column: the sort key is hidden data, not the visible text, so dates, turn counts and results sort correctly, and numeric columns start descending. tools/import_history.py backfills the database from the session logs already on disk, tests/test_history.py covers the date handling, the idempotency and the win rate maths.
This commit is contained in:
+52
-1
@@ -8,7 +8,7 @@ görselle birlikte satır tanınabilir oluyor.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PyQt6.QtCore import QPoint, QRect, QSize, Qt, QTimer
|
||||
from PyQt6.QtCore import QPoint, QRect, QRectF, QSize, Qt, QTimer
|
||||
from PyQt6.QtGui import (
|
||||
QColor,
|
||||
QFont,
|
||||
@@ -31,6 +31,57 @@ PREVIEW_DELAY_MS = 200
|
||||
HIDE_DELAY_MS = 140
|
||||
PREVIEW_GAP = 8
|
||||
|
||||
# Kahraman kartının render'ında yüzün bulunduğu kare: sol kenar, üst kenar ve
|
||||
# kenar uzunluğu, kart genişliğinin oranı olarak. Altın çerçeve dışarıda kalsın
|
||||
# diye deneyerek bulundu.
|
||||
PORTRAIT_CROP = (0.33, 0.18, 0.34)
|
||||
|
||||
|
||||
def _circle(size: int) -> QPainterPath:
|
||||
path = QPainterPath()
|
||||
path.addEllipse(QRectF(0.0, 0.0, float(size), float(size)))
|
||||
return path
|
||||
|
||||
|
||||
def color_dot(color: str, size: int) -> QPixmap:
|
||||
"""Sınıf rengiyle dolu daire. Portre inene kadarki yer tutucu."""
|
||||
pixmap = QPixmap(size, size)
|
||||
pixmap.fill(QColor(0, 0, 0, 0))
|
||||
painter = QPainter(pixmap)
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
painter.fillPath(_circle(size), QColor(color))
|
||||
painter.end()
|
||||
return pixmap
|
||||
|
||||
|
||||
def hero_portrait(path, size: int) -> QPixmap | None:
|
||||
"""Kahraman kartının render'ından daire portre keser."""
|
||||
source = QPixmap(str(path))
|
||||
if source.isNull():
|
||||
return None
|
||||
left, top, side = PORTRAIT_CROP
|
||||
crop = source.copy(
|
||||
QRect(
|
||||
int(source.width() * left),
|
||||
int(source.height() * top),
|
||||
int(source.width() * side),
|
||||
int(source.width() * side),
|
||||
)
|
||||
).scaled(
|
||||
size,
|
||||
size,
|
||||
Qt.AspectRatioMode.KeepAspectRatioByExpanding,
|
||||
Qt.TransformationMode.SmoothTransformation,
|
||||
)
|
||||
pixmap = QPixmap(size, size)
|
||||
pixmap.fill(QColor(0, 0, 0, 0))
|
||||
painter = QPainter(pixmap)
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
painter.setClipPath(_circle(size))
|
||||
painter.drawPixmap(0, 0, crop)
|
||||
painter.end()
|
||||
return pixmap
|
||||
|
||||
|
||||
class ElidedLabel(QLabel):
|
||||
"""Metni kısaltarak gösteren, genişliği pencereye dayatmayan etiket.
|
||||
|
||||
Reference in New Issue
Block a user