--- a/admin/importOAICFOIrequests.php +++ b/admin/importOAICFOIrequests.php @@ -1,1 +1,86 @@ +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
"; + if ($data[0] != "TOTALS" && $data[0] != "") { + if (isset($nametoid[$name])) { + $id = $nametoid[$name]; + $timePeriod = $data[0] . "-Q" . $data[1]; + + echo "$timePeriod
"; + 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 . "
" . 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 "
ERROR NAME MISSING FROM ID LIST

$row" . PHP_EOL; + print_r($data); + die(); + } + } + } else { + $headers = $data; +//print_r($headers); + } + $row++; + } + fclose($handle); +} +foreach ($stats as $id => $stat) { + echo $id . "
" . PHP_EOL; + $doc = $db->get($id); + echo $doc->name . "
" . 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" . "
" . PHP_EOL; + } +} +?> +