{ "cells": [ { "cell_type": "code", "execution_count": 15, "source": [ "from LIB.BACKEND import DBManager\r\n", "from LIB.MIDDLE.CellStateEstimation.Common import log\r\n", "import datetime\r\n", "import pandas as pd\r\n", "import numpy as np\r\n", "import os \r\n", "from DataPreProcessMGMC import DataPreProcess\r\n", "from scipy import stats\r\n", "\r\n", "#log信息配置\r\n", "mylog=log.Mylog('log.txt','error')\r\n", "mylog.logcfg()\r\n", "\r\n", "dbManager = DBManager.DBManager()\r\n", "dataSOH = pd.read_excel('../V1_0_0/sn-20210903.xlsx',sheet_name='MGMC')\r\n", "fileNames = dataSOH['sn']\r\n", "fileNames = list(fileNames)\r\n", "\r\n", "data_GMGC=pd.DataFrame()\r\n", "for k in range(len(fileNames)):\r\n", " # try: \r\n", " sn = fileNames[k]\r\n", " df_data = dbManager.get_data(sn=sn, start_time='2021-10-15 00:00:00', end_time='2021-11-06 00:00:00', data_groups=['bms'])\r\n", " data_bms = df_data['bms']\r\n", " data_bms['sn'] = sn\r\n", " df_sheetCat = DataPreProcess.data_split_by_status(DataPreProcess,data_bms, drive_interval_threshold=120, charge_interval_threshold=300, drive_stand_threshold=120, charge_stand_threshold=300)\r\n", " unique_status_idx = np.unique(df_sheetCat.data_split_by_status.values)\r\n", " data_result = pd.DataFrame()\r\n", " list_result = []\r\n", " for n in unique_status_idx:\r\n", " list_result.append(df_sheetCat[df_sheetCat.data_split_by_status==n]) \r\n", " \r\n", " maxI=[]\r\n", " modI=[]\r\n", " lenI=[]\r\n", " temp1_start=[]\r\n", " temp2_start=[]\r\n", " temp1_fin=[]\r\n", " temp2_fin=[]\r\n", " time_start=[]\r\n", " time_fin=[]\r\n", " time_drivefin=[]\r\n", " temp1_drivefin=[]\r\n", " temp2_drivefin=[]\r\n", " sn2=[]\r\n", " \r\n", " for i in range(1,len(list_result)):\r\n", " if list_result[i]['data_status'].values[0]=='charge':\r\n", " \r\n", " maxI.append(max(list_result[i]['总电流[A]'].values[:10]))\r\n", " modI.append(stats.mode(list_result[i]['总电流[A]'].values[:10])[0][0])\r\n", " lenI.append(len(list_result[i]['总电流[A]'].values))\r\n", " temp1_start.append(list_result[i]['单体温度1'].values[0])\r\n", " temp2_start.append(list_result[i]['单体温度2'].values[0])\r\n", " temp1_fin.append(list_result[i]['单体温度1'].values[-1])\r\n", " temp2_fin.append(list_result[i]['单体温度2'].values[-1])\r\n", " time_start.append(list_result[i]['时间戳'].values[0])\r\n", " time_fin.append(list_result[i]['时间戳'].values[-1])\r\n", " time_drivefin.append(list_result[i-1]['时间戳'].values[0])\r\n", " temp1_drivefin.append(list_result[i-1]['单体温度1'].values[0])\r\n", " temp2_drivefin.append(list_result[i-1]['单体温度2'].values[0]) \r\n", " sn2.append(list_result[i]['sn'].values[0])\r\n", " dic={\"初始充电电流max\":maxI,\"初始充电电流mod\":modI,\"电流长度\":lenI,\"初始充电温度1\":temp1_start,\"初始充电温度2\":temp2_start,\r\n", " \"结束充电温度1\":temp1_fin,\"结束充电温度2\":temp2_fin,\"初始充电时间\":time_start,\r\n", " \"结束充电时间\":time_fin,\"行驶结束时间\":time_drivefin,\"行驶结束温度1\":temp1_drivefin,\r\n", " \"行驶结束温度2\":temp2_drivefin,\"sn\":sn2}\r\n", " df_analyse=pd.DataFrame(dic)\r\n", "\r\n", " data_analyse=df_analyse[df_analyse['电流长度'].values>5]\r\n", "\r\n", " mean_temp1=[]\r\n", " mean_temp2=[]\r\n", " mean_temp3=[]\r\n", " time_diff_stand=[]\r\n", " time_diff_charge=[]\r\n", "\r\n", " for i in range(len(data_analyse)):\r\n", " meantemp1=(data_analyse['初始充电温度1'].values[i]+data_analyse['初始充电温度2'].values[i])/2\r\n", " mean_temp1.append(meantemp1)\r\n", " meantemp2=(data_analyse['结束充电温度1'].values[i]+data_analyse['结束充电温度2'].values[i])/2\r\n", " mean_temp2.append(meantemp2)\r\n", " meantemp3=(data_analyse['行驶结束温度1'].values[i]+data_analyse['行驶结束温度2'].values[i])/2\r\n", " mean_temp3.append(meantemp3)\r\n", " td_charge=float(np.diff([data_analyse['初始充电时间'].values[i],data_analyse['结束充电时间'].values[i]])/np.timedelta64(1, 'm'))\r\n", " time_diff_charge.append(td_charge)\r\n", " td_stand=float(np.diff([data_analyse['行驶结束时间'].values[i],data_analyse['初始充电时间'].values[i]])/np.timedelta64(1, 'm'))\r\n", " time_diff_stand.append(td_stand) \r\n", " \r\n", " data_analyse['初始充电温度']=mean_temp1\r\n", " data_analyse['结束充电温度']=mean_temp2\r\n", " data_analyse['行驶结束温度']=mean_temp3\r\n", " data_analyse['闲置时长']=time_diff_stand\r\n", " data_analyse['充电时长']=time_diff_charge\r\n", "\r\n", " diff_temp=[]\r\n", " for i in range(len(data_analyse)):\r\n", " difftemp=data_analyse['结束充电温度'].values[i]-data_analyse['初始充电温度'].values[i]\r\n", " diff_temp.append(difftemp)\r\n", " data_analyse['充电温差']=diff_temp\r\n", "\r\n", " data_select=data_analyse[data_analyse['充电时长'].values>5]\r\n", "\r\n", " data_select.to_csv('./result/data'+sn+'.csv')\r\n", "\r\n", " data_GMGC = data_GMGC.append(data_select)\r\n", " data_GMGC.to_csv('./result/dataGMGC.csv')\r\n", "\r\n", " # except Exception as e:\r\n", " # print(repr(e))\r\n", " # mylog.logopt(sn,e)\r\n", " # pass \r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n", "\r\n" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "### start to get data MGMCLN750N215H001 from 2021-10-15 00:00:00 to 2021-11-06 00:00:00\n", "# get data from 2021-11-05 00:00:00 to 2021-11-06 00:00:00......... \n", "all data-getting done, bms_count is 11389, gps_count is 0, system_count is 0, accum_count is 0 \n", "\n", "### start to get data MGMCLN750N215H002 from 2021-10-15 00:00:00 to 2021-11-06 00:00:00\n", "# get data from 2021-10-27 00:00:00 to 2021-10-28 00:00:00......... " ] }, { "output_type": "error", "ename": "KeyboardInterrupt", "evalue": "", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[1;31m# try:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 22\u001b[0m \u001b[0msn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfileNames\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 23\u001b[1;33m \u001b[0mdf_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdbManager\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_data\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msn\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstart_time\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'2021-10-15 00:00:00'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend_time\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'2021-11-06 00:00:00'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata_groups\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'bms'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 24\u001b[0m \u001b[0mdata_bms\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdf_data\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'bms'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 25\u001b[0m \u001b[0mdata_bms\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'sn'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msn\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32mD:\\Platform\\platform_python\\data_analyze_platform\\LIB\\BACKEND\\DBManager.py\u001b[0m in \u001b[0;36mget_data\u001b[1;34m(self, url, sn, start_time, end_time, data_groups)\u001b[0m\n\u001b[0;32m 351\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdata_group\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'bms'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 352\u001b[0m \u001b[0mfile_url\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m12\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msn\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m\"&from=\"\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mtimefrom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrftime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'%Y-%m-%d %H:%M:%S'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m\"&to=\"\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mtimeto\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrftime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'%Y-%m-%d %H:%M:%S'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 353\u001b[1;33m \u001b[0mbms_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mDBManager\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_data\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_url\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'bms'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mmode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 354\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdata_group\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'gps'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 355\u001b[0m \u001b[0mfile_url\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m16\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msn\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m\"&from=\"\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mtimefrom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrftime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'%Y-%m-%d %H:%M:%S'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m\"&to=\"\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mtimeto\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstrftime\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'%Y-%m-%d %H:%M:%S'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32mD:\\Platform\\platform_python\\data_analyze_platform\\LIB\\BACKEND\\DBManager.py\u001b[0m in \u001b[0;36m_get_data\u001b[1;34m(urls, type_name, mode)\u001b[0m\n\u001b[0;32m 236\u001b[0m \u001b[1;32mcontinue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 237\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 238\u001b[1;33m \u001b[0mdata_blocks\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconcatenate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata_blocks\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mdata_block\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 239\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 240\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;34m'all the input array dimensions for the concatenation axis must match exactly'\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mor\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m<__array_function__ internals>\u001b[0m in \u001b[0;36mconcatenate\u001b[1;34m(*args, **kwargs)\u001b[0m\n", "\u001b[1;31mKeyboardInterrupt\u001b[0m: " ] } ], "metadata": {} }, { "cell_type": "code", "execution_count": 17, "source": [ "data_GMGC.append(data_select)" ], "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " 初始充电电流max 初始充电电流mod 电流长度 初始充电温度1 初始充电温度2 结束充电温度1 结束充电温度2 \\\n", "0 7.7 7.7 1025 6.0 7.0 11.0 11.0 \n", "2 7.7 7.7 1031 7.0 7.0 10.0 9.0 \n", "\n", " 初始充电时间 结束充电时间 行驶结束时间 行驶结束温度1 \\\n", "0 2021-10-17 12:23:57 2021-10-17 15:14:28 2021-10-15 21:38:13 18.0 \n", "2 2021-10-18 06:21:53 2021-10-18 09:13:32 2021-10-18 06:21:49 7.0 \n", "\n", " 行驶结束温度2 sn 初始充电温度 结束充电温度 行驶结束温度 闲置时长 \\\n", "0 16.0 MGMCLN750N215H001 6.5 11.0 17.0 2325.733333 \n", "2 7.0 MGMCLN750N215H001 7.0 9.5 7.0 0.066667 \n", "\n", " 充电时长 充电温差 \n", "0 170.516667 4.5 \n", "2 171.650000 2.5 " ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
初始充电电流max初始充电电流mod电流长度初始充电温度1初始充电温度2结束充电温度1结束充电温度2初始充电时间结束充电时间行驶结束时间行驶结束温度1行驶结束温度2sn初始充电温度结束充电温度行驶结束温度闲置时长充电时长充电温差
07.77.710256.07.011.011.02021-10-17 12:23:572021-10-17 15:14:282021-10-15 21:38:1318.016.0MGMCLN750N215H0016.511.017.02325.733333170.5166674.5
27.77.710317.07.010.09.02021-10-18 06:21:532021-10-18 09:13:322021-10-18 06:21:497.07.0MGMCLN750N215H0017.09.57.00.066667171.6500002.5
\n", "
" ] }, "metadata": {}, "execution_count": 17 } ], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [], "outputs": [], "metadata": {} } ], "metadata": { "orig_nbformat": 4, "language_info": { "name": "python", "version": "3.8.10", "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py" }, "kernelspec": { "name": "python3", "display_name": "Python 3.8.10 64-bit (conda)" }, "interpreter": { "hash": "69976922f58704918d459eb5dccc4a4074095a997db3fffa9f9946bbc3807710" } }, "nbformat": 4, "nbformat_minor": 2 }