Fixed healing and started working on item collection tracking
This commit is contained in:
@@ -105,6 +105,14 @@ class GameStats():
|
|||||||
elif stat_type == VisibilityType.Overall:
|
elif stat_type == VisibilityType.Overall:
|
||||||
return self.history[StatType.Combat].combined(self.zone[StatType.Combat]).players_healing()
|
return self.history[StatType.Combat].combined(self.zone[StatType.Combat]).players_healing()
|
||||||
|
|
||||||
|
def get_total_healing_stats(self, stat_type):
|
||||||
|
if stat_type == VisibilityType.Zone:
|
||||||
|
return self.zone[StatType.Combat].players_total_healing()
|
||||||
|
elif stat_type == VisibilityType.LastFight:
|
||||||
|
return self.last_fight[StatType.Combat].players_total_healing()
|
||||||
|
elif stat_type == VisibilityType.Overall:
|
||||||
|
return self.history[StatType.Combat].combined(self.zone[StatType.Combat]).players_total_healing()
|
||||||
|
|
||||||
def fame_stats(self, stat_type):
|
def fame_stats(self, stat_type):
|
||||||
if stat_type == VisibilityType.Zone:
|
if stat_type == VisibilityType.Zone:
|
||||||
return self.zone[StatType.Fame].stats()
|
return self.zone[StatType.Fame].stats()
|
||||||
@@ -156,6 +164,18 @@ def last_fight_stats(combat_stat_type: str):
|
|||||||
return get_stats(VisibilityType.LastFight, combat_stat_type)
|
return get_stats(VisibilityType.LastFight, combat_stat_type)
|
||||||
|
|
||||||
|
|
||||||
|
def zone_total_healing_stats():
|
||||||
|
return game_stats.get_total_healing_stats(VisibilityType.Zone)
|
||||||
|
|
||||||
|
|
||||||
|
def overall_total_healing_stats():
|
||||||
|
return game_stats.get_total_healing_stats(VisibilityType.Overall)
|
||||||
|
|
||||||
|
|
||||||
|
def last_fight_total_healing_stats():
|
||||||
|
return game_stats.get_total_healing_stats(VisibilityType.LastFight)
|
||||||
|
|
||||||
|
|
||||||
cached_players = () # do not compute values if there is nothing in queue
|
cached_players = () # do not compute values if there is nothing in queue
|
||||||
cached_stat_type = None
|
cached_stat_type = None
|
||||||
cached_combat_stat_type = None
|
cached_combat_stat_type = None
|
||||||
|
|||||||
+11
-1
@@ -101,7 +101,8 @@ class MainWidget(QWidget):
|
|||||||
elapsed,
|
elapsed,
|
||||||
fame_stat.fame,
|
fame_stat.fame,
|
||||||
fame_stat.fame_per_hour,
|
fame_stat.fame_per_hour,
|
||||||
player_list_items
|
player_list_items,
|
||||||
|
self.total_healing_stats()
|
||||||
)
|
)
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
@@ -141,3 +142,12 @@ class MainWidget(QWidget):
|
|||||||
}
|
}
|
||||||
|
|
||||||
return stats[self.top_bar.view_type.get_view_type()][self.view.get_mode()]()
|
return stats[self.top_bar.view_type.get_view_type()][self.view.get_mode()]()
|
||||||
|
|
||||||
|
def total_healing_stats(self):
|
||||||
|
stats = {
|
||||||
|
StatsType.ZONE: engine.zone_total_healing_stats,
|
||||||
|
StatsType.LAST_FIGHT: engine.last_fight_total_healing_stats,
|
||||||
|
StatsType.OVERALL: engine.overall_total_healing_stats,
|
||||||
|
}
|
||||||
|
|
||||||
|
return stats[self.view.get_mode()]()
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ icon_cache = {}
|
|||||||
def get_weapon_icon(weapon):
|
def get_weapon_icon(weapon):
|
||||||
global icon_cache
|
global icon_cache
|
||||||
|
|
||||||
|
if not weapon:
|
||||||
|
return None
|
||||||
|
|
||||||
url = f'https://albiononline2d.ams3.cdn.digitaloceanspaces.com/thumbnails/orig/{weapon}'
|
url = f'https://albiononline2d.ams3.cdn.digitaloceanspaces.com/thumbnails/orig/{weapon}'
|
||||||
|
|
||||||
if weapon in icon_cache:
|
if weapon in icon_cache:
|
||||||
@@ -18,6 +21,8 @@ def get_weapon_icon(weapon):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
r = async_request.get(url)
|
r = async_request.get(url)
|
||||||
|
if r is None or not r.ok:
|
||||||
|
return None
|
||||||
img = Image.open(BytesIO(r.content))
|
img = Image.open(BytesIO(r.content))
|
||||||
|
|
||||||
img_qt = ImageQt.ImageQt(img)
|
img_qt = ImageQt.ImageQt(img)
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ from typing import Callable
|
|||||||
from PySide6.QtWidgets import QHBoxLayout # type: ignore
|
from PySide6.QtWidgets import QHBoxLayout # type: ignore
|
||||||
from PySide6.QtWidgets import QVBoxLayout # type: ignore
|
from PySide6.QtWidgets import QVBoxLayout # type: ignore
|
||||||
from PySide6.QtWidgets import QComboBox # type: ignore
|
from PySide6.QtWidgets import QComboBox # type: ignore
|
||||||
|
from PySide6.QtWidgets import QLabel # type: ignore
|
||||||
from PySide6.QtWidgets import QWidget # type: ignore
|
from PySide6.QtWidgets import QWidget # type: ignore
|
||||||
|
|
||||||
from ....stats.list_item import PlayerListItem
|
from ....stats.list_item import PlayerListItem
|
||||||
|
from ..view_type import ViewType
|
||||||
|
|
||||||
from .list_view import ListItemView
|
from .list_view import ListItemView
|
||||||
from .stats_type import StatsType
|
from .stats_type import StatsType
|
||||||
@@ -63,13 +65,31 @@ class ModeBasedListView(QWidget):
|
|||||||
self.list_view = ListItemView()
|
self.list_view = ListItemView()
|
||||||
self.layout.addWidget(self.list_view)
|
self.layout.addWidget(self.list_view)
|
||||||
|
|
||||||
|
self.total_healing_label = QLabel('Total Healing')
|
||||||
|
self.layout.addWidget(self.total_healing_label)
|
||||||
|
|
||||||
|
self.total_healing_view = ListItemView()
|
||||||
|
self.layout.addWidget(self.total_healing_view)
|
||||||
|
|
||||||
|
self.total_healing_label.hide()
|
||||||
|
self.total_healing_view.hide()
|
||||||
|
|
||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
def update(self, prefix, elapsed, fame, fame_per_hour, players: PlayerListItem):
|
def update(self, prefix, elapsed, fame, fame_per_hour,
|
||||||
|
players: PlayerListItem, total_healing: PlayerListItem):
|
||||||
self.session_bar.player_stats.update(elapsed, fame, fame_per_hour)
|
self.session_bar.player_stats.update(elapsed, fame, fame_per_hour)
|
||||||
self.session_bar.copy_button.update(
|
self.session_bar.copy_button.update(
|
||||||
prefix, self.list_view.get_player_list_items(), self.session_bar.mode.get_mode(), fame)
|
prefix, self.list_view.get_player_list_items(), self.session_bar.mode.get_mode(), fame)
|
||||||
self.list_view.update(players)
|
self.list_view.update(players)
|
||||||
|
if prefix == ViewType.HEALING_DONE and total_healing:
|
||||||
|
self.total_healing_label.show()
|
||||||
|
self.total_healing_view.show()
|
||||||
|
self.total_healing_view.update(total_healing)
|
||||||
|
else:
|
||||||
|
self.total_healing_label.hide()
|
||||||
|
self.total_healing_view.hide()
|
||||||
|
self.total_healing_view.update([])
|
||||||
self.session_bar.update()
|
self.session_bar.update()
|
||||||
|
|
||||||
def get_mode(self) -> str:
|
def get_mode(self) -> str:
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ class Party:
|
|||||||
self.get_visible_players = get_visible_players
|
self.get_visible_players = get_visible_players
|
||||||
|
|
||||||
def combat_state(self) -> int:
|
def combat_state(self) -> int:
|
||||||
return CombatState.OutOfCombat if all(
|
return CombatState.InCombat if any(
|
||||||
player.combat_state == CombatState.InCombat for player in self.get_visible_players()) else CombatState.InCombat
|
player.combat_state == CombatState.InCombat for player in self.get_visible_players()) else CombatState.OutOfCombat
|
||||||
|
|
||||||
def time_in_combat(self) -> float:
|
def time_in_combat(self) -> float:
|
||||||
longest = 0.0
|
longest = 0.0
|
||||||
@@ -50,6 +50,7 @@ class Player(Stats):
|
|||||||
items: dict = field(default_factory=lambda: {'weapon': None})
|
items: dict = field(default_factory=lambda: {'weapon': None})
|
||||||
damage_done: float = 0.0
|
damage_done: float = 0.0
|
||||||
healing_done: float = 0.0
|
healing_done: float = 0.0
|
||||||
|
total_healing_done: float = 0.0
|
||||||
combat_time: CombatTime = field(default_factory=lambda: CombatTime())
|
combat_time: CombatTime = field(default_factory=lambda: CombatTime())
|
||||||
combat_state: int = CombatState.OutOfCombat
|
combat_state: int = CombatState.OutOfCombat
|
||||||
active: bool = False
|
active: bool = False
|
||||||
@@ -61,7 +62,7 @@ class Player(Stats):
|
|||||||
return self.active
|
return self.active
|
||||||
|
|
||||||
def has_stats(self) -> bool:
|
def has_stats(self) -> bool:
|
||||||
return bool(self.damage_done or self.healing_done)
|
return bool(self.damage_done or self.healing_done or self.total_healing_done)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new(self):
|
def new(self):
|
||||||
@@ -75,6 +76,7 @@ class Player(Stats):
|
|||||||
self.name = other.name
|
self.name = other.name
|
||||||
self.damage_done += other.damage_done
|
self.damage_done += other.damage_done
|
||||||
self.healing_done += other.healing_done
|
self.healing_done += other.healing_done
|
||||||
|
self.total_healing_done += other.total_healing_done
|
||||||
self.combat_state = other.combat_state
|
self.combat_state = other.combat_state
|
||||||
self.combat_time.entered_combat = other.combat_time.entered_combat
|
self.combat_time.entered_combat = other.combat_time.entered_combat
|
||||||
self.combat_time.time_in_combat += other.combat_time.time_in_combat
|
self.combat_time.time_in_combat += other.combat_time.time_in_combat
|
||||||
@@ -92,11 +94,13 @@ class Player(Stats):
|
|||||||
self.activate()
|
self.activate()
|
||||||
|
|
||||||
def register_healing_done(self, value):
|
def register_healing_done(self, value):
|
||||||
|
self.total_healing_done += value
|
||||||
|
self.activate()
|
||||||
|
|
||||||
if self.party.combat_state() == CombatState.OutOfCombat:
|
if self.party.combat_state() == CombatState.OutOfCombat:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.healing_done += value
|
self.healing_done += value
|
||||||
self.activate()
|
|
||||||
|
|
||||||
def enter_combat(self):
|
def enter_combat(self):
|
||||||
self.combat_time.entered_combat = time_utils.now()
|
self.combat_time.entered_combat = time_utils.now()
|
||||||
@@ -116,6 +120,11 @@ class Player(Stats):
|
|||||||
return StandalonePlayerListItem(
|
return StandalonePlayerListItem(
|
||||||
self.name, self.items, self.healing_done, self.hps, self.combat_state)
|
self.name, self.items, self.healing_done, self.hps, self.combat_state)
|
||||||
|
|
||||||
|
def into_total_healing_list_item(self) -> StandalonePlayerListItem:
|
||||||
|
return StandalonePlayerListItem(
|
||||||
|
self.name, self.items, self.total_healing_done, self.total_hps,
|
||||||
|
self.combat_state)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def time_in_combat(self):
|
def time_in_combat(self):
|
||||||
if self.combat_state == CombatState.InCombat:
|
if self.combat_state == CombatState.InCombat:
|
||||||
@@ -140,6 +149,16 @@ class Player(Stats):
|
|||||||
|
|
||||||
return time_utils.as_milliseconds(self.healing_done / time_in_combat)
|
return time_utils.as_milliseconds(self.healing_done / time_in_combat)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def total_hps(self):
|
||||||
|
time_in_combat = self.party.time_in_combat()
|
||||||
|
|
||||||
|
if time_in_combat == 0.0:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
return time_utils.as_milliseconds(
|
||||||
|
self.total_healing_done / time_in_combat)
|
||||||
|
|
||||||
|
|
||||||
class CombatStats(CombatEventReceiver, Stats):
|
class CombatStats(CombatEventReceiver, Stats):
|
||||||
def __init__(self, visibility, players=None):
|
def __init__(self, visibility, players=None):
|
||||||
@@ -187,7 +206,13 @@ class CombatStats(CombatEventReceiver, Stats):
|
|||||||
|
|
||||||
def players_healing(self) -> List[PlayerListItem]:
|
def players_healing(self) -> List[PlayerListItem]:
|
||||||
return to_player_list_items([player.into_healing_list_item()
|
return to_player_list_items([player.into_healing_list_item()
|
||||||
|
for player in self.visible_players()
|
||||||
|
])
|
||||||
|
|
||||||
|
def players_total_healing(self) -> List[PlayerListItem]:
|
||||||
|
return to_player_list_items([player.into_total_healing_list_item()
|
||||||
for player in self.visible_players()
|
for player in self.visible_players()
|
||||||
|
if player.total_healing_done
|
||||||
])
|
])
|
||||||
|
|
||||||
def party_combat_state(self):
|
def party_combat_state(self):
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ import threading
|
|||||||
import queue
|
import queue
|
||||||
import requests
|
import requests
|
||||||
import collections
|
import collections
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
Item = collections.namedtuple('Item', 'key value')
|
Item = collections.namedtuple('Item', 'key value')
|
||||||
@@ -26,7 +30,11 @@ _update_thread.start()
|
|||||||
|
|
||||||
|
|
||||||
def _async_req(url):
|
def _async_req(url):
|
||||||
req = requests.get(url)
|
try:
|
||||||
|
req = requests.get(url, timeout=5)
|
||||||
|
except requests.RequestException as e:
|
||||||
|
logger.debug("async request failed for %s: %s", url, e)
|
||||||
|
req = None
|
||||||
|
|
||||||
_queue.put(Item(key=url, value=req))
|
_queue.put(Item(key=url, value=req))
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
from src.gui.modules.views.list_view import icon
|
||||||
|
from src.utils import async_request
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_weapon_icon_ignores_missing_weapon(monkeypatch):
|
||||||
|
called = []
|
||||||
|
monkeypatch.setattr(icon.async_request, 'get', lambda url: called.append(url))
|
||||||
|
|
||||||
|
assert icon.get_weapon_icon(None) is None
|
||||||
|
assert called == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_async_request_catches_request_errors(monkeypatch):
|
||||||
|
queued = []
|
||||||
|
|
||||||
|
def raise_connection_error(_url, timeout=None):
|
||||||
|
raise requests.ConnectionError('dns failed')
|
||||||
|
|
||||||
|
class FakeQueue:
|
||||||
|
def put(self, item):
|
||||||
|
queued.append(item)
|
||||||
|
|
||||||
|
monkeypatch.setattr(async_request.requests, 'get', raise_connection_error)
|
||||||
|
monkeypatch.setattr(async_request, '_queue', FakeQueue())
|
||||||
|
|
||||||
|
async_request._async_req('https://example.invalid/icon')
|
||||||
|
|
||||||
|
assert queued[0].key == 'https://example.invalid/icon'
|
||||||
|
assert queued[0].value is None
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
from src.stats.combat_stats import CombatStats
|
||||||
|
|
||||||
|
|
||||||
|
class VisibleAll:
|
||||||
|
def test(self, _name):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def test_self_healing_counts_while_in_combat():
|
||||||
|
stats = CombatStats(VisibleAll())
|
||||||
|
stats.on_player_appeared(0, 'Healer')
|
||||||
|
stats.on_enter_combat(0)
|
||||||
|
|
||||||
|
stats.on_health_received(0, 0, 100.0)
|
||||||
|
|
||||||
|
combat_healing = stats.players_healing()
|
||||||
|
total_healing = stats.players_total_healing()
|
||||||
|
|
||||||
|
assert combat_healing[0].name == 'Healer'
|
||||||
|
assert combat_healing[0].value == 100.0
|
||||||
|
assert total_healing[0].value == 100.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_total_healing_includes_post_combat_healing():
|
||||||
|
stats = CombatStats(VisibleAll())
|
||||||
|
stats.on_player_appeared(0, 'Healer')
|
||||||
|
stats.on_enter_combat(0)
|
||||||
|
stats.on_health_received(0, 0, 100.0)
|
||||||
|
stats.on_leave_combat(0)
|
||||||
|
|
||||||
|
stats.on_health_received(0, 0, 50.0)
|
||||||
|
|
||||||
|
combat_healing = stats.players_healing()
|
||||||
|
total_healing = stats.players_total_healing()
|
||||||
|
|
||||||
|
assert combat_healing[0].value == 100.0
|
||||||
|
assert total_healing[0].value == 150.0
|
||||||
Reference in New Issue
Block a user