Tools.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. '''
  2. 工具类
  3. '''
  4. __author__ = 'wlm'
  5. import CONFIGURE.PathSetting as PathSetting
  6. import sys
  7. sys.path.append(PathSetting.backend_path)
  8. import DBManager
  9. import pandas as pd
  10. import numpy as np
  11. import math
  12. from numba import jit
  13. import os
  14. import datetime
  15. import pdb
  16. import warnings
  17. warnings.filterwarnings('ignore')
  18. class Tools():
  19. def __init__(self):
  20. pass
  21. # 数据下载
  22. def data_download(self, write_path='', sn='', start_time='', end_time='', gps_switch=True, mode=0):
  23. '''
  24. 数据下载函数
  25. --------------输入参数------------
  26. write_path: 文件保存路径,不需要指定文件名
  27. sn: str, 电池sn号
  28. start_time: str, 开始时间
  29. end_time: str, 结束时间
  30. gps_switch: True:获取gps数据; False:不获取gps数据
  31. mode: 0:正常取数; 1:7255 取数
  32. --------------输出参数------------
  33. bms_data: 获取到的bms数据
  34. gps_data: 获取到的gps数据
  35. '''
  36. dbManager = DBManager.DBManager()
  37. print('downloading......')
  38. df_bms, df_gps = dbManager.get_data(sn=sn, start_time=start_time,
  39. end_time=end_time, gps_switch=gps_switch, mode=mode)
  40. df_bms.to_csv(os.path.join(write_path, 'BMS_{}_from_{}_to_{}.csv'.format(sn, start_time[0:10], end_time[0:10])), index=False, encoding='GB2312')
  41. if gps_switch:
  42. df_gps.to_csv(os.path.join(write_path, 'GPS_{}_from_{}_to_{}.csv'.format(sn, start_time[0:10], end_time[0:10])), index=False, encoding='GB2312')
  43. print('downloading success!')
  44. # 根据经纬度计算距离
  45. @jit
  46. def cal_distance(self, latitude1, longitude1,latitude2, longitude2,radius=6371):
  47. '''
  48. 输入两个地点的经纬度,输出两点间的距离
  49. '''
  50. radLat1 = (math.pi/180)*latitude1
  51. radLat2 = (math.pi/180)*latitude2
  52. radLng1 = (math.pi/180)*longitude1
  53. radLng2= (math.pi/180)*longitude2
  54. d=2*math.asin(math.sqrt(math.pow(math.sin((radLat1-radLat2)/2.0),2)+math.cos(radLat1)*math.cos(radLat2)*math.pow(math.sin((radLng1-radLng2)/2.0),2)))*radius
  55. return d
  56. # 输入GPS数据, 返回本段数据中GPS 位置相距最远的距离
  57. # @jit
  58. # def cal_max_dis(self, lat, long):
  59. # count = len(lat)
  60. # dis_mat=np.zeros([count,count])
  61. # for i in range(count):
  62. # for j in range(i,count):
  63. # dis_mat[i][j]=self.cal_distance(lat[i],long[i], lat[j],long[j])
  64. # max_dis = dis_mat.max()
  65. # return max_dis