mainvoltrange.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import pandas as pd
  2. from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
  3. from sqlalchemy import create_engine
  4. import pymysql
  5. import matplotlib.pyplot as plt
  6. import voltrange
  7. import time, datetime
  8. #--------------------------------------主函数------------------------------------------
  9. if __name__ == "__main__":
  10. #读取SN号
  11. SNnums_df=pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\didi_test_short.csv',encoding='GB18030')
  12. SNnums=SNnums_df['sn'].tolist()
  13. data_save1 = pd.DataFrame()
  14. # data_save2 = pd.DataFrame()
  15. # data_save3 = pd.DataFrame()
  16. # data_save4 = pd.DataFrame()
  17. start = time.time()
  18. k = 1
  19. for sn in SNnums:
  20. try:
  21. start1 = time.time()
  22. host='47.97.96.242'
  23. port=3306
  24. db='didi'
  25. user='root'
  26. password='qx123456'
  27. tablename='didi_data'
  28. param='date,device_id,bat_model,position,current,soc,celltemp,cellvolt_2,cellvolt_3,cellvolt_4,cellvolt_5,cellvolt_6,cellvolt_7,cellvolt_8,cellvolt_9'
  29. mysql = pymysql.connect (host=host, user=user, password=password, port=port, database=db)
  30. cursor = mysql.cursor()
  31. sql = "select %s from %s where device_id='%s'" %(param,tablename,sn)
  32. cursor.execute(sql)
  33. res = cursor.fetchall()
  34. df_bms= pd.DataFrame(res,columns=param.split(','))
  35. cursor.close()
  36. mysql.close()
  37. #log信息配置
  38. mylog=log.Mylog('log.txt','error')
  39. mylog.logcfg()
  40. print(sn)
  41. if not df_bms.empty:
  42. data_save_temp1 = voltrange.cellVolt_rang(sn,df_bms)
  43. # data_save_temp1,data_save_temp2,data_save_temp3,data_save_temp4 = voltrange.cellVolt_rang(sn,df_bms)
  44. #print(data_save_temp)
  45. if not data_save_temp1.empty:
  46. data_save1 = pd.concat([data_save1,data_save_temp1])
  47. # if not data_save_temp2.empty:
  48. # data_save2 = pd.concat([data_save2,data_save_temp2])
  49. # if not data_save_temp3.empty:
  50. # data_save3 = pd.concat([data_save3,data_save_temp3])
  51. # if not data_save_temp4.empty:
  52. # data_save4 = pd.concat([data_save4,data_save_temp4])
  53. #print(data_save)
  54. end1 = time.time()
  55. print(end1-start1)
  56. print(k)
  57. k = k+1
  58. except IndexError as e:
  59. print(repr(e))
  60. mylog.logopt(sn,e)
  61. pass
  62. data_save1.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'筛选1.csv')
  63. # data_save2.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'筛选2.csv')
  64. # data_save3.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'筛选3.csv')
  65. # data_save4.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'筛选4.csv')
  66. end = time.time()
  67. print(end-start)