import pandas as pd from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log from sqlalchemy import create_engine import pymysql import matplotlib.pyplot as plt import voltrange import time, datetime #--------------------------------------主函数------------------------------------------ if __name__ == "__main__": #读取SN号 SNnums_df=pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\didi_test_short.csv',encoding='GB18030') SNnums=SNnums_df['sn'].tolist() data_save1 = pd.DataFrame() # data_save2 = pd.DataFrame() # data_save3 = pd.DataFrame() # data_save4 = pd.DataFrame() start = time.time() k = 1 for sn in SNnums: try: start1 = time.time() host='47.97.96.242' port=3306 db='didi' user='root' password='qx123456' tablename='didi_data' 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' mysql = pymysql.connect (host=host, user=user, password=password, port=port, database=db) cursor = mysql.cursor() sql = "select %s from %s where device_id='%s'" %(param,tablename,sn) cursor.execute(sql) res = cursor.fetchall() df_bms= pd.DataFrame(res,columns=param.split(',')) cursor.close() mysql.close() #log信息配置 mylog=log.Mylog('log.txt','error') mylog.logcfg() print(sn) if not df_bms.empty: data_save_temp1 = voltrange.cellVolt_rang(sn,df_bms) # data_save_temp1,data_save_temp2,data_save_temp3,data_save_temp4 = voltrange.cellVolt_rang(sn,df_bms) #print(data_save_temp) if not data_save_temp1.empty: data_save1 = pd.concat([data_save1,data_save_temp1]) # if not data_save_temp2.empty: # data_save2 = pd.concat([data_save2,data_save_temp2]) # if not data_save_temp3.empty: # data_save3 = pd.concat([data_save3,data_save_temp3]) # if not data_save_temp4.empty: # data_save4 = pd.concat([data_save4,data_save_temp4]) #print(data_save) end1 = time.time() print(end1-start1) print(k) k = k+1 except IndexError as e: print(repr(e)) mylog.logopt(sn,e) pass data_save1.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'筛选1.csv') # data_save2.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'筛选2.csv') # data_save3.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'筛选3.csv') # data_save4.to_csv(r'D:\Work\Code_write\data_analyze_platform\test\lzx\01Qixiang\01电压排序\01算法\DBDownload\\'+'筛选4.csv') end = time.time() print(end-start)