{ "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": [ "
\n", " | 创建时间 | \n", "在线 | \n", "驱动已打开 | \n", "操作模式 | \n", "当前程序号 | \n", "当前程序步 | \n", "TCP位姿 | \n", "焊接电流 | \n", "驱动打开时间 | \n", "停止采集日期 | \n", "... | \n", "焊接状态.1 | \n", "保护气流量 | \n", "焊接速度 | \n", "0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "5 | \n", "createTime | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "2022/8/1 8:08:38 | \n", "True | \n", "True | \n", "1.0 | \n", "NaN | \n", "0.0.0 | \n", "[-3.101456, -622.703380, -527.500837, -0.50521... | \n", "329.0 | \n", "42806478193644 | \n", "2022-8-2 0:47:18.003 | \n", "... | \n", "False | \n", "0.029388 | \n", "0.0 | \n", "-3.101456 | \n", "-622.703380 | \n", "-527.500837 | \n", "-0.505214 | \n", "108.646219 | \n", "-4.107130 | \n", "1.659313e+09 | \n", "
1 | \n", "2022/8/1 8:08:39 | \n", "True | \n", "True | \n", "1.0 | \n", "NaN | \n", "0.0.0 | \n", "[-3.101456, -622.703380, -527.500837, -0.50521... | \n", "329.0 | \n", "42806478193644 | \n", "2022-8-2 0:47:18.003 | \n", "... | \n", "False | \n", "0.029388 | \n", "0.0 | \n", "-3.101456 | \n", "-622.703380 | \n", "-527.500837 | \n", "-0.505214 | \n", "108.646219 | \n", "-4.107130 | \n", "1.659313e+09 | \n", "
2 | \n", "2022/8/1 8:08:40 | \n", "True | \n", "True | \n", "1.0 | \n", "NaN | \n", "0.0.0 | \n", "[-3.101456, -622.703380, -527.500837, -0.50521... | \n", "329.0 | \n", "42806478193644 | \n", "2022-8-2 0:47:18.003 | \n", "... | \n", "False | \n", "0.029388 | \n", "0.0 | \n", "-3.101456 | \n", "-622.703380 | \n", "-527.500837 | \n", "-0.505214 | \n", "108.646219 | \n", "-4.107130 | \n", "1.659313e+09 | \n", "
3 | \n", "2022/8/1 8:08:41 | \n", "True | \n", "True | \n", "1.0 | \n", "NaN | \n", "0.0.0 | \n", "[-3.101456, -622.703380, -527.500837, -0.50521... | \n", "329.0 | \n", "42806478193644 | \n", "2022-8-2 0:47:18.003 | \n", "... | \n", "False | \n", "0.029388 | \n", "0.0 | \n", "-3.101456 | \n", "-622.703380 | \n", "-527.500837 | \n", "-0.505214 | \n", "108.646219 | \n", "-4.107130 | \n", "1.659313e+09 | \n", "
4 | \n", "2022/8/1 8:08:42 | \n", "True | \n", "True | \n", "1.0 | \n", "NaN | \n", "0.0.0 | \n", "[-3.101456, -622.703380, -527.500837, -0.50521... | \n", "329.0 | \n", "42806478193644 | \n", "2022-8-2 0:47:18.003 | \n", "... | \n", "False | \n", "0.029388 | \n", "0.0 | \n", "-3.101456 | \n", "-622.703380 | \n", "-527.500837 | \n", "-0.505214 | \n", "108.646219 | \n", "-4.107130 | \n", "1.659313e+09 | \n", "
5 rows × 37 columns
\n", "