-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_all.php
executable file
·40 lines (34 loc) · 1.42 KB
/
state_all.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
include 'functions.php';
$states = array('az', 'ca', 'co', 'id', 'nm', 'nv', 'or', 'tx', 'utah', 'wa', 'wy');
foreach($states as $state) {
$fh = fopen('data/states_all/' . $state . '_all.csv', 'wb');
fputcsv($fh, array('reservoir','storage','capacity','pct_capacity','date'));
$suffix = ($state == 'tx') ? '_m' : '_month';
$file_dir = 'data/' . $state . $suffix;
$files = scandir($file_dir);
foreach($files as $file) {
if(!preg_match('/^\./', $file)) {
if (($handle = fopen($file_dir . '/' . $file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$date = preg_split('/\//', $data[4]);
if(!preg_match('/reservoir/', $data[0]) && $date[1] >= 2000) {
if($data[0] == "Coyote Res-sta Clara") {
$data[0] = "Coyote Res Sta Clara";
}
if($data[0] == "Clear Lk - Cache Creek") {
$data[0] = "Clear Lk Cache Creek";
}
if($data[0] == "Clear Lk - Klamath R") {
$data[0] = "Clear Lk Klamath R";
}
fputcsv($fh, $data);
}
}
fclose($handle);
}
}
}
fclose($fh);
$state . "processed\n";
}