Tools.py 2.5 KB

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