@@ -35,7 +35,6 @@ class SensorReadingSchema(BaseModel):
3535 latitude : float | None = None
3636 longitude : float | None = None
3737 original_timezone : str | None = None
38- synced : bool | None = False
3938 # Enhanced identity fields
4039 serial_number : str | None = None
4140 manufacture_date : str | None = None
@@ -130,7 +129,6 @@ def _init_db(self):
130129 latitude REAL,
131130 longitude REAL,
132131 original_timezone TEXT,
133- synced INTEGER DEFAULT 0,
134132 serial_number TEXT,
135133 manufacture_date TEXT,
136134 deployment_type TEXT,
@@ -145,7 +143,6 @@ def _init_db(self):
145143 # Create indices
146144 cursor .execute ("CREATE INDEX IF NOT EXISTS idx_timestamp ON sensor_readings(timestamp)" )
147145 cursor .execute ("CREATE INDEX IF NOT EXISTS idx_sensor_id ON sensor_readings(sensor_id)" )
148- cursor .execute ("CREATE INDEX IF NOT EXISTS idx_synced ON sensor_readings(synced)" )
149146
150147 self .conn .commit ()
151148 cursor .close ()
@@ -196,7 +193,6 @@ def commit_batch(self):
196193 reading .latitude ,
197194 reading .longitude ,
198195 reading .original_timezone ,
199- 1 if reading .synced else 0 ,
200196 reading .serial_number ,
201197 reading .manufacture_date ,
202198 reading .deployment_type ,
@@ -215,11 +211,11 @@ def commit_batch(self):
215211 timestamp, sensor_id, temperature, humidity, pressure,
216212 vibration, voltage, status_code, anomaly_flag, anomaly_type,
217213 firmware_version, model, manufacturer, location,
218- latitude, longitude, original_timezone, synced,
214+ latitude, longitude, original_timezone,
219215 serial_number, manufacture_date, deployment_type,
220216 installation_date, height_meters, orientation_degrees,
221217 instance_id, sensor_type
222- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
218+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
223219 """ ,
224220 batch_data ,
225221 )
@@ -285,58 +281,17 @@ def get_readings(self, limit: int = 100, offset: int = 0) -> list[dict]:
285281 cursor .close ()
286282 return readings
287283
288- def get_unsynced_readings (self , limit : int = 100 ) -> list [dict ]:
289- """Get unsynced readings."""
290- assert self .conn is not None
291- cursor = self .conn .cursor ()
292- cursor .execute (
293- """
294- SELECT * FROM sensor_readings
295- WHERE synced = 0
296- ORDER BY id ASC
297- LIMIT ?
298- """ ,
299- (limit ,),
300- )
301-
302- readings = []
303- for row in cursor .fetchall ():
304- readings .append (dict (row ))
305-
306- cursor .close ()
307- return readings
308-
309- def mark_readings_as_synced (self , reading_ids : list [int ]):
310- """Mark readings as synced."""
311- if not reading_ids :
312- return
313-
314- assert self .conn is not None
315- cursor = self .conn .cursor ()
316- placeholders = "," .join ("?" * len (reading_ids ))
317- cursor .execute (
318- f"UPDATE sensor_readings SET synced = 1 WHERE id IN ({ placeholders } )" , reading_ids
319- )
320- assert self .conn is not None
321- self .conn .commit ()
322- cursor .close ()
323-
324284 def get_reading_stats (self ) -> dict :
325285 """Get basic statistics."""
326286 assert self .conn is not None
327287 cursor = self .conn .cursor ()
328288 cursor .execute ("SELECT COUNT(*) FROM sensor_readings" )
329289 total = cursor .fetchone ()[0 ]
330290
331- cursor .execute ("SELECT COUNT(*) FROM sensor_readings WHERE synced = 0" )
332- unsynced = cursor .fetchone ()[0 ]
333-
334291 cursor .close ()
335292
336293 return {
337294 "total_readings" : total ,
338- "unsynced_readings" : unsynced ,
339- "synced_readings" : total - unsynced ,
340295 }
341296
342297 def get_database_stats (self ) -> dict [str , Any ]:
0 commit comments