Browse Source

Minor project page bugfixes

maziggy 4 months ago
parent
commit
1e08c3d5a9

+ 21 - 9
backend/app/api/routes/projects.py

@@ -49,18 +49,19 @@ async def compute_project_stats(db: AsyncSession, project_id: int, target_count:
     )
     )
     total_items = total_items_result.scalar() or 0
     total_items = total_items_result.scalar() or 0
 
 
-    # Sum completed items (using quantity field)
+    # Count completed archives (number of print jobs) - includes "archived" as successful
     completed_result = await db.execute(
     completed_result = await db.execute(
-        select(func.coalesce(func.sum(PrintArchive.quantity), 0)).where(
-            PrintArchive.project_id == project_id, PrintArchive.status == "completed"
+        select(func.count(PrintArchive.id)).where(
+            PrintArchive.project_id == project_id, PrintArchive.status.in_(["completed", "archived"])
         )
         )
     )
     )
     completed_prints = completed_result.scalar() or 0
     completed_prints = completed_result.scalar() or 0
 
 
-    # Sum failed items (using quantity field)
+    # Count failed archives (number of print jobs) - includes all failure states
     failed_result = await db.execute(
     failed_result = await db.execute(
-        select(func.coalesce(func.sum(PrintArchive.quantity), 0)).where(
-            PrintArchive.project_id == project_id, PrintArchive.status == "failed"
+        select(func.count(PrintArchive.id)).where(
+            PrintArchive.project_id == project_id,
+            PrintArchive.status.in_(["failed", "aborted", "cancelled", "stopped"]),
         )
         )
     )
     )
     failed_prints = failed_result.scalar() or 0
     failed_prints = failed_result.scalar() or 0
@@ -169,15 +170,24 @@ async def list_projects(
         )
         )
         queue_count = queue_count_result.scalar() or 0
         queue_count = queue_count_result.scalar() or 0
 
 
-        # Get completed count for progress (sum of quantities)
+        # Count completed archives - includes "archived" as successful
         completed_result = await db.execute(
         completed_result = await db.execute(
-            select(func.coalesce(func.sum(PrintArchive.quantity), 0)).where(
+            select(func.count(PrintArchive.id)).where(
                 PrintArchive.project_id == project.id,
                 PrintArchive.project_id == project.id,
-                PrintArchive.status == "completed",
+                PrintArchive.status.in_(["completed", "archived"]),
             )
             )
         )
         )
         completed_count = int(completed_result.scalar() or 0)
         completed_count = int(completed_result.scalar() or 0)
 
 
+        # Count failed archives - includes all failure states
+        failed_result = await db.execute(
+            select(func.count(PrintArchive.id)).where(
+                PrintArchive.project_id == project.id,
+                PrintArchive.status.in_(["failed", "aborted", "cancelled", "stopped"]),
+            )
+        )
+        failed_count = int(failed_result.scalar() or 0)
+
         progress_percent = None
         progress_percent = None
         if project.target_count and project.target_count > 0:
         if project.target_count and project.target_count > 0:
             progress_percent = round((completed_count / project.target_count) * 100, 1)
             progress_percent = round((completed_count / project.target_count) * 100, 1)
@@ -213,6 +223,8 @@ async def list_projects(
                 created_at=project.created_at,
                 created_at=project.created_at,
                 archive_count=archive_count,
                 archive_count=archive_count,
                 total_items=total_items,
                 total_items=total_items,
+                completed_count=completed_count,
+                failed_count=failed_count,
                 queue_count=queue_count,
                 queue_count=queue_count,
                 progress_percent=progress_percent,
                 progress_percent=progress_percent,
                 archives=archive_previews,
                 archives=archive_previews,

+ 3 - 1
backend/app/schemas/project.py

@@ -117,7 +117,9 @@ class ProjectListResponse(BaseModel):
     created_at: datetime
     created_at: datetime
     # Quick stats
     # Quick stats
     archive_count: int = 0  # Number of print jobs
     archive_count: int = 0  # Number of print jobs
-    total_items: int = 0  # Sum of quantities (total items printed)
+    total_items: int = 0  # Sum of quantities (total items printed, including failed)
+    completed_count: int = 0  # Sum of quantities for completed prints only
+    failed_count: int = 0  # Sum of quantities for failed prints
     queue_count: int = 0
     queue_count: int = 0
     progress_percent: float | None = None
     progress_percent: float | None = None
     # Preview of archives (up to 5)
     # Preview of archives (up to 5)

File diff suppressed because it is too large
+ 0 - 0
static/assets/index-D7518JU5.js


+ 1 - 1
static/index.html

@@ -23,7 +23,7 @@
 
 
     <!-- Splash screens for iOS -->
     <!-- Splash screens for iOS -->
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
-    <script type="module" crossorigin src="/assets/index-WNO7X-o0.js"></script>
+    <script type="module" crossorigin src="/assets/index-D7518JU5.js"></script>
     <link rel="stylesheet" crossorigin href="/assets/index-DAZKHkJ3.css">
     <link rel="stylesheet" crossorigin href="/assets/index-DAZKHkJ3.css">
   </head>
   </head>
   <body>
   <body>

Some files were not shown because too many files changed in this diff