-
Notifications
You must be signed in to change notification settings - Fork 1
/
heatmap_data.php
59 lines (54 loc) · 1.7 KB
/
heatmap_data.php
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
<?php
function heatmapdata($timestamps, $activities){
require 'dbconnect.php';
$activities_check="";
$data_array = array();
$activities_check = "AND "."(";
for ($i=0; $i < count($activities) ; $i++) {
$activities_check.= "(".$activities[$i]. " IS NOT NULL) ";
if($i != count($activities) -1) {
$activities_check.="OR ";
}
}
$activities_check.=")";
$where="";
for($i=0; $i<count($timestamps); $i+=2){
$ts1 = $timestamps[$i];
$ts2 = $timestamps[$i+1];
$where.= " (timestampMs BETWEEN ". $ts1. " AND ". $ts2.") ";
if($i<(count($timestamps)-2)){
$where.= "OR";
}
}
$query = "SELECT timestampMs, latitude, longitude from usermapdata WHERE $where";
$result = mysqli_query($conn, $query);
if (!$result) {
return;
}
else {
while ($row = mysqli_fetch_assoc($result)) {
$timestamp = $row["timestampMs"];
unset($row["timestampMs"]); //remove timestamp cause we dont need it for heatmap dataPoints
$row = array_map('intval', $row);
$row["latitude"] = $row["latitude"]/10**7;
$row["longitude"] = $row["longitude"]/10**7;
$query_act = "SELECT count(*) FROM user_activity WHERE (userMapData_timestampMs = $timestamp) $activities_check GROUP BY userMapData_timestampMs";
$result_act = mysqli_query($conn, $query_act);
if (mysqli_num_rows($result_act) == 0) {
}
else {
$counter = mysqli_fetch_assoc($result_act);
if (is_array($counter) || is_object($counter))
{
foreach ($counter as $value) {
$row["count"] = $value + 2;
}
}
array_push($data_array, $row);
}
}
}
$data_points = array('max' => 5, 'data' => $data_array);
return $data_points;
}
?>