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
This commit is contained in:
parent
6d99d357ab
commit
e4fd75e2a7
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue