Tools.py 2.6 KB

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