-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
40 lines (32 loc) · 1.09 KB
/
api.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
<?php
require_once('database.php');
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");
// Select Alameda County & Berkeley related data
$query = "SELECT `date`, `berkeley_new_cases`, `berkeley_cumul_cases`, `ac_new_cases`, `ac_cumul_cases` FROM `alameda_county` ORDER BY `date` ASC";
$data = $database->query($query);
$rows = [];
while ( $row = mysqli_fetch_assoc($data) ) {
$rows[] = $row;
}
$data = $rows;
// Format data for output
foreach($data as $item) {
$berkeleyCumulativeCases[] = (int)$item['berkeley_cumul_cases'];
}
$date = new DateTime( array_reverse($data)[0]['date'] );
$date = $date->format('M j');
$data = [
'date' => $date,
'berkeley' => [
'total' => (int)array_reverse($data)[0]['berkeley_cumul_cases'],
'new' => (int)array_reverse($data)[0]['berkeley_new_cases'],
'cumulative' => $berkeleyCumulativeCases
],
'alameda' => [
'total' => (int)array_reverse($data)[0]['ac_cumul_cases'],
'new' => (int)array_reverse($data)[0]['ac_new_cases']
]
];
$data = json_encode($data);
print_r( $data );