-
Notifications
You must be signed in to change notification settings - Fork 0
/
findBusyness.php
executable file
·55 lines (43 loc) · 1.33 KB
/
findBusyness.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
<?php
//This function will be called by external html ie front end UI
//expects three values to be a string or null if not specified
// $building: string representing the building
// $floor: floor of the above building
// $area: area of the above floor
include 'spaceFunctions.php'; //include
function findBusyness ($building, $floor, $area){
if (!$building) echo "Error: No Building Indicated <br>";
//connect to the SpaceFinder database
$con = connectToDB();
if ($con->errno) return 2; //return 2 if connection failed
//get values from SpaceFinder database
$currPop = getPopulation($building, $floor, $area, $con);
$maxPop = getMaxPop($building, $floor, $area, $con);
//calculate busyness index
if ($maxPop) {
$busyness = $currPop / $maxPop *100;
} else {
echo "Error: Max Population is zero";
return 0;
}
switch ($busyness){
case $busyness > 100:
echo "Overcrowded";
return 0;
case $busyness > 70 && $busyness <=100 :
echo "Extremely Busy";
return 0;
case $busyness > 50 && $busyness <=75 :
echo "Busy";
return 0;
case $busyness > 10 && $busyness <=50 :
echo "Normal";
return 0;
case $busyness <= 10 :
echo "Empty";
return 0;
}
if ($con) $con->close;
return 1; //return 1 if the case statement did not work
}
?>