forked from dipanshu231099/ADP_project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgethint.php
More file actions
49 lines (46 loc) · 1.58 KB
/
gethint.php
File metadata and controls
49 lines (46 loc) · 1.58 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
<?php
//change the username passwd here
$conn = mysqli_connect('localhost','dipanshu','dipanshu23','project');
$from_date = $_REQUEST['from_date'];
$in_date = new DateTime($from_date . " 01:00:00");
$to_date = $_REQUEST['to_date'];
$fin_date = new DateTime($to_date . " 23:00:01");
$field = $_REQUEST['field'];
$query = "SELECT * FROM pollution_data";
$result = $conn->query($query);
$maximum = 0.00;
$minimum = 10000.00;
$avg = 0;
$count=0;
while($row = mysqli_fetch_array($result)){
$date= explode(" ",$row['TIMESTAMP'])[0];
$mm = (int)explode('/',$date)[0];
$dd = (int)explode('/',$date)[1];
$yy = (int)explode('/',$date)[2];
$date = new DateTime(strval($yy) . "-" . strval($mm) . "-" . strval($dd) . " 12:00:00");
if($date>$in_date && $date<$fin_date){
$count++;
$req_value = $row[$field];
$avg += (float)$req_value;
if($req_value > $maximum){
$maximum = $req_value;
}
if($req_value < $minimum){
$minimum = $req_value;
}
}
}
$avg/=$count;
$q = $_REQUEST["q"];
$hint = "";
if(strpos($q,"avg")!==false)$hint.= "average value $avg <br>";
if(strpos($q,"max")!==false){
if($maximum != 0)$hint.= "maximum value: $maximum <br>";
else $hint.= "no value to maximise <br>";
}
if(strpos($q, "min")){
if($minimum!=10000)$hint.= "minimum value: $minimum <br>";
else $hint.= "no value to minimise <br>";
}
echo $hint;
?>