bms_record_ctl.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. import csv
  4. from utils.delay import m_delay
  5. from utils.globalvar import SD
  6. from widget.bms_record import Win_Record
  7. from model.record_model import RecordModel
  8. class BmsRecordControll:
  9. def __init__(self):
  10. self._view = Win_Record()
  11. self._model = RecordModel()
  12. self.init()
  13. def init(self):
  14. self._view.can_record_start_signal.connect(self._save)
  15. self._view.can_record_stop_signal.connect(self._stop)
  16. def _save(self):
  17. SD.RECORD_NAME, ok = self._view.save_csv()
  18. if SD.RECORD_NAME == "":
  19. return
  20. self._view.save_record.setDisabled(True)
  21. self._view.stop_record.setDisabled(False)
  22. header = ["时间戳", "簇号", "故障等级", "簇电压", "簇电流", "簇SOC", "簇SOH", "簇单体V平均", "簇单体Vmax单体号", "簇单体Vmax", "簇单体Vmin单体号", "簇单体Vmin", "簇单体T平均", "簇单体Tmax单体号", "簇单体Tmax", "簇单体Tmin单体号", "簇单体Tmin", "主正接触器", "主负接触器", "预充接触器", "断路器", "干接点1", "干接点2", "最高单体SOC", "最低单体SOC", "平均单体SOC"]
  23. if SD.CCU_TYPE == 0:
  24. header_1= ["V" + str(i + 1) for i in range(16)]
  25. header_2 = ["T" + str(i + 1) for i in range(16)]
  26. else:
  27. header_1= ["V" + str(i + 1) for i in range(396)]
  28. header_2 = ["T" + str(i + 1) for i in range(360)]
  29. header.extend(header_1)
  30. header.extend(header_2)
  31. if ok:
  32. with open(SD.RECORD_NAME, 'w') as csvfile:
  33. writer = csv.writer(csvfile, dialect='excel', lineterminator='\n')
  34. writer.writerow(header)
  35. SD.RECORD_SAVE = 1
  36. else:
  37. return
  38. def _stop(self):
  39. self._view.save_record.setDisabled(False)
  40. self._view.stop_record.setDisabled(True)
  41. SD.RECORD_SAVE = 0