Tools.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. '''
  2. 工具类
  3. '''
  4. __author__ = 'Wang Liming'
  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='', data_groups=['bms', 'gps']):
  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_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=data_groups)
  39. for data_group in data_groups:
  40. df_data[data_group].to_csv(os.path.join(write_path, '{}_{}_from_{}_to_{}.csv'.format(data_group, sn, start_time[0:10], end_time[0:10])), index=False, encoding='GB2312')
  41. print('downloading success!')
  42. # 根据经纬度计算距离
  43. @jit
  44. def cal_distance(self, latitude1, longitude1,latitude2, longitude2,radius=6371):
  45. '''
  46. 输入两个地点的经纬度,输出两点间的距离
  47. '''
  48. radLat1 = (math.pi/180)*latitude1
  49. radLat2 = (math.pi/180)*latitude2
  50. radLng1 = (math.pi/180)*longitude1
  51. radLng2= (math.pi/180)*longitude2
  52. 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
  53. return d
  54. # 输入GPS数据, 返回本段数据中GPS 位置相距最远的距离
  55. # @jit
  56. # def cal_max_dis(self, lat, long):
  57. # count = len(lat)
  58. # dis_mat=np.zeros([count,count])
  59. # for i in range(count):
  60. # for j in range(i,count):
  61. # dis_mat[i][j]=self.cal_distance(lat[i],long[i], lat[j],long[j])
  62. # max_dis = dis_mat.max()
  63. # return max_dis