{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "### start to get data PK504B10100004341 from 2021-10-30 00:00:00 to 2021-10-31 00:00:00\n", "# get data from 2021-10-30 00:00:00 to 2021-10-31 00:00:00......... \n", "all data-getting done, bms_count is 3754, gps_count is 0, system_count is 0, accum_count is 0 \n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\frame.py:4441: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " return super().rename(\n" ] } ], "source": [ "# 获取数据\n", "import sys\n", "from LIB.BACKEND import DBManager\n", "from LIB.MIDDLE.OutlierDetection.VoltOutlier.V_1_0_0 import sta\n", "import pymysql\n", "import pandas as pd\n", "from matplotlib import pyplot as plt\n", "\n", "plt.rcParams['font.sans-serif'] = ['SimHei']\n", "plt.rcParams['axes.unicode_minus'] = False\n", "\n", "# 更新sn列表\n", "host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'\n", "port=3306\n", "db='qixiang_oss'\n", "user='qixiang_oss'\n", "password='Qixiang2021'\n", "conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)\n", "cursor = conn.cursor()\n", "cursor.execute(\"select sn, imei, add_time from app_device\")\n", "res = cursor.fetchall()\n", "df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])\n", "df_sn = df_sn.reset_index(drop=True)\n", "conn.close();\n", "\n", "window = 50\n", "step = 10\n", "window2 = 5\n", "step2 = 3\n", "volt_column = ['单体电压1', '单体电压2',\n", " '单体电压3', '单体电压4','单体电压5', '单体电压6','单体电压7', '单体电压8','单体电压9', '单体电压10', '单体电压11', '单体电压12',\n", " '单体电压13', '单体电压14','单体电压15', '单体电压16','单体电压17', '单体电压18','单体电压19', '单体电压20']\n", "columns = ['时间戳', '单体电压1', '单体电压2','单体电压3', '单体电压4','单体电压5', '单体电压6','单体电压7', '单体电压8','单体电压9', '单体电压10', '单体电压11', '单体电压12',\n", "'单体电压13', '单体电压14','单体电压15', '单体电压16','单体电压17', '单体电压18','单体电压19', '单体电压20']\n", "dbManager = DBManager.DBManager()\n", "\n", "all_result = pd.DataFrame(columns=['sn', 'suptype', 'type', 'num', 'alarm_time'])\n", "for sn in df_sn['sn'].tolist()[0:3]:\n", " st = '2021-10-30 00:00:00'\n", " et = '2021-10-31 00:00:00'\n", "\n", " \n", " df_data = dbManager.get_data(sn=sn, start_time=st, end_time=et, data_groups=['bms'])\n", " # \n", " df_bms = df_data['bms']\n", "\n", " df_ori = df_bms[columns]\n", " df_ori.rename(columns = {'时间戳':'time'}, inplace=True)\n", " df = df_ori.drop_duplicates(subset=['time']) # 删除时间相同的数据\n", " df = df.reset_index(drop=True)\n", " df_result_1,time_list_1 = sta.cal_voltdiff_uniform(df,volt_column, window=window, step=step, window2=window2, step2=step2)\n", " df_result_2,time_list_2 = sta.cal_volt_uniform(df,volt_column, window=window, step=step)\n", "\n", " df_result_1['time'] = time_list_1\n", " df_result_2['time'] = time_list_2\n", " # second_list = [((pd.to_datetime(x)-pd.to_datetime(time_list[0])).total_seconds()) for x in time_list] # 距离第一个点的分钟数\n", "\n", " # fig = plt.figure(figsize=(20,10))\n", "\n", " # length = len(df_result)\n", " # for column in volt_column:\n", " # # plt.plot([x for x in range(0, length)], df_result[column][0:length], label=column)\n", " # plt.scatter(time_list[:], df_result[column][:length], label=column)\n", "\n", " # plt.legend()\n", " # plt.title('{}电压离群(电压滤波窗口大小:{}, 步进大小:{}'.format(sn, window, step, window2, step2))\n", " # sn = sn.replace('/','_')\n", " # plt.savefig('./结果/新数据/' + sn + '.png')\n", " # plt.close()\n", "\n", " # 报警\n", " # df_result_1['time'] = time_list_1\n", " # alarm_result = sta.alarm(df_result_1, volt_column, alarm_window=20, alarm_ratio=0.9, alarm_threshold=3.5)\n", " # alarm_result['sn'] = [sn] * len(alarm_result)\n", " # alarm_result['suptype'] = ['电压变化量离群'] * len(alarm_result)\n", " # all_result = pd.concat([all_result, alarm_result])\n", "\n", " # df_result_2['time'] = time_list_2\n", " # alarm_result = sta.alarm(df_result_2, volt_column, alarm_window=20, alarm_ratio=0.9, alarm_threshold=3.5)\n", " # alarm_result['sn'] = [sn] * len(alarm_result)\n", " # alarm_result['suptype'] = ['电压离群'] * len(alarm_result)\n", "\n", " # 记录偏差超过3的电芯编号\n", " df_all_result = sta.instorage(sn, df_result_1, df_result_2)\n", " \n", " # all_result = pd.concat([all_result, alarm_result])\n", " # all_result.to_csv('./result_volt.csv')\n", " break" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "### start to get data MGMCLN750N215I037 from 2021-10-23 00:00:00 to 2021-10-31 00:00:00\n", "# get data from 2021-10-30 00:00:00 to 2021-10-31 00:00:00......... \n", "all data-getting done, bms_count is 32625, gps_count is 0, system_count is 0, accum_count is 0 \n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\frame.py:4441: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " return super().rename(\n" ] } ], "source": [ "# 单车运行\n", "# 获取数据\n", "import sys\n", "from LIB.BACKEND import DBManager\n", "from LIB.MIDDLE.OutlierDetection.VoltOutlier.V_1_0_0 import sta\n", "import pymysql\n", "import pandas as pd\n", "from matplotlib import pyplot as plt\n", "\n", "plt.rcParams['font.sans-serif'] = ['SimHei']\n", "plt.rcParams['axes.unicode_minus'] = False\n", "\n", "# 更新sn列表\n", "# host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'\n", "# port=3306\n", "# db='qixiang_oss'\n", "# user='qixiang_oss'\n", "# password='Qixiang2021'\n", "# conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)\n", "# cursor = conn.cursor()\n", "# cursor.execute(\"select sn, imei, add_time from app_device\")\n", "# res = cursor.fetchall()\n", "# df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])\n", "# df_sn = df_sn.reset_index(drop=True)\n", "# conn.close();\n", "\n", "window = 50\n", "step = 10\n", "window2 = 5\n", "step2 = 3\n", "volt_column = ['单体电压1', '单体电压2',\n", " '单体电压3', '单体电压4','单体电压5', '单体电压6','单体电压7', '单体电压8','单体电压9', '单体电压10', '单体电压11', '单体电压12',\n", " '单体电压13', '单体电压14','单体电压15', '单体电压16','单体电压17', '单体电压18','单体电压19', '单体电压20']\n", "columns = ['时间戳', '单体电压1', '单体电压2','单体电压3', '单体电压4','单体电压5', '单体电压6','单体电压7', '单体电压8','单体电压9', '单体电压10', '单体电压11', '单体电压12',\n", "'单体电压13', '单体电压14','单体电压15', '单体电压16','单体电压17', '单体电压18','单体电压19', '单体电压20']\n", "dbManager = DBManager.DBManager()\n", "sns = ['MGMCLN750N215I037']\n", "all_result = pd.DataFrame(columns=['sn', 'suptype', 'type', 'num', 'alarm_time'])\n", "for sn in sns:\n", " sn = 'MGMCLN750N215I037'\n", " st = '2021-10-23 00:00:00'\n", " et = '2021-10-31 00:00:00'\n", "\n", " \n", " df_data = dbManager.get_data(sn=sn, start_time=st, end_time=et, data_groups=['bms'])\n", " # \n", " df_bms = df_data['bms']\n", "\n", " df_ori = df_bms[columns]\n", " df_ori.rename(columns = {'时间戳':'time'}, inplace=True)\n", " df = df_ori.drop_duplicates(subset=['time']) # 删除时间相同的数据\n", " df = df.reset_index(drop=True)\n", " df_result_1,time_list_1 = sta.cal_voltdiff_uniform(df,volt_column, window=window, step=step, window2=window2, step2=step2)\n", " df_result_2,time_list_2 = sta.cal_volt_uniform(df,volt_column, window=window, step=step)\n", "\n", " df_result_1['time'] = time_list_1\n", " df_result_2['time'] = time_list_2\n", " # second_list = [((pd.to_datetime(x)-pd.to_datetime(time_list[0])).total_seconds()) for x in time_list] # 距离第一个点的分钟数\n", "\n", " # fig = plt.figure(figsize=(20,10))\n", "\n", " # length = len(df_result)\n", " # for column in volt_column:\n", " # # plt.plot([x for x in range(0, length)], df_result[column][0:length], label=column)\n", " # plt.scatter(time_list[:], df_result[column][:length], label=column)\n", "\n", " # plt.legend()\n", " # plt.title('{}电压离群(电压滤波窗口大小:{}, 步进大小:{}'.format(sn, window, step, window2, step2))\n", " # sn = sn.replace('/','_')\n", " # plt.savefig('./结果/新数据/' + sn + '.png')\n", " # plt.close()\n", "\n", " # 报警\n", " # df_result_1['time'] = time_list_1\n", " # alarm_result = sta.alarm(df_result_1, volt_column, alarm_window=20, alarm_ratio=0.9, alarm_threshold=3.5)\n", " # alarm_result['sn'] = [sn] * len(alarm_result)\n", " # alarm_result['suptype'] = ['电压变化量离群'] * len(alarm_result)\n", " # all_result = pd.concat([all_result, alarm_result])\n", "\n", " # df_result_2['time'] = time_list_2\n", " # alarm_result = sta.alarm(df_result_2, volt_column, alarm_window=20, alarm_ratio=0.9, alarm_threshold=3.5)\n", " # alarm_result['sn'] = [sn] * len(alarm_result)\n", " # alarm_result['suptype'] = ['电压离群'] * len(alarm_result)\n", "\n", " # 记录偏差超过3的电芯编号\n", " df_all_result = sta.instorage(sn, df_result_1, df_result_2)\n", " \n", " # all_result = pd.concat([all_result, alarm_result])\n", " # all_result.to_csv('./result_volt.csv')\n", " break" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | 1340 | \n", "单体电压1 | \n", "单体电压10 | \n", "单体电压11 | \n", "单体电压12 | \n", "单体电压13 | \n", "单体电压14 | \n", "单体电压15 | \n", "单体电压16 | \n", "单体电压17 | \n", "... | \n", "单体电压19 | \n", "单体电压2 | \n", "单体电压20 | \n", "单体电压3 | \n", "单体电压4 | \n", "单体电压5 | \n", "单体电压6 | \n", "单体电压7 | \n", "单体电压8 | \n", "单体电压9 | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1340 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
1 rows × 21 columns
\n", "\n", " | 单体电压1 | \n", "单体电压2 | \n", "单体电压3 | \n", "单体电压4 | \n", "单体电压5 | \n", "单体电压6 | \n", "单体电压7 | \n", "单体电压8 | \n", "单体电压9 | \n", "单体电压10 | \n", "单体电压11 | \n", "单体电压12 | \n", "单体电压13 | \n", "单体电压14 | \n", "单体电压15 | \n", "单体电压16 | \n", "单体电压17 | \n", "单体电压18 | \n", "单体电压19 | \n", "单体电压20 | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1340 | \n", "1.0 | \n", "0.0 | \n", "1.0 | \n", "0.0 | \n", "0.0 | \n", "-5.0 | \n", "0.0 | \n", "-3.0 | \n", "1.0 | \n", "3.0 | \n", "1.0 | \n", "2.0 | \n", "-2.0 | \n", "1.0 | \n", "3.0 | \n", "2.0 | \n", "-1.0 | \n", "-1.0 | \n", "-2.0 | \n", "-1.0 | \n", "
\n", " | 单体电压1 | \n", "单体电压2 | \n", "单体电压3 | \n", "单体电压4 | \n", "单体电压5 | \n", "单体电压6 | \n", "单体电压7 | \n", "单体电压8 | \n", "单体电压9 | \n", "单体电压10 | \n", "... | \n", "单体电压12 | \n", "单体电压13 | \n", "单体电压14 | \n", "单体电压15 | \n", "单体电压16 | \n", "单体电压17 | \n", "单体电压18 | \n", "单体电压19 | \n", "单体电压20 | \n", "time | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
134 | \n", "0.702075 | \n", "0.228056 | \n", "0.712609 | \n", "0.038448 | \n", "0.070050 | \n", "-3.090080 | \n", "0.322860 | \n", "-1.194002 | \n", "0.249124 | \n", "0.933818 | \n", "... | \n", "1.218230 | \n", "-1.130800 | \n", "0.712609 | \n", "0.817947 | \n", "0.828481 | \n", "-0.235430 | \n", "-0.351301 | \n", "-0.814787 | \n", "-0.488240 | \n", "2021-10-23 04:15:26 | \n", "
135 | \n", "0.666068 | \n", "0.300821 | \n", "0.737088 | \n", "0.057323 | \n", "0.118198 | \n", "-3.270480 | \n", "0.341404 | \n", "-1.109437 | \n", "0.148635 | \n", "0.767525 | \n", "... | \n", "1.183501 | \n", "-1.058708 | \n", "0.777671 | \n", "0.554465 | \n", "0.879129 | \n", "-0.135446 | \n", "-0.257195 | \n", "-0.703607 | \n", "-0.480401 | \n", "2021-10-23 04:17:06 | \n", "
136 | \n", "0.624390 | \n", "0.292164 | \n", "0.712332 | \n", "0.096736 | \n", "0.174907 | \n", "-3.401409 | \n", "0.380106 | \n", "-1.026970 | \n", "0.047880 | \n", "0.624390 | \n", "... | \n", "1.191128 | \n", "-0.968341 | \n", "0.810045 | \n", "0.321478 | \n", "0.927302 | \n", "-0.108462 | \n", "-0.206176 | \n", "-0.577487 | \n", "-0.430917 | \n", "2021-10-23 04:18:46 | \n", "
137 | \n", "0.584256 | \n", "0.310090 | \n", "0.678795 | \n", "0.111557 | \n", "0.215551 | \n", "-3.480953 | \n", "0.423538 | \n", "-0.956742 | \n", "-0.001891 | \n", "0.489716 | \n", "... | \n", "1.189310 | \n", "-0.909472 | \n", "0.858421 | \n", "0.121011 | \n", "0.943507 | \n", "-0.058615 | \n", "-0.153154 | \n", "-0.493497 | \n", "-0.398958 | \n", "2021-10-23 04:20:25 | \n", "
138 | \n", "0.585815 | \n", "0.321195 | \n", "0.686188 | \n", "0.111323 | \n", "0.229946 | \n", "-3.538615 | \n", "0.448942 | \n", "-0.846786 | \n", "-0.043799 | \n", "0.412443 | \n", "... | \n", "1.142430 | \n", "-0.901535 | \n", "0.859560 | \n", "-0.071174 | \n", "0.987308 | \n", "-0.016425 | \n", "-0.116798 | \n", "-0.399668 | \n", "-0.363169 | \n", "2021-10-23 04:22:06 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
2886 | \n", "-0.028128 | \n", "0.137713 | \n", "0.358835 | \n", "0.648244 | \n", "0.254777 | \n", "-3.110822 | \n", "0.410863 | \n", "-0.037883 | \n", "-0.232991 | \n", "-1.436152 | \n", "... | \n", "0.690517 | \n", "0.726287 | \n", "0.794574 | \n", "-1.810107 | \n", "0.553942 | \n", "0.713279 | \n", "0.719783 | \n", "0.124706 | \n", "0.306806 | \n", "2021-10-30 09:42:21 | \n", "
2887 | \n", "-0.032019 | \n", "0.172903 | \n", "0.337979 | \n", "0.645362 | \n", "0.283903 | \n", "-3.063159 | \n", "0.414825 | \n", "0.070442 | \n", "-0.211326 | \n", "-1.475012 | \n", "... | \n", "0.605516 | \n", "0.727900 | \n", "0.796208 | \n", "-1.899087 | \n", "0.528671 | \n", "0.685208 | \n", "0.725054 | \n", "0.181441 | \n", "0.303825 | \n", "2021-10-30 09:44:01 | \n", "
2888 | \n", "0.011380 | \n", "0.249315 | \n", "0.308799 | \n", "0.598460 | \n", "0.264833 | \n", "-3.040403 | \n", "0.440698 | \n", "0.083795 | \n", "-0.270522 | \n", "-1.460200 | \n", "... | \n", "0.505354 | \n", "0.722600 | \n", "0.779498 | \n", "-1.954175 | \n", "0.546735 | \n", "0.691565 | \n", "0.735531 | \n", "0.182072 | \n", "0.414835 | \n", "2021-10-30 09:45:41 | \n", "
2889 | \n", "0.030937 | \n", "0.264848 | \n", "0.315152 | \n", "0.596851 | \n", "0.244727 | \n", "-3.017456 | \n", "0.453486 | \n", "0.121483 | \n", "-0.353885 | \n", "-1.513381 | \n", "... | \n", "0.503790 | \n", "0.750277 | \n", "0.747762 | \n", "-1.920840 | \n", "0.559124 | \n", "0.699973 | \n", "0.760338 | \n", "0.171786 | \n", "0.405698 | \n", "2021-10-30 09:47:17 | \n", "
2890 | \n", "0.035617 | \n", "0.269594 | \n", "0.287792 | \n", "0.589363 | \n", "0.235797 | \n", "-3.024289 | \n", "0.454176 | \n", "0.103210 | \n", "-0.375144 | \n", "-1.506035 | \n", "... | \n", "0.513971 | \n", "0.781745 | \n", "0.732349 | \n", "-1.898597 | \n", "0.532169 | \n", "0.719351 | \n", "0.784344 | \n", "0.176003 | \n", "0.420380 | \n", "2021-10-30 09:48:59 | \n", "
940 rows × 21 columns
\n", "