beginning datagov scraper
[disclosr.git] / documents / charts.php
blob:a/documents/charts.php -> blob:b/documents/charts.php
--- a/documents/charts.php
+++ b/documents/charts.php
@@ -5,18 +5,27 @@
 $agenciesdb = $server->get_db('disclosr-agencies');
 
 $idtoname = Array();
+$idtofoirequestssuccessful = Array();
 foreach ($agenciesdb->get_view("app", "byCanonicalName")->rows as $row) {
     $idtoname[$row->id] = trim($row->value->name);
+    $foirequestssuccessful = 0;
+if(isset($row->value->statistics->foiRequests)) {
+    foreach ($row->value->statistics->foiRequests as $statperiod) {
+	$statperiod=object_to_array($statperiod);
+	if (isset($statperiod["Requests for other information granted in full"])) $foirequestssuccessful += $statperiod["Requests for other information granted in full"];
+	if (isset($statperiod["Requests for other information granted in part"])) $foirequestssuccessful += $statperiod["Requests for other information granted in part"];
+	}
+}
+   $idtofoirequestssuccessful[$row->id] =$foirequestssuccessful;
 }
 $foidocsdb = $server->get_db('disclosr-foidocuments');
-
 ?>
 <div class="foundation-header">
     <h1><a href="about.php">Charts</a></h1>
-    <h4 class="subheader">Lorem ipsum.</h4>
+    <h4 class="subheader"></h4>
 </div>
 <div id="bydate" style="width:1000px;height:300px;"></div>
-<div id="byagency" style="width:1200px;height:300px;"></div>
+<div id="byagency" style="width:1000px;height:1400px;"></div>
 <script id="source">
     window.onload = function () {
         $(document).ready(function () {
@@ -28,7 +37,6 @@
             <?php
                 try {
                     $rows = $foidocsdb->get_view("app", "byDateMonthYear?group=true",null, false,false,true)->rows;
-
 
                     $dataValues = Array();
                     foreach ($rows as $row) {
@@ -59,7 +67,7 @@
                     mode: 'x'
                 },
                 HtmlText: false,
-                title: 'Time'
+                title: 'Disclosure Log entries added by Date'
             };
 
             // Draw graph with default options, overwriting with passed options
@@ -95,15 +103,16 @@
     };
 
     var d2 = [];
+    var d3 = [];
     var agencylabels = [];
     function agencytrackformatter(obj) {
 
-        return agencylabels[Math.floor(obj.x)] + " = " + obj.y;
+        return agencylabels[Math.floor(obj.y)] + " = " + obj.x;
 
     }
     function agencytickformatter(val, axis) {
         if (agencylabels[Math.floor(val)]) {
-            return '<p style="margin-top:8em;-webkit-transform:rotate(-90deg);">' + (agencylabels[Math.floor(val)]) + "</b>";
+            return  (agencylabels[Math.floor(val)]) ;
 
         } else {
             return "";
@@ -112,12 +121,17 @@
     <?php
         try {
             $rows = $foidocsdb->get_view("app", "byAgencyID?group=true",null, false,false,true)->rows;
-
+function cmp($a, $b)
+{
+    return $a->value > $b->value;
+}
+usort($rows, "cmp");
 
             $dataValues = Array();
             $i = 0;
             foreach ($rows as $row) {
-                echo "       d2.push([".$i.", $row->value]);" . PHP_EOL;
+                echo "       d2.push([ $row->value,$i]);" . PHP_EOL;
+                echo "       d3.push([ ".$idtofoirequestssuccessful[$row->key].",$i]);" . PHP_EOL;
                 echo "       agencylabels.push(['".str_replace("'","",$idtoname[$row->key])."']);" . PHP_EOL;
 
                 $i++;
@@ -131,9 +145,10 @@
         document.getElementById("byagency"),
         [d2],
         {
+            title: "Disclosure Log entries by Agency",
             bars: {
                 show: true,
-                horizontal: false,
+                horizontal: true,
                 shadowSize: 0,
                 barWidth: 0.5
             },
@@ -143,17 +158,17 @@
                 trackFormatter: agencytrackformatter
             },
             yaxis: {
-                min: 0,
-                autoscaleMargin: 1
-            },
-            xaxis: {
                 minorTickFreq: 1,
                 noTicks: agencylabels.length,
                 showMinorLabels: true,
                 tickFormatter: agencytickformatter
             },
+            xaxis: {
+                min: 0,
+                autoscaleMargin: 1
+            },
             legend: {
-                show: false
+                show: true
             }
         }
     );