You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

629 lines
18 KiB
Plaintext

2 years ago
{
"cells": [
{
"cell_type": "markdown",
"id": "bbe6ec77",
"metadata": {},
"source": [
"处理原始数据origin.csv"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "e77e804a",
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-07T16:58:08.770045Z",
"iopub.status.busy": "2022-12-07T16:58:08.769489Z",
"iopub.status.idle": "2022-12-07T16:58:08.826735Z",
"shell.execute_reply": "2022-12-07T16:58:08.825976Z"
},
"origin_pos": 1,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"import hashlib\n",
"import os\n",
"import tarfile\n",
"import zipfile\n",
"import requests\n",
"import math\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "5f97aaa0",
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-07T16:58:08.849212Z",
"iopub.status.busy": "2022-12-07T16:58:08.848803Z",
"iopub.status.idle": "2022-12-07T16:58:11.308665Z",
"shell.execute_reply": "2022-12-07T16:58:11.307847Z"
},
"origin_pos": 8,
"tab": [
"pytorch"
]
},
"outputs": [],
"source": [
"\n",
"%matplotlib inline\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"将位姿数据拆分为6个属性"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ebe45f59",
"metadata": {},
"outputs": [],
"source": [
"data = pd.read_csv(\"origin.csv\")\n",
"data[\"TCP位姿\"] = data[\"TCP位姿\"].str.strip(\"[]\").str.split(\",\") \n",
"# 使用apply(pd.Series)方法将列表展开为多列并合并到原来的DataFrame对象中 \n",
"data = data.join(data[\"TCP位姿\"].apply(pd.Series)) "
]
},
{
"cell_type": "markdown",
"id": "6100a284",
"metadata": {},
"source": [
"将时间转化为时间戳"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7bb4fbce",
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime\n",
" \n",
"def toNum(x):\n",
" datetime_object = datetime.strptime(x, '%Y/%m/%d %H:%M:%S')\n",
" return datetime_object.timestamp()\n",
" # return x.replace(\":\",\"\").replace(\"/\",\"\").replace(\" \",\"\")\n",
"data[\"createTime\"]=data[\"创建时间\"].map(toNum)"
]
},
{
"cell_type": "markdown",
"id": "5edec8a4",
"metadata": {},
"source": [
"提取有用的属性"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "08d63378",
"metadata": {},
"outputs": [],
"source": [
"data1=data[[\"createTime\",0,1,2,3,4,5,\"焊接速度\",\"焊接电压\",\"焊接电流\"]]\n",
"data1.head()\n",
"data1.to_csv(\"pos_time_cvv.csv\",index=False)"
]
},
{
"cell_type": "markdown",
"id": "574f3b97",
"metadata": {},
"source": [
"删除冗余和异常数据"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "fe01601c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(790966, 10)\n",
"(185143, 10)\n"
]
}
],
"source": [
"data=pd.read_csv(\"pos_time_cvv.csv\")\n",
"print(data.shape)\n",
"# data=data.drop_duplicates([\"0\",\"1\",\"2\",\"焊接电流\",\"焊接电压\"],keep='first')\n",
"toDeleteList=[]\n",
"x=data[\"1\"]\n",
"y=data[\"2\"]\n",
"z=data[\"3\"]\n",
"v=data[\"焊接电压\"]\n",
"c=data[\"焊接电流\"]\n",
"time=data[\"createTime\"]\n",
"x1=[]\n",
"y1=[]\n",
"z1=[]\n",
"v1=[]\n",
"c1=[]\n",
"t1=[]\n",
"count=0\n",
"lastTime=time[0]\n",
"lastV=0\n",
"lastC=0\n",
"lastX=0\n",
"lastY=0\n",
"lastZ=0\n",
"thisTime=0\n",
"colors=['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']\n",
"colorCnt=0\n",
"for tup in zip(x,y,z,time,v,c):\n",
" # print(tup,type(tup[1:]))\n",
"\n",
" thisTime=tup[3]\n",
" if (tup[4]==lastV and tup[5]==lastC)or\\\n",
" (lastX==tup[0] and lastY==tup[1] and lastZ==tup[2])or tup[5]==400 or\\\n",
" abs(lastC-tup[5])>30:\n",
" # print(count)\n",
" colorCnt+=1\n",
" toDeleteList.append(count)\n",
" \n",
" \n",
" \n",
" # print(len(x1))\n",
" \n",
" x1=[]\n",
" y1=[]\n",
" z1=[]\n",
" v1=[]\n",
" c1=[]\n",
" t1=[]\n",
" count+=1 \n",
" lastV=tup[4]\n",
" lastC=tup[5]\n",
" lastX=tup[0]\n",
" lastY=tup[1]\n",
" lastZ=tup[2]\n",
" lastTime=thisTime\n",
"data=data.drop(toDeleteList)\n",
"print(data.values.shape)\n",
"data.to_csv(\"delete_same_and_sharp.csv\",index=False)"
]
},
{
"cell_type": "markdown",
"id": "92aba770",
"metadata": {},
"source": [
"提取line(因为轨迹是一条条的线所以可以把轨迹投影到xoy平面)"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "b02274bc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(183427, 10)\n",
"(1320, 10)\n"
]
}
],
"source": [
"\n",
"# data=data.drop_duplicates([\"0\",\"1\",\"2\",\"焊接电流\",\"焊接电压\"],keep='first')\n",
"def dis(x1,y1,x2,y2):\n",
" return math.sqrt((x1-x2)**2+(y1-y2)**2)\n",
"data=pd.read_csv(\"delete_same_and_sharp3.csv\")\n",
"x=data[\"1\"]\n",
"y=data[\"2\"]\n",
"z=data[\"3\"]\n",
"v=data[\"焊接电压\"]\n",
"c=data[\"焊接电流\"]\n",
"time=data[\"createTime\"]\n",
"toDeleteList=[]\n",
"x1=[]\n",
"y1=[]\n",
"z1=[]\n",
"v1=[]\n",
"c1=[]\n",
"t1=[]\n",
"count=0\n",
"lastTime=0\n",
"lastV=0\n",
"lastC=0\n",
"lastX=0\n",
"lastY=0\n",
"lastZ=0\n",
"thisTime=0\n",
"colors=['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']\n",
"colorCnt=0\n",
"for tup in zip(x,y,z,time,v,c):\n",
" # print(tup,type(tup[1:]))\n",
"\n",
" thisTime=tup[3]\n",
" if dis(lastY,lastZ,tup[1],tup[2])<1:\n",
" # print(count)\n",
" colorCnt+=1\n",
" toDeleteList.append(count)\n",
" \n",
" \n",
" \n",
" # print(len(x1))\n",
"\n",
" x1=[]\n",
" y1=[]\n",
" z1=[]\n",
" v1=[]\n",
" c1=[]\n",
" t1=[]\n",
" count+=1 \n",
" lastV=tup[4]\n",
" lastC=tup[5]\n",
" lastX=tup[0]\n",
" lastY=tup[1]\n",
" lastZ=tup[2]\n",
" lastTime=thisTime\n",
"# print(toDeleteList)\n",
"print(data.shape)\n",
"data=data.drop(toDeleteList)\n",
"# print(data['createTime'])\n",
"\n",
"data.to_csv(\"line.csv\",index=False)\n",
"\n",
"print(data.shape)\n",
"# data.to_csv(\"delete_same_and_sharp7.csv\",index=False)"
]
},
{
"cell_type": "markdown",
"id": "b937fa76",
"metadata": {},
"source": [
"合并相近的line离得太近的合并到一起减少点的数量"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "37a9a5b7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1320, 10)\n",
"(872, 10)\n"
]
}
],
"source": [
"def dis(x1,y1,x2,y2):\n",
" return math.sqrt((x1-x2)**2+(y1-y2)**2)\n",
"data=pd.read_csv(\"line.csv\")\n",
"x=data[\"1\"]\n",
"y=data[\"2\"]\n",
"z=data[\"3\"]\n",
"v=data[\"焊接电压\"]\n",
"c=data[\"焊接电流\"]\n",
"time=data[\"createTime\"]\n",
"toDeleteList=[]\n",
"x1=[]\n",
"y1=[]\n",
"z1=[]\n",
"v1=[]\n",
"c1=[]\n",
"t1=[]\n",
"count=0\n",
"lastTime=0\n",
"lastV=0\n",
"lastC=0\n",
"lastX=0\n",
"lastY=0\n",
"lastZ=0\n",
"thisTime=0\n",
"colors=['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']\n",
"colorCnt=0\n",
"for tup in zip(x,y,z,time,v,c):\n",
" # print(tup,type(tup[1:]))\n",
"\n",
" thisTime=tup[3]\n",
" if abs(lastTime-tup[3])<100:\n",
" # print(count)\n",
" colorCnt+=1\n",
" toDeleteList.append(count)\n",
" \n",
" \n",
" \n",
" # print(len(x1))\n",
"\n",
" x1=[]\n",
" y1=[]\n",
" z1=[]\n",
" v1=[]\n",
" c1=[]\n",
" t1=[]\n",
" count+=1 \n",
" lastV=tup[4]\n",
" lastC=tup[5]\n",
" lastX=tup[0]\n",
" lastY=tup[1]\n",
" lastZ=tup[2]\n",
" lastTime=thisTime\n",
"# print(toDeleteList)\n",
"print(data.shape)\n",
"data=data.drop(toDeleteList)\n",
"# print(data['createTime'])\n",
"\n",
"data.to_csv(\"line0.csv\",index=False)\n",
"\n",
"print(data.shape)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "96afb190",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>创建时间</th>\n",
" <th>在线</th>\n",
" <th>驱动已打开</th>\n",
" <th>操作模式</th>\n",
" <th>当前程序号</th>\n",
" <th>当前程序步</th>\n",
" <th>TCP位姿</th>\n",
" <th>焊接电流</th>\n",
" <th>驱动打开时间</th>\n",
" <th>停止采集日期</th>\n",
" <th>...</th>\n",
" <th>焊接状态.1</th>\n",
" <th>保护气流量</th>\n",
" <th>焊接速度</th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" <th>4</th>\n",
" <th>5</th>\n",
" <th>createTime</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2022/8/1 8:08:38</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>1.0</td>\n",
" <td>NaN</td>\n",
" <td>0.0.0</td>\n",
" <td>[-3.101456, -622.703380, -527.500837, -0.50521...</td>\n",
" <td>329.0</td>\n",
" <td>42806478193644</td>\n",
" <td>2022-8-2 0:47:18.003</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>0.029388</td>\n",
" <td>0.0</td>\n",
" <td>-3.101456</td>\n",
" <td>-622.703380</td>\n",
" <td>-527.500837</td>\n",
" <td>-0.505214</td>\n",
" <td>108.646219</td>\n",
" <td>-4.107130</td>\n",
" <td>1.659313e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2022/8/1 8:08:39</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>1.0</td>\n",
" <td>NaN</td>\n",
" <td>0.0.0</td>\n",
" <td>[-3.101456, -622.703380, -527.500837, -0.50521...</td>\n",
" <td>329.0</td>\n",
" <td>42806478193644</td>\n",
" <td>2022-8-2 0:47:18.003</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>0.029388</td>\n",
" <td>0.0</td>\n",
" <td>-3.101456</td>\n",
" <td>-622.703380</td>\n",
" <td>-527.500837</td>\n",
" <td>-0.505214</td>\n",
" <td>108.646219</td>\n",
" <td>-4.107130</td>\n",
" <td>1.659313e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2022/8/1 8:08:40</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>1.0</td>\n",
" <td>NaN</td>\n",
" <td>0.0.0</td>\n",
" <td>[-3.101456, -622.703380, -527.500837, -0.50521...</td>\n",
" <td>329.0</td>\n",
" <td>42806478193644</td>\n",
" <td>2022-8-2 0:47:18.003</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>0.029388</td>\n",
" <td>0.0</td>\n",
" <td>-3.101456</td>\n",
" <td>-622.703380</td>\n",
" <td>-527.500837</td>\n",
" <td>-0.505214</td>\n",
" <td>108.646219</td>\n",
" <td>-4.107130</td>\n",
" <td>1.659313e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2022/8/1 8:08:41</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>1.0</td>\n",
" <td>NaN</td>\n",
" <td>0.0.0</td>\n",
" <td>[-3.101456, -622.703380, -527.500837, -0.50521...</td>\n",
" <td>329.0</td>\n",
" <td>42806478193644</td>\n",
" <td>2022-8-2 0:47:18.003</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>0.029388</td>\n",
" <td>0.0</td>\n",
" <td>-3.101456</td>\n",
" <td>-622.703380</td>\n",
" <td>-527.500837</td>\n",
" <td>-0.505214</td>\n",
" <td>108.646219</td>\n",
" <td>-4.107130</td>\n",
" <td>1.659313e+09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2022/8/1 8:08:42</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>1.0</td>\n",
" <td>NaN</td>\n",
" <td>0.0.0</td>\n",
" <td>[-3.101456, -622.703380, -527.500837, -0.50521...</td>\n",
" <td>329.0</td>\n",
" <td>42806478193644</td>\n",
" <td>2022-8-2 0:47:18.003</td>\n",
" <td>...</td>\n",
" <td>False</td>\n",
" <td>0.029388</td>\n",
" <td>0.0</td>\n",
" <td>-3.101456</td>\n",
" <td>-622.703380</td>\n",
" <td>-527.500837</td>\n",
" <td>-0.505214</td>\n",
" <td>108.646219</td>\n",
" <td>-4.107130</td>\n",
" <td>1.659313e+09</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 37 columns</p>\n",
"</div>"
],
"text/plain": [
" 创建时间 在线 驱动已打开 操作模式 当前程序号 当前程序步 \\\n",
"0 2022/8/1 8:08:38 True True 1.0 NaN 0.0.0 \n",
"1 2022/8/1 8:08:39 True True 1.0 NaN 0.0.0 \n",
"2 2022/8/1 8:08:40 True True 1.0 NaN 0.0.0 \n",
"3 2022/8/1 8:08:41 True True 1.0 NaN 0.0.0 \n",
"4 2022/8/1 8:08:42 True True 1.0 NaN 0.0.0 \n",
"\n",
" TCP位姿 焊接电流 驱动打开时间 \\\n",
"0 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n",
"1 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n",
"2 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n",
"3 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n",
"4 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n",
"\n",
" 停止采集日期 ... 焊接状态.1 保护气流量 焊接速度 0 1 \\\n",
"0 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n",
"1 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n",
"2 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n",
"3 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n",
"4 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n",
"\n",
" 2 3 4 5 createTime \n",
"0 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n",
"1 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n",
"2 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n",
"3 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n",
"4 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n",
"\n",
"[5 rows x 37 columns]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# print(data.iloc[[0,1,2], :])\n",
"data.head()\n",
"# data.to_csv(\"origin_TimePos.csv\",index=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.16 ('torch_py3.9')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"vscode": {
"interpreter": {
"hash": "2c93e8e09754cf1cd40b55c7c8fefeaff6ac58d6a85dd394fdad2eae466f5690"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}