Selaa lähdekoodia

finish base structure

Silas Gruen 1 vuosi sitten
vanhempi
commit
941cd0f7a6
6 muutettua tiedostoa jossa 38 lisäystä ja 33 poistoa
  1. 4 3
      cell.py
  2. 22 0
      db_handler.py
  3. 5 2
      rack.py
  4. 4 4
      redis_handler.py
  5. 1 13
      segment.py
  6. 2 11
      subsegment.py

+ 4 - 3
cell.py

@@ -1,10 +1,10 @@
 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())
+
+    def __init__(self, cell_id):
+        self.cell_id = cell_id
         self.voltage = 0
         self.current = 0
         self.temperature = 0
@@ -14,6 +14,7 @@ class Cell:
         # 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
+        self.cell_limits = self._db.get_cell_limits(self.cell_id)
 
     def measure_voltage(self):
         # Logic to measure voltage

+ 22 - 0
db_handler.py

@@ -1,6 +1,23 @@
 import sqlite3
 from pathlib import Path
 
+
+class CellLimits():
+
+    def __init__(self, min_voltage, max_voltage, min_current, max_current, min_temperature, max_temperature):
+        if min_voltage > max_voltage:
+            raise ValueError("min_voltage cannot be greater than max_voltage")
+        if min_current > max_current:
+            raise ValueError("min_current cannot be greater than max_current")
+        if min_temperature > max_temperature:
+            raise ValueError("min_temperature cannot be greater than max_temperature")
+        self.min_voltage = min_voltage
+        self.max_voltage = max_voltage
+        self.min_current = min_current
+        self.max_current = max_current
+        self.min_temperature = min_temperature
+        self.max_temperature = max_temperature
+
 class DatabaseHandler:
     def __init__(self, db_path="cell_data.db"):
         # add code for initializing database connection
@@ -20,3 +37,8 @@ class DatabaseHandler:
         # add code for updating cell capacity in database
         pass
 
+    def get_cell_limits(self, cell_id):
+        # add code for getting cell limits from database
+        return None
+
+

+ 5 - 2
rack.py

@@ -10,8 +10,11 @@ class Rack:
         ]
 
     def measure_voltage(self):
-        # Logic to measure voltage
-        pass
+        total_voltage = 0
+        for segment in self.segments:
+            for subsegment in segment.subsegments:
+                total_voltage += subsegment.get_subset_voltage()
+        return total_voltage
 
     def measure_power(self):
         # Logic to measure power

+ 4 - 4
redis_handler.py

@@ -2,8 +2,9 @@ import redis
 from datetime import datetime
 
 class RedisHandler:
-    def __init__(self, host='localhost', port=6379, db=0):
+    def __init__(self, host='localhost', port=6379, db=0, expire_time=60 * 60 * 24 * 30):   # Keep data for 30 days
         self.client = redis.Redis(host=host, port=port, db=db)
+        self.expire_time = expire_time
 
     def save_measurement(self, cell_id, voltage, current, temperature):
         """Save cell measurements with timestamp"""
@@ -14,7 +15,7 @@ class RedisHandler:
             'current': current,
             'temperature': temperature
         })
-        self.client.expire(key, 60 * 60 * 24 * 30)  # Keep data for 30 days
+        self.client.expire(key, self.expire_time)
 
     def get_capacity_estimate(self, cell_id):
         """Calculate estimated capacity based on historical data"""
@@ -22,7 +23,6 @@ class RedisHandler:
         if not measurements:
             return None
             
-        # Here you would implement your capacity estimation algorithm
+        # TODO: Put the capacity estimation algorithm
         # based on voltage curves, current integration, etc.
-        # This is a simplified example
         return float(self.client.get(f"cell:{cell_id}:estimated_capacity") or 0)

+ 1 - 13
segment.py

@@ -12,16 +12,4 @@ class Segment:
         self.subsegments = [
             Subsegment(self.segment_id, subseg['id'])
             for subseg in segment_config['subsegments']
-        ]
-
-    def measure_voltage(self):
-        # Logic to measure voltage
-        pass
-
-    def measure_power(self):
-        # Logic to measure power
-        pass
-
-    def measure_temperature(self):
-        # Logic to measure temperature
-        pass
+        ]

+ 2 - 11
subsegment.py

@@ -29,11 +29,11 @@ class Subsegment:
     # def calculate_saved_power(self):
     #     return sum(self.get_power())
 
-    def get_voltage(self):
+    def get_subset_voltage(self):
         voltages = self.measure_voltages()
         return sum(voltages) / len(voltages) if voltages else 0
 
-    def get_current(self):
+    def get_subset_current(self):
         currents = self.measure_currents()
         return sum(currents)
 
@@ -48,12 +48,3 @@ class Subsegment:
     def get_total_estimated_capacity_mah(self):
         """For cells in parallel, total estimated capacity is sum of individual estimated capacities"""
         return sum(cell.estimated_capacity_mah for cell in self.cells)
-    
-    def get_capacity_health_percentage(self):
-        """Estimate capacity health based on voltage and internal resistance"""
-        voltages = self.measure_voltages()
-        if not voltages:
-            return 0
-        avg_voltage = sum(voltages) / len(voltages)
-        # Basic health estimation (can be made more sophisticated)
-        return min(100, max(0, (avg_voltage - 2.5) / (4.2 - 2.5) * 100))