Skip to content
This repository was archived by the owner on Jun 13, 2026. It is now read-only.

Commit 45843de

Browse files
committed
fix: add missing get_database_stats method and correct column name
- Add get_database_stats() method required by main.py health check - Fix column name from 'timezone' to 'original_timezone' in INSERT - Both issues prevented the sensor from writing data Now local testing works correctly with: 1. uv run main.py (writer) 2. uv run scripts/testing/test_readers.py (readers)
1 parent d56fa12 commit 45843de

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ services:
66
environment:
77
- CONFIG_FILE=/config/config.yaml
88
- IDENTITY_FILE=/config/node-identity.json
9-
# IMPORTANT: Docker Desktop on macOS/Windows has issues with SQLite WAL mode
10-
# Uncomment the line below to use DELETE mode for proper data persistence:
11-
# - SENSOR_WAL=false # REQUIRED for macOS/Windows Docker Desktop!
129
volumes:
1310
- ./config:/config
1411
- ./data:/app/data # Mount local data directory for database persistence

src/database.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def commit_batch(self):
198198
timestamp, sensor_id, temperature, humidity, pressure,
199199
voltage, vibration, status_code, anomaly_flag, anomaly_type,
200200
firmware_version, model, manufacturer, serial_number,
201-
location, latitude, longitude, timezone,
201+
location, latitude, longitude, original_timezone,
202202
deployment_type, installation_date, height_meters
203203
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
204204
""",
@@ -282,7 +282,26 @@ def __exit__(self, exc_type, exc_val, exc_tb):
282282
"""Context manager exit."""
283283
self.close()
284284

285-
# Compatibility method
285+
# Compatibility methods
286286
def stop_background_commit_thread(self):
287287
"""No-op for compatibility."""
288288
pass
289+
290+
def get_database_stats(self) -> dict:
291+
"""Get database statistics."""
292+
try:
293+
cursor = self.conn.cursor()
294+
cursor.execute("SELECT COUNT(*) FROM sensor_readings")
295+
total = cursor.fetchone()[0]
296+
297+
cursor.execute("SELECT COUNT(*) FROM sensor_readings WHERE anomaly_flag = 1")
298+
anomalies = cursor.fetchone()[0]
299+
300+
return {
301+
"total_readings": total,
302+
"anomaly_count": anomalies,
303+
"database_size": 0, # Not calculated for simplicity
304+
}
305+
except Exception as e:
306+
self.logger.error(f"Failed to get database stats: {e}")
307+
return {"total_readings": 0, "anomaly_count": 0, "database_size": 0}

0 commit comments

Comments
 (0)