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)