-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
137 lines (116 loc) · 3.45 KB
/
index.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
<?php
require('inc/functions.php');
$file = file_get_contents('inc/Water.json', true);
$json = json_decode($file, true);
$token = 'c5de7ee89c1925924dbf0cfd0087b9642fb8cd5c';
$url = "https://formhub.org/api/v1/data/north_ghana/8379";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Token '.$token,
'Content-Type: application/json',
'Accept: application/json'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
//$json = json_decode($output, true);
//var_dump($json);
$total = count($json);
$communities = array_values(getCommunities($json));
sort($communities);
//var_dump($json);
$com_count = count($communities);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title>Programming Task | Ona Labs</title>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<meta name="author" content="Mucheru"/>
<meta name="robots" content="index, follow" />
<meta name="revisit-after" content="7 days" />
<meta name="viewport" content="width=device-width, user-scalable=no"/>
<link rel="stylesheet" href="assets/css/reset.css"/>
<link rel="stylesheet" href="assets/css/style.css"/>
<link rel="stylesheet" href="assets/css/leaflet.css"/>
<style type="text/css">
#map{
height:30em;
}
</style>
</head>
<body>
<div id="wrapper">
<h2>Survey on Water Points</h2>
<p>Based on research from:
<a href="http://ona.io/">http://ona.io</a></p>
<p><a href="http://mucheru.me/test/ona/water/src.zip">Download Source</a></p>
<br/><br/>
<div class="container">
<div class="waterbox cfix">
<h3>Functional Water points:
<?php echo '<span style="color:green;">'.getPointStatus($json, 'functioning').'</span>'; ?></h3>
</div>
<div class="waterbox cfix">
<h3>The number of water points per community: </h3>
<table class="dataTables">
<thead>
<tr>
<th width="60%">Community</th>
<th># of Water points in community</th>
</tr>
</thead>
<tbody>
<?php
for($c=0; $c<=$com_count; $c++){
$name = isset($communities[$c])? $communities[$c] : '';
if($name){
echo '<tr><td>'.$name . '</td>
<td>'.countWaterPoints($name, $json, '').'</td></tr>';
}
}
?>
</tbody>
</table>
</div>
<div class="waterbox cfix">
<h3>Percentage of broken water points per community</h3>
<p>(Rankings in Descending order)</p><br/>
<table class="dataTables">
<thead>
<tr>
<th width="60%">Community</th>
<th>% of Broken Water points</th>
</tr>
</thead>
<tbody>
<?php
for($c=0; $c<$com_count; $c++){
$name = isset($communities[$c])? $communities[$c] : '';
$all_points = countWaterPoints($name, $json, '');
$broken_points = countWaterPoints($name, $json, 'broken');
if($name && $broken_points!=0 && $all_points!=0){
$percentage = ($broken_points/$all_points)*100;
echo '<tr><td>'.$name . '</td>
<td>'.number_format($percentage,1,'.','').'</td></tr>';
}
//var_dump($name);
}
?>
</tbody>
</table>
</div>
<div class="cls"></div>
</div>
<div class="cls"></div>
</div>
<div id="map"></div>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/datatable.js"></script>
<script src="assets/js/leaflet.js"></script>
<script src="assets/js/script.js"></script>
</body>
</html>