From e4fd75e2a7d30fdefe0829166237c67f0ad58a42 Mon Sep 17 00:00:00 2001 From: LemonNexus Date: Tue, 10 Feb 2026 14:52:32 +0000 Subject: [PATCH] fix: save HUD costs to database on session end - Save weapon_cost_total, armor_cost_total, healing_cost_total to decay_events - This ensures core profit calculation matches HUD display - Insert decay events before calling end_session - Log the saved costs for verification --- ui/main_window.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ui/main_window.py b/ui/main_window.py index abff918..f674fb4 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -1378,6 +1378,47 @@ class MainWindow(QMainWindow): # Stop LogWatcher self._stop_log_watcher() + # Save HUD costs to database before ending session + if self._current_db_session_id and self.hud: + from decimal import Decimal + from datetime import datetime + + # Save weapon decay + if self.hud._stats.weapon_cost_total > 0: + self.db.execute( + """INSERT INTO decay_events + (session_id, item_name, decay_amount_ped, timestamp) + VALUES (?, ?, ?, ?)""", + (self._current_db_session_id, 'Weapon', + float(self.hud._stats.weapon_cost_total), datetime.now()) + ) + + # Save armor decay + if self.hud._stats.armor_cost_total > 0: + self.db.execute( + """INSERT INTO decay_events + (session_id, item_name, decay_amount_ped, timestamp) + VALUES (?, ?, ?, ?)""", + (self._current_db_session_id, 'Armor', + float(self.hud._stats.armor_cost_total), datetime.now()) + ) + + # Save healing decay + if self.hud._stats.healing_cost_total > 0: + self.db.execute( + """INSERT INTO decay_events + (session_id, item_name, decay_amount_ped, timestamp) + VALUES (?, ?, ?, ?)""", + (self._current_db_session_id, 'Healing', + float(self.hud._stats.healing_cost_total), datetime.now()) + ) + + self.db.commit() + self.log_info("Session", + f"Saved costs to DB: Weapon={self.hud._stats.weapon_cost_total:.2f}, " + f"Armor={self.hud._stats.armor_cost_total:.2f}, " + f"Healing={self.hud._stats.healing_cost_total:.2f}") + # End session in database if self._current_db_session_id: self.project_manager.end_session(self._current_db_session_id)