JawRollPitch.ipynb 3.31 KB
Newer Older
Oskars Linde's avatar
Oskars Linde committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
 "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",
112
    "version": 3
Oskars Linde's avatar
Oskars Linde committed
113
114
115
116
117
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
118
119
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
Oskars Linde's avatar
Oskars Linde committed
120
121
122
123
124
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}