CalDist_Batch.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from math import radians, cos, sin, asin, sqrt
  2. import pandas as pd
  3. import numpy as np
  4. from datetime import datetime
  5. from datetime import timedelta
  6. from GpsRank import *
  7. from ProcessDfBms import *
  8. from ProcessDfGps import *
  9. from CalDist import *
  10. from LIB.BACKEND import DBManager
  11. import pdb
  12. asset_table_path='D:\\work\\Qixiang\\data_analyze_platform\\pengmin\\AllCarDist\\asset_table.xlsx'
  13. drive_info_path='D:\\work\\Qixiang\\data_analyze_platform\\pengmin\\AllCarDist\\drive_info.xlsx'
  14. asset_sheet_num=1
  15. usecols_list=[4,5]
  16. asset_table=pd.read_excel(asset_table_path,sheet_name=asset_sheet_num,skiprows=1,usecols=usecols_list)
  17. SN_list=asset_table['SN号'].values.tolist()
  18. print('从6060sheet读取到:'+str(len(SN_list))+'行')
  19. asset_table=asset_table.rename(columns={'SN号':'SN','状态':'state'})
  20. asset_table.set_index(["SN"],inplace=True)
  21. col_name=asset_table.columns.tolist()
  22. col_name.extend(['range','accum_soc','day_start_soc','day_end_soc','day_start_time','day_end_time'])
  23. asset_table=asset_table.reindex(columns=col_name)
  24. start_hour='00:00:00'#每日查询最早时间
  25. end_hour='23:59:00'#每日查询最晚时间
  26. date_index=pd.date_range('2021-07-31','2021-07-31')
  27. for date in date_index:
  28. '''遍历日期'''
  29. str_date=str(date)[:10]
  30. input_starttime=str_date+' '+start_hour
  31. input_endtime=str_date+' '+end_hour
  32. test_day=str_date[5:10]#月-日,用于建立sheet
  33. drive_info_path='D:\\work\\Qixiang\\data_analyze_platform\\pengmin\\AllCarDist\\6060\\drive_info'+test_day+'_50_end_'+'.xlsx'
  34. print(input_starttime)
  35. drive_info_aday=pd.DataFrame()
  36. SN_list_short=SN_list#先选择了0:50,50:end
  37. for SN in SN_list_short:
  38. '''遍历SN号'''
  39. SN=SN.strip('\t')
  40. SN=SN.strip('\n')
  41. try:
  42. range=GetDistInfo(SN,input_starttime,input_endtime)
  43. range_df=pd.DataFrame([range])
  44. drive_info_aday=pd.concat([drive_info_aday,range_df],axis=0)
  45. except:
  46. print(SN+' '+test_day+'fail')
  47. else:
  48. pass
  49. #print(SN+' '+test_day+'success')
  50. drive_info_aday.to_excel(drive_info_path,sheet_name=test_day)#sheet名称为testday