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