Repository cleanup
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
from .app import run
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from PySide2.QtWidgets import QMessageBox
|
||||
|
||||
|
||||
text = """
|
||||
This software is free to use and delivered to you with a lot on fun :)
|
||||
|
||||
If somebody ask you how to get it, just tell him/her to google 'albion online stats github'
|
||||
|
||||
Feel free to donate me with some in-game silver or support me on patronite.
|
||||
|
||||
Quick contact - catch me on discord JaWiktor#1717
|
||||
|
||||
See you in game, WedrowyczJakub
|
||||
"""
|
||||
|
||||
class About(QMessageBox):
|
||||
def __init__(self):
|
||||
QMessageBox.__init__(self)
|
||||
self.setIcon(QMessageBox.Information)
|
||||
self.setWindowTitle("Albion online stats")
|
||||
self.setText(text)
|
||||
self.setInformativeText('<a href="{}"> Report Bug/Feature request </a> | <a href="{}"> Contribute </a> | <a href="{}"> Download </a> | <a href="{}"> Donate </a>'.format(
|
||||
"https://github.com/mazurwiktor/albion-online-stats/issues/new/choose",
|
||||
"https://github.com/mazurwiktor/albion-online-stats",
|
||||
"https://github.com/mazurwiktor/albion-online-stats/releases/latest",
|
||||
"https://www.patreon.com/wiktormazur",
|
||||
))
|
||||
self.setStandardButtons(QMessageBox.Ok)
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.abspath('__file__')))
|
||||
|
||||
from PySide2.QtCore import Qt
|
||||
from PySide2.QtWidgets import QApplication
|
||||
from PySide2.QtWidgets import QMessageBox
|
||||
|
||||
from .config import config
|
||||
from .main import MainWidget
|
||||
from .engine import initialize
|
||||
from .styling import style
|
||||
from .version import current_version as get_current_version
|
||||
from .version import latest_version as get_latest_version
|
||||
from .version import latest_url
|
||||
|
||||
def run():
|
||||
initialize()
|
||||
conf = config()
|
||||
window_config = conf['window']
|
||||
|
||||
WIDTH = window_config['width']
|
||||
HEIGHT = window_config['height']
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
app.setStyleSheet(style)
|
||||
|
||||
geometry = app.screens()[0].size()
|
||||
|
||||
widget = MainWidget()
|
||||
widget.setWindowOpacity(window_config['opacity'])
|
||||
widget.resize(WIDTH, HEIGHT)
|
||||
widget.move(0, geometry.height() - HEIGHT - 280)
|
||||
|
||||
widget.setWindowTitle('Damage Meter')
|
||||
|
||||
widget.setWindowFlag(Qt.WindowStaysOnTopHint)
|
||||
widget.setWindowFlag(Qt.FramelessWindowHint)
|
||||
widget.show()
|
||||
|
||||
current_version, latest_version = (get_current_version(), get_latest_version())
|
||||
|
||||
if latest_version and current_version != latest_version:
|
||||
msg = QMessageBox()
|
||||
msg.setIcon(QMessageBox.Warning)
|
||||
msg.setWindowTitle("Update available!")
|
||||
msg.setText("Another version of app is avaliable.")
|
||||
msg.setInformativeText("You are using app in version {}, new version {} available <a href='{}'>here</a>".format(
|
||||
current_version, latest_version, latest_url))
|
||||
msg.setStandardButtons(QMessageBox.Ok)
|
||||
msg.show()
|
||||
|
||||
sys.exit(app.exec_())
|
||||
@@ -0,0 +1,48 @@
|
||||
import os
|
||||
import sys
|
||||
import toml
|
||||
|
||||
CFG_VERSION = '0.2'
|
||||
|
||||
default = """
|
||||
[window]
|
||||
width = 300
|
||||
height = 230
|
||||
font-size = '10px'
|
||||
opacity = 0.5
|
||||
|
||||
[app]
|
||||
skip_non_party_players = true
|
||||
|
||||
[config]
|
||||
# do not change
|
||||
version = '%s'
|
||||
""" % (CFG_VERSION)
|
||||
|
||||
|
||||
_script_path = sys.argv[0] # pyinstaller creates tmpdir for python files, thus this is the way to get executable path
|
||||
_config = None
|
||||
|
||||
def config():
|
||||
global _script_path
|
||||
global _config
|
||||
|
||||
if _config:
|
||||
return _config
|
||||
|
||||
conf_file = os.path.join(os.path.dirname(
|
||||
_script_path), 'albion-online-stats.cfg')
|
||||
|
||||
try:
|
||||
with open(conf_file, "r") as cfg_file:
|
||||
cfg = toml.load(cfg_file)
|
||||
if cfg['config']['version'] != CFG_VERSION:
|
||||
print('version changed')
|
||||
raise Exception('Version changed')
|
||||
return cfg
|
||||
except(Exception) as e:
|
||||
with open(conf_file, "w") as cfg_file:
|
||||
cfg_file.write(default)
|
||||
return toml.loads(default)
|
||||
|
||||
return {}
|
||||
@@ -0,0 +1,122 @@
|
||||
import os
|
||||
|
||||
import aostats
|
||||
|
||||
from .config import config
|
||||
|
||||
TESTING_ENABLED = bool(os.getenv('TESTING'))
|
||||
|
||||
|
||||
class StatType:
|
||||
Unknown = 0
|
||||
LastFight = 1
|
||||
Zone = 2
|
||||
Overall = 3
|
||||
|
||||
|
||||
class DamageStat:
|
||||
def __init__(self, name, damage, time_in_combat, dps, precentage):
|
||||
self.name = name
|
||||
self.damage = '{0:.2f}'.format(damage)
|
||||
self.time_in_combat = '{0:.2f}'.format(time_in_combat)
|
||||
self.dps = '{0:.2f}'.format(dps)
|
||||
self.precentage = '{0:.2f}'.format(precentage)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.name == other.name and self.damage == other.damage and self.time_in_combat == other.time_in_combat and self.dps == other.dps
|
||||
|
||||
|
||||
class FameStat:
|
||||
def __init__(self, fame, fame_per_minute):
|
||||
self.fame = '{0:.2f}'.format(fame)
|
||||
self.fame_per_minute = fame_per_minute
|
||||
|
||||
|
||||
def stats(session):
|
||||
with_damage = [s for s in session if s['damage'] != 0.0]
|
||||
extended_session = with_precentage(with_damage)
|
||||
statistics = [DamageStat(s['player'], s['damage'], s['time_in_combat'], s['dps'], s['dmg_precentage']) for s in extended_session]
|
||||
stats_with_fame = [p for p in session if 'fame' in p and p['fame'] != 0.0]
|
||||
|
||||
if len(stats_with_fame) > 0:
|
||||
stat_with_fame = stats_with_fame[0]
|
||||
fame = FameStat(stat_with_fame['fame'], stat_with_fame['fame_per_minute'])
|
||||
else:
|
||||
fame = FameStat(0.0, 0.0)
|
||||
|
||||
return statistics, fame
|
||||
|
||||
|
||||
def with_precentage(session):
|
||||
|
||||
damage_done = 0.0
|
||||
for s in session:
|
||||
damage_done += s['damage']
|
||||
|
||||
for s in session:
|
||||
s['dmg_precentage'] = s['damage'] / damage_done * 100
|
||||
|
||||
return session
|
||||
|
||||
def zone_stats():
|
||||
if TESTING_ENABLED:
|
||||
session = [
|
||||
{'player': 'A'*20, 'damage': 1234.02,
|
||||
'time_in_combat': 12.0, 'dps': 12.4234, 'fame': 20.0, 'fame_per_minute': 30},
|
||||
{'player': 'B'*20, 'damage': 5435.02, 'time_in_combat': 12.0, 'dps': 12},
|
||||
{'player': 'C'*20, 'damage': 23.02, 'time_in_combat': 12.0, 'dps': 13},
|
||||
{'player': 'D'*20, 'damage': 0, 'time_in_combat': 12.0, 'dps': 0}
|
||||
]
|
||||
else:
|
||||
session = aostats.stats(StatType.Zone)
|
||||
|
||||
return stats(session)
|
||||
|
||||
|
||||
def overall_stats():
|
||||
if TESTING_ENABLED:
|
||||
session = [
|
||||
{'player': 'overall', 'damage': 1234.02,
|
||||
'time_in_combat': 12.0, 'dps': 12.4234},
|
||||
]
|
||||
else:
|
||||
session = aostats.stats(StatType.Overall)
|
||||
|
||||
return stats(session)
|
||||
|
||||
|
||||
def last_fight_stats():
|
||||
if TESTING_ENABLED:
|
||||
session = [
|
||||
{'player': 'last fight', 'damage': 1234.02,
|
||||
'time_in_combat': 12.0, 'dps': 12.4234},
|
||||
]
|
||||
else:
|
||||
session = aostats.stats(StatType.LastFight)
|
||||
|
||||
return stats(session)
|
||||
|
||||
def get_party_members():
|
||||
if TESTING_ENABLED:
|
||||
return ['a', 'b', 'c']
|
||||
else:
|
||||
return aostats.get_players_in_party()
|
||||
|
||||
|
||||
def reset_zone_stats():
|
||||
aostats.reset(StatType.Zone)
|
||||
|
||||
def reset_last_fight_stats():
|
||||
aostats.reset(StatType.LastFight)
|
||||
|
||||
def reset_stats():
|
||||
aostats.reset(StatType.Overall)
|
||||
|
||||
def initialize():
|
||||
if TESTING_ENABLED:
|
||||
return
|
||||
cfg = config()
|
||||
try:
|
||||
aostats.initialize(cfg['app']['skip_non_party_players'])
|
||||
except:
|
||||
pass
|
||||
@@ -0,0 +1,134 @@
|
||||
import sys
|
||||
|
||||
from PySide2.QtCore import QTimer
|
||||
from PySide2.QtCore import Qt
|
||||
|
||||
from PySide2.QtWidgets import QHBoxLayout
|
||||
from PySide2.QtWidgets import QPushButton
|
||||
from PySide2.QtWidgets import QVBoxLayout
|
||||
from PySide2.QtWidgets import QWidget
|
||||
from PySide2.QtWidgets import QLabel
|
||||
from PySide2.QtWidgets import QComboBox
|
||||
|
||||
import clipboard
|
||||
|
||||
from .table import Table
|
||||
from . import about
|
||||
from . import engine
|
||||
|
||||
class Mode:
|
||||
CURRENT_ZONE = 'Statistics: Current zone'
|
||||
OVERALL = 'Statistics: Overall'
|
||||
LAST_FIGHT = 'Statistics: Last fight'
|
||||
|
||||
|
||||
class BottomButtons(QWidget):
|
||||
def __init__(self, table, mode):
|
||||
QWidget.__init__(self)
|
||||
self.mode = mode
|
||||
self.table = table
|
||||
self.layout = QHBoxLayout()
|
||||
self.about = about.About()
|
||||
|
||||
self.copy_button = QPushButton("&Copy", self)
|
||||
self.reset_button = QPushButton("&Reset", self)
|
||||
self.close_button = QPushButton("&Close", self)
|
||||
self.about_button = QPushButton("&About", self)
|
||||
self.layout.addWidget(self.copy_button)
|
||||
self.layout.addWidget(self.reset_button)
|
||||
self.layout.addWidget(self.about_button)
|
||||
self.layout.addWidget(self.close_button)
|
||||
self.setLayout(self.layout)
|
||||
|
||||
self.copy_button.clicked.connect(self.copy)
|
||||
self.reset_button.clicked.connect(self.reset)
|
||||
self.close_button.clicked.connect(self.close)
|
||||
self.about_button.clicked.connect(self.about.show)
|
||||
|
||||
self.copy_button.setObjectName('BottomButtons')
|
||||
self.reset_button.setObjectName('BottomButtons')
|
||||
self.about_button.setObjectName('BottomButtons')
|
||||
self.close_button.setObjectName('BottomButtons')
|
||||
|
||||
def copy(self):
|
||||
clip = "{}\n".format(self.mode())
|
||||
for i in range(self.table.rowCount()):
|
||||
clip += '{}. {} {}-{}-{}%'.format(i+1, self.table.item(i, 0).text(
|
||||
), self.table.item(i, 1).text(), self.table.item(i, 2).text(), self.table.item(i, 3).text())
|
||||
clip += "\n"
|
||||
clipboard.copy(clip)
|
||||
|
||||
def reset(self):
|
||||
reset = {
|
||||
Mode.CURRENT_ZONE: engine.reset_zone_stats,
|
||||
Mode.LAST_FIGHT: engine.reset_last_fight_stats,
|
||||
Mode.OVERALL: engine.reset_stats
|
||||
}
|
||||
|
||||
reset[self.mode()]()
|
||||
|
||||
def close(self):
|
||||
sys.exit(0)
|
||||
|
||||
class ModeWidget(QComboBox):
|
||||
def __init__(self):
|
||||
QComboBox.__init__(self)
|
||||
|
||||
self.addItem(Mode.CURRENT_ZONE)
|
||||
self.addItem(Mode.OVERALL)
|
||||
self.addItem(Mode.LAST_FIGHT)
|
||||
|
||||
|
||||
class MainWidget(QWidget):
|
||||
def __init__(self):
|
||||
QWidget.__init__(self)
|
||||
|
||||
self.mouse_pos = None
|
||||
self.mode = ModeWidget()
|
||||
self.table = Table()
|
||||
self.fame_label = QLabel()
|
||||
self.bottom_buttons = BottomButtons(
|
||||
self.table, lambda: self.mode.currentText())
|
||||
|
||||
self.layout = QVBoxLayout()
|
||||
self.layout.addWidget(self.mode)
|
||||
self.layout.addWidget(self.fame_label)
|
||||
self.layout.addWidget(self.table)
|
||||
self.layout.addWidget(self.bottom_buttons)
|
||||
self.setLayout(self.layout)
|
||||
|
||||
self.refresh()
|
||||
|
||||
timer = QTimer(self)
|
||||
timer.timeout.connect(self.refresh)
|
||||
timer.start(500)
|
||||
|
||||
def refresh(self):
|
||||
damage_session, fame_stat = self.session()
|
||||
self.table.fill(damage_session)
|
||||
self.fame_label.setText("Fame <b>{}</b> | Fame per minute <b>{}</b> | Party members <b>{}</b>".format(
|
||||
fame_stat.fame, fame_stat.fame_per_minute, len(engine.get_party_members())))
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
self.mouse_pos = event.pos()
|
||||
|
||||
def mouseMoveEvent(self, event):
|
||||
if self.mode.geometry().contains(event.pos()):
|
||||
return
|
||||
if not self.mouse_pos:
|
||||
return
|
||||
|
||||
if event.buttons() & Qt.LeftButton:
|
||||
diff = event.pos() - self.mouse_pos
|
||||
newpos = self.pos() + diff
|
||||
|
||||
self.move(newpos)
|
||||
|
||||
def session(self):
|
||||
sessions = {
|
||||
Mode.CURRENT_ZONE: engine.zone_stats,
|
||||
Mode.LAST_FIGHT: engine.last_fight_stats,
|
||||
Mode.OVERALL: engine.overall_stats
|
||||
}
|
||||
|
||||
return sessions[self.mode.currentText()]()
|
||||
@@ -0,0 +1,16 @@
|
||||
from .config import config
|
||||
|
||||
cfg = config()
|
||||
font_size = cfg['window']['font-size']
|
||||
|
||||
style = """
|
||||
QWidget {
|
||||
font-size: %s;
|
||||
}
|
||||
QListView {
|
||||
min-height: 100px;
|
||||
}
|
||||
QPushButton {
|
||||
max-width: 60px;
|
||||
}
|
||||
""" % (font_size)
|
||||
@@ -0,0 +1,44 @@
|
||||
from PySide2.QtWidgets import QTableWidget
|
||||
from PySide2.QtWidgets import QHeaderView
|
||||
from PySide2.QtWidgets import QTableWidgetItem
|
||||
|
||||
class Table(QTableWidget):
|
||||
def __init__(self):
|
||||
QTableWidget.__init__(self)
|
||||
|
||||
self.session = None
|
||||
|
||||
self.setColumnCount(4)
|
||||
self.setHorizontalHeaderLabels(["Player", "Damage", "DPS", "%"])
|
||||
self.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
|
||||
def fill(self, new_session):
|
||||
if not self._session_changed(new_session):
|
||||
return
|
||||
|
||||
self.session = new_session
|
||||
|
||||
session = sorted(new_session, key=lambda s: float(
|
||||
s.damage), reverse=True)
|
||||
|
||||
self._align_rows(len(session))
|
||||
|
||||
for idx, stats in enumerate(session):
|
||||
self.setItem(idx, 0, QTableWidgetItem(stats.name))
|
||||
self.setItem(idx, 1, QTableWidgetItem(stats.damage))
|
||||
self.setItem(idx, 2, QTableWidgetItem(stats.dps))
|
||||
self.setItem(idx, 3, QTableWidgetItem(stats.precentage))
|
||||
|
||||
def _align_rows(self, new_row_count):
|
||||
row_count = self.rowCount()
|
||||
diff = row_count - new_row_count
|
||||
|
||||
if diff < 0:
|
||||
for i in range(row_count, row_count - diff):
|
||||
self.insertRow(i)
|
||||
else:
|
||||
for i in range(0, diff):
|
||||
self.removeRow(0)
|
||||
|
||||
def _session_changed(self, session):
|
||||
return self.session != session
|
||||
@@ -0,0 +1,17 @@
|
||||
import os
|
||||
import requests
|
||||
|
||||
_version = "0.5.3"
|
||||
|
||||
latest_url = "https://github.com/mazurwiktor/albion-online-stats/releases/latest"
|
||||
|
||||
|
||||
def latest_version():
|
||||
req = requests.get(latest_url)
|
||||
if req.status_code == 200:
|
||||
return os.path.basename(req.url)
|
||||
return None
|
||||
|
||||
|
||||
def current_version():
|
||||
return _version
|
||||
Reference in New Issue
Block a user