1
0
Fork 0
mirror of https://github.com/maziggy/bambuddy.git synced 2026-05-09 08:25:54 +02:00

[PR #277] [MERGED] Feature/accurate usage tracking #989

Closed
opened 2026-05-07 00:15:20 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/maziggy/bambuddy/pull/277
Author: @bambuman
Created: 2/5/2026
Status: Merged
Merged: 2/6/2026
Merged by: @maziggy

Base: 0.1.8bHead: feature/accurate-usage-tracking


📝 Commits (8)

  • 6e82cc6 Add per-filament Spoolman usage tracking with G-code parsing
  • 5703cea fix linting isssues
  • 2c086dd ruff format changes
  • 33b9360 pre-commit changes
  • 996f788 Merge pull request #279 from maziggy/0.1.8b
  • 0a39b12 Merge branch 'maziggy:main' into feature/accurate-usage-tracking
  • ce4683a Use defusedxml in test files for Bandit compliance
  • 0dcb154 Merge branch '0.1.8b' into feature/accurate-usage-tracking

📊 Changes

12 files changed (+1316 additions, -73 deletions)

View changed files

📝 backend/app/api/routes/settings.py (+10 -0)
📝 backend/app/api/routes/spoolman.py (+19 -14)
📝 backend/app/core/database.py (+21 -0)
📝 backend/app/main.py (+463 -52)
backend/app/models/active_print_spoolman.py (+42 -0)
📝 backend/app/schemas/settings.py (+10 -0)
📝 backend/app/services/spoolman.py (+4 -2)
backend/app/utils/threemf_tools.py (+307 -0)
📝 backend/tests/integration/test_spoolman_api.py (+206 -0)
backend/tests/unit/services/test_spoolman_service.py (+174 -0)
📝 frontend/src/api/client.ts (+3 -3)
📝 frontend/src/components/SpoolmanSettings.tsx (+57 -2)

📄 Description

Description

Add per-filament Spoolman usage tracking with G-code parsing.

Implements accurate per-filament usage tracking for Spoolman integration, similar to OpenSpoolman v0.3.0. This replaces the previous single-spool reporting with multi-material aware tracking.

Features:

  • Parse G-code from 3MF files at print start to build per-layer, per-filament cumulative extrusion maps
  • Store tracking data in new active_print_spoolman database table (survives server restarts for long prints)
  • Report accurate partial usage when prints fail/cancel based on actual layer progress and G-code data
  • Add "Disable AMS Weight Sync" setting to prevent AMS percentage-based weight estimates from overwriting Spoolman's granular tracking
  • Add "Report Partial Usage for Failed Prints" toggle (only shown when weight sync is disabled)
  • Use Spoolman's filament density instead of defaults for mm-to-grams conversion
  • Prefer tray_uuid over tag_uid for spool identification

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test addition or update

Changes Made

  • Added G-code parsing utilities (backend/app/utils/threemf_tools.py) to extract per-layer, per-filament extrusion data from 3MF files
  • Created ActivePrintSpoolman database model to persist tracking data across server restarts
  • Added database migration for active_print_spoolman table with layer_usage and filament_properties columns
  • Implemented _store_spoolman_print_data() to capture AMS tray state and G-code data at print start
  • Rewrote _report_spoolman_usage() to report per-filament usage to correct spools based on slot-to-tray mapping
  • Added _report_partial_spoolman_usage() to calculate and report partial usage for failed/cancelled prints using G-code layer data
  • Added "Disable AMS Weight Sync" toggle in Spoolman settings - prevents AMS percentage estimates from overwriting Spoolman's usage-based calculations
  • Added "Report Partial Usage for Failed Prints" toggle (conditionally shown when weight sync is disabled)
  • Updated sync_ams_tray() to support disable_weight_sync parameter
  • Fixed tray_uuid preference over tag_uid for spool identification
  • Added unit tests for weight sync behavior (test_spoolman_service.py)
  • Added integration tests for new settings (test_spoolman_api.py)
  • Updated wiki documentation with new settings and AMS estimation accuracy info

Screenshots

{9B8E68ED-56B0-4187-A0CF-A177BD575974}

Testing

  • I have tested this on my local machine
  • I have tested with my printer model: P1S with AMS

Testing performed:

  • Single-material prints: verified usage goes to correct spool
  • Multi-material prints: verified each spool receives only its portion
  • Print cancellation: verified partial usage is reported based on layer progress
  • Server restart during print: verified tracking data survives in database
  • Toggled "Disable AMS Weight Sync" on/off: verified weight sync behavior changes
  • Verified ruff linting passes

Checklist

  • My code follows the project's coding style
  • I have commented my code where necessary
  • I have updated the documentation (if needed)
  • My changes generate no new warnings
  • I have tested my changes thoroughly

Additional Notes

Why "Disable AMS Weight Sync"?
The AMS estimates filament remaining by tracking spool rotation speed, NFC tag data, and filament extrusion speed. This estimation can jump up or down by several percent between readings and isn't very accurate. By disabling weight sync, users can rely on Spoolman's more precise usage-based calculations instead.

Partial Usage Reporting:
When a print fails or is cancelled, Bambuddy now calculates how much filament was actually used based on G-code layer data rather than linear interpolation. This is especially important for multi-material prints where different filaments are used on different layers.

Database Persistence:
Tracking data is stored in SQLite rather than memory to survive server restarts. This is important since prints can take many hours or even days.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/maziggy/bambuddy/pull/277 **Author:** [@bambuman](https://github.com/bambuman) **Created:** 2/5/2026 **Status:** ✅ Merged **Merged:** 2/6/2026 **Merged by:** [@maziggy](https://github.com/maziggy) **Base:** `0.1.8b` ← **Head:** `feature/accurate-usage-tracking` --- ### 📝 Commits (8) - [`6e82cc6`](https://github.com/maziggy/bambuddy/commit/6e82cc611e79442a43e11b8e9612eea0301c47f0) Add per-filament Spoolman usage tracking with G-code parsing - [`5703cea`](https://github.com/maziggy/bambuddy/commit/5703cea3f2902d312ab4f133d42af457c58dac30) fix linting isssues - [`2c086dd`](https://github.com/maziggy/bambuddy/commit/2c086dd91ada7511357bcd514c5c232aee5f9355) ruff format changes - [`33b9360`](https://github.com/maziggy/bambuddy/commit/33b9360e7a5bb56d9516a287a4fb72358b1e0e32) pre-commit changes - [`996f788`](https://github.com/maziggy/bambuddy/commit/996f78870f098b410f6ca56ab32067b825dc92c8) Merge pull request #279 from maziggy/0.1.8b - [`0a39b12`](https://github.com/maziggy/bambuddy/commit/0a39b120645c99c5b2d0f6e005ded315b8fd69fb) Merge branch 'maziggy:main' into feature/accurate-usage-tracking - [`ce4683a`](https://github.com/maziggy/bambuddy/commit/ce4683ad3f7ad4fbc964d176f8a1e0ceb8f67729) Use defusedxml in test files for Bandit compliance - [`0dcb154`](https://github.com/maziggy/bambuddy/commit/0dcb154ae318fb9074b3da7ec1d7c418bb0d2d92) Merge branch '0.1.8b' into feature/accurate-usage-tracking ### 📊 Changes **12 files changed** (+1316 additions, -73 deletions) <details> <summary>View changed files</summary> 📝 `backend/app/api/routes/settings.py` (+10 -0) 📝 `backend/app/api/routes/spoolman.py` (+19 -14) 📝 `backend/app/core/database.py` (+21 -0) 📝 `backend/app/main.py` (+463 -52) ➕ `backend/app/models/active_print_spoolman.py` (+42 -0) 📝 `backend/app/schemas/settings.py` (+10 -0) 📝 `backend/app/services/spoolman.py` (+4 -2) ➕ `backend/app/utils/threemf_tools.py` (+307 -0) 📝 `backend/tests/integration/test_spoolman_api.py` (+206 -0) ➕ `backend/tests/unit/services/test_spoolman_service.py` (+174 -0) 📝 `frontend/src/api/client.ts` (+3 -3) 📝 `frontend/src/components/SpoolmanSettings.tsx` (+57 -2) </details> ### 📄 Description ## Description Add per-filament Spoolman usage tracking with G-code parsing. Implements accurate per-filament usage tracking for Spoolman integration, similar to OpenSpoolman v0.3.0. This replaces the previous single-spool reporting with multi-material aware tracking. **Features:** - Parse G-code from 3MF files at print start to build per-layer, per-filament cumulative extrusion maps - Store tracking data in new `active_print_spoolman` database table (survives server restarts for long prints) - Report accurate partial usage when prints fail/cancel based on actual layer progress and G-code data - Add "Disable AMS Weight Sync" setting to prevent AMS percentage-based weight estimates from overwriting Spoolman's granular tracking - Add "Report Partial Usage for Failed Prints" toggle (only shown when weight sync is disabled) - Use Spoolman's filament density instead of defaults for mm-to-grams conversion - Prefer tray_uuid over tag_uid for spool identification ## Related Issue ## Type of Change - [ ] Bug fix (non-breaking change that fixes an issue) - [x] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [x] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [x] Test addition or update ## Changes Made - Added G-code parsing utilities (`backend/app/utils/threemf_tools.py`) to extract per-layer, per-filament extrusion data from 3MF files - Created `ActivePrintSpoolman` database model to persist tracking data across server restarts - Added database migration for `active_print_spoolman` table with `layer_usage` and `filament_properties` columns - Implemented `_store_spoolman_print_data()` to capture AMS tray state and G-code data at print start - Rewrote `_report_spoolman_usage()` to report per-filament usage to correct spools based on slot-to-tray mapping - Added `_report_partial_spoolman_usage()` to calculate and report partial usage for failed/cancelled prints using G-code layer data - Added "Disable AMS Weight Sync" toggle in Spoolman settings - prevents AMS percentage estimates from overwriting Spoolman's usage-based calculations - Added "Report Partial Usage for Failed Prints" toggle (conditionally shown when weight sync is disabled) - Updated `sync_ams_tray()` to support `disable_weight_sync` parameter - Fixed tray_uuid preference over tag_uid for spool identification - Added unit tests for weight sync behavior (`test_spoolman_service.py`) - Added integration tests for new settings (`test_spoolman_api.py`) - Updated wiki documentation with new settings and AMS estimation accuracy info ## Screenshots <img width="1712" height="1260" alt="{9B8E68ED-56B0-4187-A0CF-A177BD575974}" src="https://github.com/user-attachments/assets/07818aa2-5dbe-4bee-b782-455c9e9f73a6" /> ## Testing - [x] I have tested this on my local machine - [x] I have tested with my printer model: P1S with AMS **Testing performed:** - Single-material prints: verified usage goes to correct spool - Multi-material prints: verified each spool receives only its portion - Print cancellation: verified partial usage is reported based on layer progress - Server restart during print: verified tracking data survives in database - Toggled "Disable AMS Weight Sync" on/off: verified weight sync behavior changes - Verified ruff linting passes ## Checklist - [x] My code follows the project's coding style - [x] I have commented my code where necessary - [x] I have updated the documentation (if needed) - [x] My changes generate no new warnings - [x] I have tested my changes thoroughly ## Additional Notes **Why "Disable AMS Weight Sync"?** The AMS estimates filament remaining by tracking spool rotation speed, NFC tag data, and filament extrusion speed. This estimation can jump up or down by several percent between readings and isn't very accurate. By disabling weight sync, users can rely on Spoolman's more precise usage-based calculations instead. **Partial Usage Reporting:** When a print fails or is cancelled, Bambuddy now calculates how much filament was actually used based on G-code layer data rather than linear interpolation. This is especially important for multi-material prints where different filaments are used on different layers. **Database Persistence:** Tracking data is stored in SQLite rather than memory to survive server restarts. This is important since prints can take many hours or even days. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-07 00:15:20 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/bambuddy-maziggy-1#989
No description provided.