-
Notifications
You must be signed in to change notification settings - Fork 8
/
index_input_label.html
271 lines (237 loc) · 11.3 KB
/
index_input_label.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">body{font-family:sans-serif}.main{border:1px solid #000;box-shadow:10px 10px 5px #888;border-radius:12px;padding:20px;background-color:#ddd;margin:25px;width:450px;margin-left:auto;margin-right:auto}.logo{margin-left:auto;margin-right:auto;display:block;padding:15px}.container{-webkit-perspective:300;perspective:300}</style>
</head>
<body bgcolor="#000000"><noscript><meta HTTP-EQUIV="refresh" content="0;url='http://www.html5rocks.com/en/tutorials/device/orientation/deviceorientationsample.html?ModPagespeed=noscript'" /><style><!--table,div,span,font,p{display:none} --></style><div style="display:block">Please click <a href="http://www.html5rocks.com/en/tutorials/device/orientation/deviceorientationsample.html?ModPagespeed=noscript">here</a> if you are not redirected within a few seconds.</div></noscript>
<div id="algorithms_io_result">xxxxxxxxx</div>
<div id="event_save_output"></div>
<div id="query_get_data_by_range"></div>
<div id="statistic_eps_stat_device"></div>
<div id="statistic_get_rolling_avg_and_std"></div>
<div class="main">
<h2>Label The Action</h2>
<input type="text" id="input_label"/>
<h2>Device Orientation</h2>
<table>
<tr><td>Unique Device ID</td><td id="doDeviceID"></td></td></tr>
<tr><td>Device Information:</td><td id="doDeviceInfo"></td></td></tr>
<tr>
<td>Event Supported</td>
<td id="doEvent"></td>
</tr>
<tr>
<td>Tilt Left/Right [gamma]</td>
<td id="doTiltLR"></td>
</tr>
<tr>
<td>Tilt Front/Back [beta]</td>
<td id="doTiltFB"></td>
</tr>
<tr>
<td>Direction [alpha]</td>
<td id="doDirection"></td>
</tr>
<tr><td>Latitude</td>
<td id="doLat"></td>
</tr>
<tr><td>Longitude</td><td id="doLong"></td></tr>
<tr><td>GeoAccuracy</td><td id="doGeoAccuracy"></td></tr>
<tr><td>Altitude</td><td id="doAlt"></td></tr>
<tr><td>AltitudeAccuracy</td><td id="doAltAccuracy"></td></tr>
<tr><td>Heading</td><td id="doHeading"></td></tr>
<tr><td>Speed</td><td id="doSpeed"></td></tr>
<tr><td>GeoTimestamp</td><td id="doGeoTimestamp"></td></tr>
<tr><td>SocketServerResponse</td><td id="socketResponse">xxxxxxxx</td></tr>
</table>
<h2>Device Motion</h2>
<table>
<tr>
<td>Event Supported</td>
<td id="dmEvent"></td>
</tr>
<tr>
<td>acceleration</td>
<td id="moAccel"></td>
</tr>
<tr>
<td>accelerationIncludingGravity</td>
<td id="moAccelGrav"></td>
</tr>
<tr>
<td>rotationRate</td>
<td id="moRotation"></td>
</tr>
<tr>
<td>interval</td>
<td id="moInterval"></td>
</tr>
</table>
</div>
<div class="container" style="-webkit-perspective: 300; perspective: 300;">
<img src="http://www.algorithms.io//wp-content/uploads/2013/05/Algorithms-dark-Bkgd.png" id="imgLogo" class="logo" width="400" height="110">
</div>
<script src="http://ws.algorithms.io:8082/socket.io/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script type="text/javascript">
var count=0;
var socket;
var alpha, beta, gamma;
var accelx, accely, accelz;
// init();
// function init(){
document.getElementById("doDeviceInfo").innerHTML=navigator.userAgent + navigator.platform;
if(window.DeviceOrientationEvent){
document.getElementById("doEvent").innerHTML="DeviceOrientation";
window.addEventListener('deviceorientation',function(eventData){
var tiltLR=eventData.gamma;
var tiltFB=eventData.beta;
if(eventData.webkitCompassHeading) {
document.getElementById("doHeading").innerHTML=eventData.webkitCompassHeading + window.orientation;
}
var dir=eventData.alpha
deviceOrientationHandler(tiltLR,tiltFB,dir);
},false);
} else {
document.getElementById("doEvent").innerHTML="Not supported on your device or browser. Sorry."
}
if ((window.DeviceMotionEvent) || ('listenForDeviceMovement' in window)) {
window.addEventListener('devicemotion', deviceMotionHandler, false);
}
else {
document.getElementById("dmEvent").innerHTML = "Not supported on your device or browser. Sorry."
}
getLocation();
socket = io.connect('http://ws.algorithms.io:8082');
socket.on('news', function (data) {
console.log(data);
// document.getElementById("socketResponse").innerHTML=data;
//socket.emit('my other event', { my: 'data' });
});
socket.on('algorithms_io_api', function(data) {
// $('#algorithms_io_result').text('Random Forest Result: ' + data.data + "........");
document.getElementById("socketResponse").innerHTML(data.data + ".......");
});
window.setInterval(function(){
//alert( $('#input_label').val() );
socket.emit('event_save', {
'authToken': '02cfc86d9992e822510318adebccb4d3',
'data': '{"Accelerometer.X":' + accelx + ',"Accelerometer.Y":' + accely + ',"Accelerometer.Z":' + accelz +
',"Gyroscope.X":' + alpha.toFixed(1) + ',"Gyroscope.Y":' + beta.toFixed(1) + ',"Gyroscope.Z":' + gamma.toFixed(1) + '}', //'{"Accelerometer.X":-5.6,"Accelerometer.Y":-2.5,"Accelerometer.Z":3.7,"Gyroscope.X":-84.2,"Gyroscope.Y":-132.2,"Gyroscope.Z":-80}',
'device_id': 'android_1',
'label': $('#input_label').val()
});
}, 1000);
// }
function deviceOrientationHandler(tiltLR,tiltFB,dir){
document.getElementById("doTiltLR").innerHTML=Math.round(tiltLR);
document.getElementById("doTiltFB").innerHTML=Math.round(tiltFB);
document.getElementById("doDirection").innerHTML=Math.round(dir);
alpha = dir;
beta = tiltLR;
gamma = tiltFB;
var logo=document.getElementById("imgLogo");
logo.style.webkitTransform="rotate("+tiltLR+"deg) rotate3d(1,0,0, "+(tiltFB*-1)+"deg)";
logo.style.MozTransform="rotate("+tiltLR+"deg)";
logo.style.transform="rotate("+tiltLR+"deg) rotate3d(1,0,0, "+(tiltFB*-1)+"deg)";
// socket.emit('algorithm_random_forest', { 'algorithmPath': '/jobs/swagger/54',
// 'authToken': '02cfc86d9992e822510318adebccb4d3',
// 'method': 'sync',
// 'outputType': 'json',
// 'train': '3843',
// 'test': '{"Gyroscope.X":' + tiltLR.toFixed(1) + ',"Gyroscope.Y":' + tiltFB.toFixed(1) + ',"Gyroscope.Z":' + dir.toFixed(1) + '}',
// 'dependentVariable': 'action'
/*
document.getElementById("socketResponse").text(".......");
socket.emit('algorithm_random_forest', { 'algorithmPath': '/jobs/swagger/54',
'authToken': '02cfc86d9992e822510318adebccb4d3',
'method': 'sync',
'outputType': 'json',
'train': '3843',
'test': '{"Accelerometer.X":-5.6,"Accelerometer.Y":-2.5,"Accelerometer.Z":3.7,"Gyroscope.X":-84.2,"Gyroscope.Y":-132.2,"Gyroscope.Z":-80}',
'dependentVariable': 'action'
});
*/
//alert('goooo');
// socket.on('algorithms_io_api', function (data) {
//// $('#algorithms_io_result').text('Random Forest Result: ' + data.data);
// document.getElementById("socketResponse").text(data.data);
// });
// document.getElementById("doLat").innerHTML = "Sent message at " + (new Date()).getTime();
}
function deviceMotionHandler(eventData) {
var info, xyz = "[X, Y, Z]";
// Grab the acceleration from the results
var acceleration = eventData.acceleration;
info = xyz.replace("X", acceleration.x);
info = info.replace("Y", acceleration.y);
info = info.replace("Z", acceleration.z);
document.getElementById("moAccel").innerHTML = info;
// Grab the acceleration including gravity from the results
acceleration = eventData.accelerationIncludingGravity;
info = xyz.replace("X", acceleration.x);
info = info.replace("Y", acceleration.y);
info = info.replace("Z", acceleration.z);
document.getElementById("moAccelGrav").innerHTML = info;
// Grab the rotation rate from the results
var rotation = eventData.rotationRate;
info = xyz.replace("X", rotation.alpha);
info = info.replace("Y", rotation.beta);
info = info.replace("Z", rotation.gamma);
document.getElementById("moRotation").innerHTML = info;
// // Grab the refresh interval from the results
info = eventData.interval;
document.getElementById("moInterval").innerHTML = info;
accelx = acceleration.x;
accely = acceleration.y;
accelz = acceleration.z;
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else{
console.log("Geolocation is not supported by this browser.");}
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
console.log("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
console.log("Location information is unavailable.");
break;
case error.TIMEOUT:
console.log("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
console.log("An unknown error occurred.");
break;
}
}
function showPosition(position) {
document.getElementById("doLat").innerHTML=Math.round(position.coords.latitude);
document.getElementById("doLong").innerHTML=Math.round(position.coords.longitude);
document.getElementById("doGeoAccuracy").innerHTML=Math.round(position.coords.accuracy);
document.getElementById("doAlt").innerHTML=Math.round(position.coords.altitude);
document.getElementById("doAltAccuracy").innerHTML=Math.round(position.coords.altitudeAccuracy);
document.getElementById("doHeading").innerHTML=position.coords.heading;
document.getElementById("doSpeed").innerHTML=position.coords.speed;
document.getElementById("doGeoTimestamp").innerHTML=new Date(position.timestamp);
}
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
};
function guid() {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
var uuid = guid();
document.getElementById("doDeviceID").innerHTML=uuid;
console.log(uuid);
</script>
</body>
</html>