subsegment.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from cell import Cell
  2. from config_loader import ConfigLoader
  3. class Subsegment:
  4. def __init__(self, segment_id, subsegment_id):
  5. self.segment_id = segment_id
  6. self.subsegment_id = subsegment_id
  7. config = ConfigLoader()
  8. cell_ids = config.get_cell_ids_for_subsegment(segment_id, subsegment_id)
  9. if not cell_ids:
  10. raise ValueError(f"No cell IDs configured for subsegment {subsegment_id}")
  11. # Create cells with explicitly configured IDs
  12. self.cells = [Cell(cell_id) for cell_id in cell_ids]
  13. def measure_voltages(self):
  14. return [cell.measure_voltage() for cell in self.cells]
  15. def measure_currents(self):
  16. return [cell.measure_current() for cell in self.cells]
  17. def measure_temperatures(self):
  18. return [cell.measure_temperature() for cell in self.cells]
  19. # def get_power(self):
  20. # return [cell.measure_voltage() * cell.measure_current() for cell in self.cells]
  21. # def calculate_saved_power(self):
  22. # return sum(self.get_power())
  23. def get_voltage(self):
  24. voltages = self.measure_voltages()
  25. return sum(voltages) / len(voltages) if voltages else 0
  26. def get_current(self):
  27. currents = self.measure_currents()
  28. return sum(currents)
  29. def disconnect(self):
  30. # Logic to disconnect the subsegment
  31. pass
  32. def connect(self):
  33. # Logic to connect the subsegment
  34. pass
  35. def get_total_estimated_capacity_mah(self):
  36. """For cells in parallel, total estimated capacity is sum of individual estimated capacities"""
  37. return sum(cell.estimated_capacity_mah for cell in self.cells)
  38. def get_capacity_health_percentage(self):
  39. """Estimate capacity health based on voltage and internal resistance"""
  40. voltages = self.measure_voltages()
  41. if not voltages:
  42. return 0
  43. avg_voltage = sum(voltages) / len(voltages)
  44. # Basic health estimation (can be made more sophisticated)
  45. return min(100, max(0, (avg_voltage - 2.5) / (4.2 - 2.5) * 100))