-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexas_month.php
executable file
·42 lines (37 loc) · 1.34 KB
/
texas_month.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
<?php
$path = 'data/tx';
$files = scandir($path);
foreach($files as $file) {
if(!is_dir($file) && !preg_match('/^\./', $file)) {
$row = 1;
$res = '';
$capacity = '';
if (($handle = fopen($path . '/' . $file, "r")) !== FALSE) {
$months = array();
$months_list = array();
$fh = fopen('data/tx_m/' . $file, 'wb');
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if($row == 1) {
fputcsv($fh, $data);
} else {
$date = explode('/', $data[4]);
$date_parts = $date[0] . '/' . $date[2];
$months[$date_parts][] = $data[1];
}
$res = $data[0];
$capacity = $data[2];
$row++;
}
foreach($months as $key => $month) {
$monthly_avg = round(array_sum($month) / count($month));
$monthly_avg_pct = round(($monthly_avg / $capacity) * 100, 1);
if(preg_match('/20\d{2}$/', $key) && !preg_match('/[A-Za-z]/', $key)) {
fputcsv($fh, array($res, $monthly_avg, $capacity, $monthly_avg_pct, $key));
}
}
echo $res . "\n";
fclose($fh);
fclose($handle);
}
}
}