-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfindings.php
More file actions
179 lines (163 loc) · 5.32 KB
/
findings.php
File metadata and controls
179 lines (163 loc) · 5.32 KB
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
<?php
/**
* Created by PhpStorm.
* User: waicung
* Date: 02/06/2016
* Time: 15:07
*/
require_once __DIR__ . '/db_config.php';
require_once __DIR__ . '/myfunctions.php';
$conn=mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
$response = array();
$search_query = "SELECT l.location_id,l.record_id,latitude,longitude,time_stamp,a.route_id
FROM locations AS l
LEFT JOIN recordings AS r
ON l.record_id = r.record_id
LEFT JOIN route_assignments AS a
ON r.assignment_id=a.assignment_id
WHERE l.record_id>15
AND latitude<>0
ORDER BY route_id,record_id, time_stamp";
$result = mysqli_query($conn,$search_query);
$route = "";
$tag = ""; // mark the current record_id
$locaions = array();
$point = array();
$record = array();
$speedResponse = array();
$speeds = array();
while($row = mysqli_fetch_assoc($result)){
if($tag=="" || $tag<>$row['record_id']){
if($tag==""){}
else{
$record['route_id'] = $route;
$record['id'] = $tag;
$record['locations'] = $locations;
array_push($response,$record);
$speeds['route_id'] = $route;
$speeds['record_id'] = $tag;
$speeds['speed'] = array();
array_push($speeds['speed'],initialSpeedComputation($locations));
array_push($speedResponse,$speeds);
}
$route = intval($row['route_id']);
$tag = $row['record_id'];
$locations = array();
}
if($tag == $row['record_id']){
$point = array();
$point['lat'] = doubleval($row['latitude']);
$point['lng'] = doubleval($row['longitude']);
$point['location_id'] = intval($row['location_id']);
$point['time_stamp'] = $row['time_stamp'];
array_push($locations,$point);
}
}
$record['route_id'] = $route;
$record['id'] = $tag;
$record['locations'] = $locations;
array_push($response,$record);
$speeds['route_id'] = $route;
$speeds['record_id'] = $tag;
$speeds['speed'] = array();
array_push($speeds['speed'],initialSpeedComputation($locations));
array_push($speedResponse,$speeds);
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Walking Path</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="/chartistjs/dist/chartist.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="/chartistjs/dist/chartist.min.js"></script>
<script src="https://npmcdn.com/simple-statistics@2.0.0/dist/simple-statistics.min.js"></script>
<style>
.ct-chart{height: auto;
}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Wayfinding</a>
</div>
<ul class="nav navbar-nav">
<li><a href="/index.php">Home</a></li>
<li><a href="/planer.php">Route Planer</a></li>
<li><a href="/visualstep.php">Routes</a></li>
<li><a href="/visualisation.php">Locations</a></li>
<li class="active"><a href="/findings.php">Findings</a></li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="row">
<div class="col-sm-12" id="chart-container">
</div>
</div>
<script src="/findings.js"></script>
<script>
var records = <?php echo json_encode($response);?>;
var speeds = <?php echo json_encode($speedResponse);?>;
var routeList = []; // number of routes
var currentRoute = records[0].route_id;
routeList.push(currentRoute);
for(var i = 1;i<records.length; i++){
if(currentRoute != records[i].route_id){
currentRoute = records[i].route_id;
routeList.push(currentRoute);
}
}
for(var i=0;i<routeList.length;i++){
var speedLists = [];
var currentRoute = routeList[i];
for(var j = 0;j<speeds.length;j++){
if(currentRoute == speeds[j].route_id){
var currentTest = speeds[j].record_id;
var eachList = [];
eachList.push(getSpeeds(speeds[j].speed[0]));
addSpeedChart("Route"+currentRoute+"Record"+currentTest, eachList);
speedLists.push(getSpeeds(speeds[j].speed[0]));
}
}
addSpeedChart("Route"+currentRoute, speedLists);
}
function addSpeedChart(title,speedLists){
addCol(title);
speedChart(title,speedLists);
}
function getSpeeds(speedList){
var output = [];
for(var i=0;i<speedList.length;i++){
output.push(speedList[i].speed);
}
return output;
}
function addCol(title){
$("#chart-container").append(
"<div class='ct-chart .ct-minor-sixth' id="+title+">" +
"<div class='floating-title'>"+title+"</div></div>");
}
function averageSpeed(speeds){
var output = 0;
var lowQuantile = quantile(speeds, 0.25);
var highQuantile = quantile(speeds, 0.75);
for(var i=0; i<speeds.length;i++){
if(speeds[i]<=lowQuantile || speeds[i]>=highQuantile){
speeds.splice(i, 1);
}
}
output = mean(speeds);
return output;
}
</script>
</div>
</div>
</body>
</html>