From 19ac5105c2dc7247323c7cb2d8cc078b7f8f78e1 Mon Sep 17 00:00:00 2001 From: David Allonby Date: Thu, 25 Dec 2025 11:55:39 +0000 Subject: [PATCH] Fix sleep analyzer loading only 1% of piezo data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CBOR file reading loop was exiting early when encountering records with empty data fields. This happened because: 1. Some RAW files contain records with `data: b''` (empty byte string) 2. When `cbor2.loads(b'')` is called, it raises `CBORDecodeEOF` 3. `CBORDecodeEOF` inherits from `EOFError` 4. The `except EOFError: break` handler catches this, exiting the loop This caused the sleep analyzer to load only ~250 records instead of ~46,000 per night, resulting in incomplete sleep detection. The fix simply skips records with empty data before attempting to decode. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- biometrics/load_raw_files.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/biometrics/load_raw_files.py b/biometrics/load_raw_files.py index cfa23e58..74fa1291 100644 --- a/biometrics/load_raw_files.py +++ b/biometrics/load_raw_files.py @@ -77,6 +77,9 @@ def _decode_cbor_file(file_path: str, data: dict, start_time, end_time, side: Si # Decode the next CBOR object row = cbor2.load(raw_data) + # Skip records with empty data (malformed records) + if not row.get('data'): + continue decoded_data = cbor2.loads(row['data']) if not decoded_data['type'] in load_raw_types: continue