main.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import datetime
  2. import pandas as pd
  3. from LIB.BACKEND import DBManager, Log
  4. import time, datetime
  5. from apscheduler.schedulers.blocking import BlockingScheduler
  6. import log
  7. from pandas.core.frame import DataFrame
  8. import rest_stscs_v1
  9. #...................................电池包电芯安全诊断函数......................................................................................................................
  10. def rest_statics():
  11. global SNnums
  12. global df_rest_static
  13. start=time.time()
  14. now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  15. now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
  16. start_time=now_time-datetime.timedelta(days=3)
  17. end_time=str(now_time)
  18. start_time=str(start_time)
  19. k = 0
  20. for sn in SNnums[k:]:
  21. if 'PK500' in sn:
  22. celltype=1 #6040三元电芯
  23. elif 'PK502' in sn:
  24. celltype=2 #4840三元电芯
  25. elif 'K504B' in sn:
  26. celltype=99 #60ah林磷酸铁锂电芯
  27. elif 'MGMLXN750' in sn:
  28. celltype=3 #力信50ah三元电芯
  29. elif 'MGMCLN750' in sn:
  30. celltype=4 #CATL 50ah三元电芯
  31. elif 'UD' in sn:
  32. celltype=4 #CATL 50ah三元电芯
  33. elif 'TJMCL' in sn:
  34. celltype=100 #金茂电芯
  35. else:
  36. print('SN:{},未找到对应电池类型!!!'.format(sn))
  37. continue
  38. # sys.exit()
  39. print('计算的第' + str(k) + '个:' + sn)
  40. k = k + 1
  41. #读取原始数据库数据........................................................................................................................................................
  42. start_time = '2022-03-01 00:00:00'
  43. end_time = '2022-04-01 00:00:00'
  44. dbManager = DBManager.DBManager()
  45. df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
  46. df_bms = df_data['bms']
  47. df_Diag_rest_add = pd.DataFrame(columns = ['sn', 'time_st', 'time_end', 'delta_time', 'soc_st', 'soc_sp', 'delta_soc', 'temp_st', 'temp_sp', 'meancrnt', 'sts_flg'])
  48. #充电统计................................................................................................................................................................
  49. if not df_bms.empty:
  50. rest_statics_temp = rest_stscs_v1.cell_statistic(sn,celltype,df_bms)#析锂检测
  51. df_Diag_rest_add = rest_statics_temp.rest_sta()
  52. if not df_Diag_rest_add.empty:
  53. df_rest_static = df_rest_static.append(df_Diag_rest_add)
  54. df_rest_static = df_rest_static.drop_duplicates(subset = ['sn','time_st'], keep = 'first', inplace = False)
  55. # df_rest_static.sort_values(by = ['sn'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
  56. df_rest_static.to_csv(r'D:\Develop\User\Liuzhongxiao\data_analyze_platform\USER\LZX\01算法开发\08合众算法开发\01车辆行为统计\静置统计.csv',index=False,encoding='GB18030')
  57. end=time.time()
  58. print(end-start)
  59. #...............................................主函数.......................................................................................................................
  60. if __name__ == "__main__":
  61. global SNnums
  62. global df_rest_static
  63. excelpath=r'D:\Develop\User\Liuzhongxiao\data_analyze_platform\USER\LZX\01算法开发\00项目sn号\sn-20210903.xlsx'
  64. SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
  65. SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
  66. SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
  67. SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
  68. SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
  69. SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
  70. SNnums_6060=SNdata_6060['SN号'].tolist()
  71. SNnums_6040=SNdata_6040['SN号'].tolist()
  72. SNnums_4840=SNdata_4840['SN号'].tolist()
  73. SNnums_L7255=SNdata_L7255['SN号'].tolist()
  74. SNnums_C7255=SNdata_C7255['SN号'].tolist()
  75. SNnums_U7255=SNdata_U7255['SN号'].tolist()
  76. # SNums_file = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\02析锂分析\各项目析锂情况_211130\增加波峰高度与峰谷比计算结果\SNnums_C7255析锂情况析锂排序.csv',encoding='GB18030')
  77. # SNums_sn = SNums_file['sn']
  78. # liplated_high = SNums_sn.iloc[7:10]
  79. # liplated_low = SNums_sn.iloc[-11:-1]
  80. # cal_sn = liplated_high.append(liplated_low)
  81. m = 100
  82. SNnums = SNnums_U7255 + SNnums_C7255[0:m] + SNnums_L7255 + SNnums_4840[0:m] + SNnums_6040[0:m] + SNnums_6060[0:m]
  83. # SNnums = SNnums_U7255
  84. # SNnums=['TJMCL120502305010','TJMCL120502305012','TJMCL120502305048','TJMCL120502305044','TJMCL120502305026','TJMCL120502305022','TJMCL120502305032','TJMCL120502305038']
  85. # SNnums = list(cal_sn)#['MGMCLN750N215N049']#['MGMCLN750N215N049'] #SNnums_6040 #SNnums_C7255 #SNnums_6040['MGMCLN750N215N049']
  86. # SNnums = pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\lzx\01算法开发\02析锂检测\liplated\疑似析锂电池sn.csv',encoding='GB18030')
  87. # SNnums=['TJMCL120502305010','TJMCL120502305012','TJMCL120502305048','TJMCL120502305044','TJMCL120502305026','TJMCL120502305022','TJMCL120502305032','TJMCL120502305038']
  88. mylog=log.Mylog('log_diag.txt','error')#'TJMCL120502305010','TJMCL120502305012',
  89. mylog.logcfg()
  90. #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................
  91. df_rest_static = pd.read_csv(r'D:\Develop\User\Liuzhongxiao\data_analyze_platform\USER\LZX\01算法开发\08合众算法开发\01车辆行为统计\静置统计.csv',encoding='GB18030')
  92. print('----------------输入--------')
  93. print('-------计算中-----------')
  94. rest_statics()
  95. #定时任务.......................................................................................................................................................................
  96. # scheduler = BlockingScheduler()
  97. # scheduler.add_job(rest_statics, 'interval', seconds=10, id='diag_job')
  98. # try:
  99. # scheduler.start()
  100. # except Exception as e:
  101. # scheduler.shutdown()
  102. # print(repr(e))
  103. # mylog.logopt(e)