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 | <?php require_once '../include/common.inc.php'; $db = $server->get_db('disclosr-agencies'); $rows = $db->get_view("app", "byName")->rows; $nametoid = Array(); $stats = Array(); foreach ($rows as $row) { $nametoid[trim($row->key)] = $row->value; } $row = 0; $headers = Array(); // source: http://data.gov.au/dataset/freedom-of-information-quarterly-request-and-review-statistical-data-2011-12/ if (($handle = fopen("FOI-quarterly-requests-and-reviews-2011-12.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) { if ($row >= 1) { // print_r($data); $name = trim($data[2]); echo "$name <br>"; if ($data[0] != "TOTALS" && $data[0] != "") { if (isset($nametoid[$name])) { $id = $nametoid[$name]; $timePeriod = $data[0] . "-Q" . $data[1]; echo "$timePeriod <br>"; unset($data[0]); unset($data[1]); unset($data[2]); unset($data[3]); unset($data[4]); unset($data[5]); unset($data[6]); unset($data[7]); unset($data[8]); //echo $id . "<br>" . PHP_EOL; $result = Array("source" => "http://data.gov.au/dataset/freedom-of-information-quarterly-request-and-review-statistical-data-2011-12/"); foreach ($data as $key => $datum) { if ($datum != 0) { $result[trim($headers[$key])] = $datum; } } $stats[$id][$timePeriod] = $result; //print_r($stats); } else { echo "<br>ERROR NAME MISSING FROM ID LIST<br><bR> $row" . PHP_EOL; print_r($data); die(); } } } else { $headers = $data; //print_r($headers); } $row++; } fclose($handle); } foreach ($stats as $id => $stat) { echo $id . "<br>" . PHP_EOL; $doc = $db->get($id); echo $doc->name . "<br>" . PHP_EOL; print_r($stat); die(); // print_r($doc); $changed = false; if (!isset($doc->statistics)) { $changed = true; $doc->statistics = Array(); } foreach ($stat as $timePeriod => $value) { if (!isset($doc->statistics->foiRequests->$timePeriod) || $doc->statistics->foiRequests->$timePeriod != $value) { $changed = true; $doc->statistics["foiRequests"][$timePeriod] = $value; } } if ($changed) { $db->save($doc); } else { echo "not changed" . "<br>" . PHP_EOL; } } ?> |