bms_record_ctl.py 1.9 KB

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