Browse Source

fix(stats): calculate success rate from completed and failed prints only

Previously divided successful prints by total_prints which includes
cancelled/stopped prints, causing an incorrect percentage.
AneoPsy 2 months ago
parent
commit
b2603c8c2d
1 changed files with 3 additions and 2 deletions
  1. 3 2
      frontend/src/pages/StatsPage.tsx

+ 3 - 2
frontend/src/pages/StatsPage.tsx

@@ -123,8 +123,9 @@ function SuccessRateWidget({
   size?: 1 | 2 | 4;
   size?: 1 | 2 | 4;
   t: (key: string) => string;
   t: (key: string) => string;
 }) {
 }) {
-  const successRate = stats?.total_prints
-    ? Math.round((stats.successful_prints / stats.total_prints) * 100)
+  const completedAndFailed = (stats?.successful_prints || 0) + (stats?.failed_prints || 0);
+  const successRate = completedAndFailed
+    ? Math.round((stats!.successful_prints / completedAndFailed) * 100)
     : 0;
     : 0;
 
 
   // Scale gauge size based on widget size
   // Scale gauge size based on widget size