-
Notifications
You must be signed in to change notification settings - Fork 1
/
adminDataAnalysis.php
157 lines (143 loc) · 4.89 KB
/
adminDataAnalysis.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
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
<?php
if ($_POST['submit'] || $_POST['exp_submit']) { //submit button
$erroryear = false;
$errormonth = false;
$errorday = false;
$errorhour = false;
$erroractivity = false;
require 'dbconnect.php';
if($_POST['select_allyears']=='true') { //all years selected
$startYear = "2000";
$endYear = "2020";
}else {
$startYear = $_POST['startyear'];
$endYear = $_POST['endyear'];
if ($startYear > $endYear) {
$erroryear = true;
}
}
if($_POST['select_allmonths']=='true') {
$startmonth = "01";
$endmonth = "12";
}else {
$startmonth = $_POST['startmonth'];
$endmonth = $_POST['endmonth'];
}
if($_POST['select_alldays']=='true') {
$startday = "0";
$endday = "6";
}else {
$startday = $_POST['startday'];
$endday = $_POST['endday'];
}
if($_POST['select_allhours']=='true') {
$starthour = "00";
$endhour = "23";
}else {
$starthour = $_POST['starthour'];
$endhour = $_POST['endhour'];
if ($starthour > $endhour) {
$errorhour = true;
}
}
$sql = "describe user_activity";
$activity = mysqli_query($conn,$sql);
if(!$activity){
$erroractivity = true;
}
$actarray = array();
$k=0;
while($row = mysqli_fetch_assoc($activity)){
if($row['Field'] != 'userMapData_userId' && $row['Field'] != 'userMapData_timestampMs' && $row['Field'] != 'activity_timestamp' && $row['Field'] != 'eco'){
array_push($actarray, $row['Field']);
$k++;
}
}
//actarray εχει τις δραστηριότητες που επέλεξε ο χρήστης
$actarray_test= $_POST['activarray'];
$activities = array();
if($_POST['select_all_activities']=='true') { //all activities selected
for ($i=0; $i < count($actarray) ; $i++) {
array_push($activities,$actarray[$i]);
}
}
else {
for ($i = 0; $i < count($actarray); $i++) {
if (strpos($actarray_test, $actarray[$i]) !== false) { //ελεγχω αν το activity ειναι μεσα στο string
array_push($activities,$actarray[$i]);
}
}
}
$timestamps = array();
$counter=0;
if($endmonth>=$startmonth){
$months=$endmonth-$startmonth;
}
elseif($endmonth<$startmonth){
$months= 12+$endmonth;
}
if($endday>=$startday){
$days=$endday-$startday;
}
elseif($endday<$startday){
$days=7+$endday;
}
for($currentYear=$startYear;$currentYear<=$endYear;$currentYear++){
for($forMonth=$startmonth;$forMonth<=$startmonth+$months;$forMonth++){
$currentMonth=date('F', mktime(0, 0, 0, ($forMonth-1)%12+1, 10));
for($forday=$startday;$forday<=$startday+$days;$forday++){
$currentDay=jddayofweek(($forday-1)%7,1);
for($day=strtotime("first $currentDay of $currentMonth $currentYear");$day<=strtotime("last $currentDay of $currentMonth $currentYear");$day+=604800){//κάθε μέρα εκκίνησης
$d=date('d',$day);
array_push($timestamps, strtotime("$starthour:00 $d $currentMonth $currentYear")*1000); //ώρα εκκίνησης
array_push($timestamps, strtotime("$endhour:59:59 $d $currentMonth $currentYear")*1000+999); //ώρα λήξης
}
}
}
}
asort($timestamps);
if(!$erroryear && !$errormonth && !$errorday && !$errorhour && !$erroractivity)
{
if($_POST['submit'] == 'true') {
include 'heatmap_data.php';
$datapoints = heatmapdata($timestamps, $activities);
echo json_encode(array('result1'=>array($erroryear, $errormonth, $errorday, $errorhour, $erroractivity), 'result2'=>$datapoints, 'result3'=>null));
}
elseif ($_POST['exp_submit'] == 'true') {
include 'export_file.php';
$export_array = array();
$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";
}
}
$sql = "SELECT heading, velocity, accuracy, longitude, latitude, altitude, timestampMs, userId FROM `usermapdata` WHERE $where";
$select_result = mysqli_query($conn,$sql);
if(!$select_result){
exit();
}
else {
while ($row = mysqli_fetch_assoc($select_result)) {
$userId = $row['userId'];
unset($row['userId']);
$row = add_activity_info($row, $activities, $conn);
if($row != false) {
$row['userId'] = $userId;
array_push($export_array, $row);
}
}
}
$result_r=export_data($export_array, $_POST['exp_type']);
$export_results=array($result_r);
echo json_encode(array('result1'=>array($erroryear, $errormonth, $errorday, $errorhour, $erroractivity), 'result2'=>null,'result3'=>$export_results));
}
}
else {
echo json_encode(array('result1'=>array($erroryear, $errormonth, $errorday, $errorhour, $erroractivity), 'result2'=>null, 'result3'=>null));
}
}
?>