From 1fd9b8c1b96aed7c4e87147c78045efb08ebe1e3 Mon Sep 17 00:00:00 2001 From: dazedanon Date: Mon, 27 Oct 2025 23:29:13 -0500 Subject: [PATCH] Fix total counter double counting last file cost --- gui/translation_tab.py | 52 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/gui/translation_tab.py b/gui/translation_tab.py index ef14a04..f6cbba7 100644 --- a/gui/translation_tab.py +++ b/gui/translation_tab.py @@ -528,6 +528,8 @@ class TranslationTab(QWidget): self.totals_output_tokens = 0 self.totals_cost = 0.0 self.totals_time = 0.0 + # Track which filenames' totals have been applied (prevents double-counting) + self._applied_file_totals = set() # Totals widget reference self.totals_widget = None @@ -1536,6 +1538,11 @@ class TranslationTab(QWidget): self.totals_output_tokens = 0 self.totals_cost = 0.0 self.totals_time = 0.0 + # Reset seen filenames for this run so totals can be applied anew + try: + self._applied_file_totals.clear() + except Exception: + self._applied_file_totals = set() if hasattr(self, 'totals_tokens_label'): self.totals_tokens_label.setText("Tokens: 0 in / 0 out") if hasattr(self, 'totals_cost_label'): @@ -1627,31 +1634,21 @@ class TranslationTab(QWidget): self.translation_worker.start() def append_log(self, message): - """Append a message to the log - now just for internal tracking.""" - # IMPORTANT: Do NOT forward worker messages directly to the - # LogViewer when tailing a file. The LogViewer is intended to - # show only the contents of the log file (e.g. log/translationHistory.txt). - # Forwarding worker messages here caused non-file messages to appear - # in the log window. Modules write to the log file themselves, so - # we no longer push worker messages into the UI. - # Parse worker/module output lines for per-file result details. - # Example line: "Enemies.json: [Input: 8865][Output: 663][Cost: $0.0230][20.1s] ✓" try: - pattern = r'^(?P[^:]+):.*?\[Input:\s*(?P\d+)\].*?\[Output:\s*(?P\d+)\].*?\[Cost:\s*\$(?P[\d\.]+)\].*?\[(?P