{ "cells": [ { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done. Total elapsed time: 0.03s\n", "(14.568, 59.012, 41.106)\n", "(29.481, 60.481, -2.774)\n", "(18.019, 71.888, -5.666)\n", "DONE\n" ] } ], "source": [ "import pandas as pd\n", "import numpy as np\n", "import time\n", "from math import atan, sqrt\n", "\n", "inputData = 'data/jrp/accData-02-27_jrp_test.txt'\n", "outputData = 'data/jrp/jrp_Data_test.txt'\n", "\n", "start = time.time()\n", "columns = ['user','activity','timestamp', 'x-axis', 'y-axis', 'z-axis']\n", "df = pd.read_csv(inputData, header = None, names = columns)\n", "df = df.dropna()\n", "\n", "xList = list(df['x-axis'])\n", "yList = list(df['y-axis'])\n", "zList = list(df['z-axis'])\n", "\n", "#print(xList[0], yList[0], zList[0])\n", "\n", "M_PI = 3.14159265358979323846\n", "for i in range(0,df['x-axis'].size):\n", " tempX = xList[i]* 3.9\n", " tempY = yList[i]* 3.9\n", " tempZ = zList[i]* 3.9\n", " \n", " if((tempY*tempY + tempZ*tempZ) == 0):\n", " pitch = 180 * 1.570796/M_PI\n", " else:\n", " pitch = 180 * atan(tempX/sqrt(tempY*tempY + tempZ*tempZ))/M_PI\n", " \n", " if((tempX*tempX + tempZ*tempZ) == 0):\n", " roll = 180 * 1.570796/M_PI\n", " else:\n", " roll = 180 * atan(tempY/sqrt(tempX*tempX + tempZ*tempZ))/M_PI \n", " \n", " if((tempX*tempX + tempZ*tempZ) == 0):\n", " yaw = 180 * 1.570796/M_PI\n", " else:\n", " yaw = 180 * atan(tempZ/sqrt(tempX*tempX + tempZ*tempZ))/M_PI\n", "\n", " xList[i] = round(pitch, 3)\n", " yList[i] = round(roll, 3)\n", " zList[i] = round(yaw, 3)\n", " \n", " if (i % 1000 == 0):\n", " end = time.time()\n", " #print(\"%.2f%% Done. Elapsed time: %.2fs\" % (i*100/df['x-axis'].size, end - start))\n", " \n", "end = time.time() \n", "print(\"Done. Total elapsed time: %.2fs\" % (end - start))\n", "print(xList[0], yList[0], zList[0])\n", "print(xList[1], yList[1], zList[1])\n", "print(xList[2], yList[2], zList[2])\n", "\n", "x_vector = np.asarray(xList)\n", "x_vector.T\n", "\n", "y_vector = np.asarray(yList)\n", "y_vector.T\n", "\n", "z_vector = np.asarray(zList)\n", "z_vector.T\n", "\n", "\n", "df['x-axis'] = x_vector\n", "df['y-axis'] = y_vector\n", "df['z-axis'] = z_vector\n", "\n", "\n", "df.to_csv(outputData, header=False, index=False) \n", "#print(df)\n", "print(\"DONE\")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }