|
@@ -0,0 +1,59 @@
|
|
|
|
|
+from redis_handler import RedisHandler
|
|
|
|
|
+from db_handler import DatabaseHandler
|
|
|
|
|
+import uuid
|
|
|
|
|
+
|
|
|
|
|
+class Cell:
|
|
|
|
|
+ def __init__(self, cell_id=None):
|
|
|
|
|
+ self.cell_id = cell_id or str(uuid.uuid4())
|
|
|
|
|
+ self.voltage = 0
|
|
|
|
|
+ self.current = 0
|
|
|
|
|
+ self.temperature = 0
|
|
|
|
|
+ self._redis = RedisHandler()
|
|
|
|
|
+ self._db = DatabaseHandler()
|
|
|
|
|
+
|
|
|
|
|
+ # Get estimated capacity from database or use nominal as default
|
|
|
|
|
+ self.nominal_capacity_mah = self._db.get_cell_capacity_nom(self.cell_id)
|
|
|
|
|
+ self.estimated_capacity_mah = self._db.get_cell_capacity(self.cell_id) or self.nominal_capacity_mah
|
|
|
|
|
+
|
|
|
|
|
+ def measure_voltage(self):
|
|
|
|
|
+ # Logic to measure voltage
|
|
|
|
|
+ return self.voltage
|
|
|
|
|
+
|
|
|
|
|
+ def measure_current(self):
|
|
|
|
|
+ # Logic to measure current
|
|
|
|
|
+ return self.current
|
|
|
|
|
+
|
|
|
|
|
+ def measure_temperature(self):
|
|
|
|
|
+ # Logic to measure temperature
|
|
|
|
|
+ return self.temperature
|
|
|
|
|
+
|
|
|
|
|
+ def disconnect(self):
|
|
|
|
|
+ # Logic to disconnect the cell
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+ def connect(self):
|
|
|
|
|
+ # Logic to connect the cell
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+ def update_estimated_capacity(self, new_estimate_mah):
|
|
|
|
|
+ """Update the estimated capacity based on usage patterns and measurements"""
|
|
|
|
|
+ self.estimated_capacity_mah = new_estimate_mah
|
|
|
|
|
+ self._db.update_cell_capacity(self.cell_id, new_estimate_mah)
|
|
|
|
|
+
|
|
|
|
|
+ def get_capacity_health(self):
|
|
|
|
|
+ """Return cell health as a percentage of nominal capacity"""
|
|
|
|
|
+ return (self.estimated_capacity_mah / self.nominal_capacity_mah) * 100
|
|
|
|
|
+
|
|
|
|
|
+ def update_measurements(self, voltage, current, temperature):
|
|
|
|
|
+ """Update measurements and save to Redis"""
|
|
|
|
|
+ self.voltage = voltage
|
|
|
|
|
+ self.current = current
|
|
|
|
|
+ self.temperature = temperature
|
|
|
|
|
+ self._redis.save_measurement(self.cell_id, voltage, current, temperature)
|
|
|
|
|
+ self._update_capacity_estimate()
|
|
|
|
|
+
|
|
|
|
|
+ def _update_capacity_estimate(self):
|
|
|
|
|
+ """Update capacity estimate based on Redis data"""
|
|
|
|
|
+ new_estimate = self._redis.get_capacity_estimate(self.cell_id)
|
|
|
|
|
+ if new_estimate:
|
|
|
|
|
+ self.estimated_capacity_mah = new_estimate
|