Fix more graphs
Fix more graphs

--- a/admin/neo4jimporter/pom.xml
+++ b/admin/neo4jimporter/pom.xml
@@ -7,7 +7,7 @@
   	<dependency>
   		<groupId>org.neo4j</groupId>
   		<artifactId>neo4j</artifactId>
-  		<version>1.5</version>
+  		<version>1.6.1</version>
   	</dependency>
   	<dependency>
     <groupId>postgresql</groupId>

--- a/admin/neo4jimporter/src/main/java/Importer.java
+++ b/admin/neo4jimporter/src/main/java/Importer.java
@@ -88,26 +88,26 @@
                     + " AND contractnotice.\"agencyName\" != 'Defence Materiel Organisation' GROUP BY contractnotice.\"agencyName\", "
                     + "  contractnotice.\"supplierABN\",contractnotice.\"supplierName\"");
             String previousAgency = "";
-GraphDatabaseService gds = inserter.getGraphDbService(); 
-HashMap<String,Long> supplierIDs = new HashMap<String,Long>();
-HashMap<String,Long> agencyIDs = new HashMap<String,Long>();
-        
+            GraphDatabaseService gds = inserter.getGraphDbService();
+            HashMap<String, Long> supplierIDs = new HashMap<String, Long>();
+            HashMap<String, Long> agencyIDs = new HashMap<String, Long>();
+
             // Loop through the result set
             while (rs.next()) {
                 long supplierID, agencyID;
                 String supplierKey;
-                    if (agencyIDs.get(rs.getString("agencyName")) == null) {
-                       Node myNode = gds.createNode(); 
-                        myNode.setProperty("Label", rs.getString("agencyName"));
-                          myNode.setProperty("type", "agency");
-                        agencyIDs.put(rs.getString("agencyName"), myNode.getId());
-                        if (myNode.getId() %100 == 0) {
-    System.out.println("Agency "+myNode.getId());
-}
-                    } 
-                       agencyID = agencyIDs.get(rs.getString("agencyName"));
-                
-                
+                if (agencyIDs.get(rs.getString("agencyName")) == null) {
+                    Node myNode = gds.createNode();
+                    myNode.setProperty("Label", rs.getString("agencyName"));
+                    myNode.setProperty("type", "agency");
+                    agencyIDs.put(rs.getString("agencyName"), myNode.getId());
+                    if (myNode.getId() % 100 == 0) {
+                        System.out.println("Agency " + myNode.getId());
+                    }
+                }
+                agencyID = agencyIDs.get(rs.getString("agencyName"));
+
+
                 if (rs.getString("supplierABN") != "0" && rs.getString("supplierABN") != "") {
                     supplierKey = rs.getString("supplierABN");
                 } else {
@@ -115,19 +115,19 @@
                 }
                 // inject some data 
                 if (supplierIDs.get(supplierKey) == null) {
-                    Node myNode = gds.createNode(); 
-                        myNode.setProperty("Label", rs.getString("supplierName"));
-                            myNode.setProperty("type", "supplier");
+                    Node myNode = gds.createNode();
+                    myNode.setProperty("Label", rs.getString("supplierName"));
+                    myNode.setProperty("type", "supplier");
                     supplierIDs.put(supplierKey, myNode.getId());
-                    if (myNode.getId() %1000 == 0) {
-    System.out.println("Supplier "+myNode.getId());
-}
+                    if (myNode.getId() % 1000 == 0) {
+                        System.out.println("Supplier " + myNode.getId());
+                    }
                 }
                 supplierID = supplierIDs.get(supplierKey);
 
 
                 long rel = inserter.createRelationship(agencyID, supplierID,
-                       DynamicRelationshipType.withName("KNOWS"), null);
+                        DynamicRelationshipType.withName("KNOWS"), null);
                 inserter.setRelationshipProperty(rel, "Weight", rs.getDouble("sum"));
 
             }
@@ -154,6 +154,4 @@
         indexProvider.shutdown();
         inserter.shutdown();
     }
-
-   
 }

 Binary files a/admin/neo4jimporter/target/classes/Importer.class and b/admin/neo4jimporter/target/classes/Importer.class differ
--- a/displayCalendar.php
+++ b/displayCalendar.php
@@ -20,8 +20,8 @@
     $query->execute();

     databaseError($conn->errorInfo());

 

-    MethodCountGraph($supplier);

-    CnCGraph($supplier);

+    //MethodCountGraph($supplier);

+    //CnCGraph($supplier);

 

     echo "<table>  <thead>

     <tr>


--- a/exportData.csv.php
+++ b/exportData.csv.php
@@ -10,7 +10,9 @@
 foreach ($unspscresult->fetchAll() as $row) {
     $unspsc[$row['UNSPSC']] = $row['Title'];
 }
-
+/*SELECT count(*), extract("week" from "publishDate") as week,extract("year" from "publishDate") as year
+FROM contractnotice   
+where "childCN" is null group by week, year order by year, week*/
 $query = $conn->prepare('
 SELECT "CNID",contractnotice."agencyName",agency_nametoabn.abn as "agencyABN",
 EXTRACT(EPOCH FROM "publishDate") as "publishDate",

--- a/lib/graphs.inc.php
+++ b/lib/graphs.inc.php
@@ -136,7 +136,7 @@
 
     global $conn;
     includeFlot();
-    $query = 'SELECT SUM("value") as val, MAX(contractnotice."agencyName") as agencyname FROM contractnotice join agency on contractnotice."agencyName"=agency."agencyName"  WHERE "childCN" is null
+    $query = 'SELECT SUM("value") as val, MAX(contractnotice."agencyName") as agencyname FROM contractnotice join agency_nametoabn on contractnotice."agencyName"=agency_nametoabn."agencyName"  WHERE "childCN" is null
 GROUP BY abn ORDER BY SUM("value") DESC';
     $query = $conn->prepare($query);
     $query->execute();
@@ -195,11 +195,15 @@
 ;
 
 function agencySuppliersGraph($agency) {
+    
+    global $conn;
     $agency = "AusAid";
     $topX = 15;
-    $query = 'SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND "childCN" is null AND agencyName = \'$agency\'
+    $query = 'SELECT SUM(value) as val, "supplierName" FROM contractnotice WHERE (extract ("YEAR" from "contractStart") >= :startYear) AND "childCN" is null AND "agencyName" = :agency
 GROUP BY lower(supplierName) ORDER BY val DESC limit $topX';
     $query = $conn->prepare($query);
+        $query->bindParam(":startYear",$startYear);
+    $query->bindParam(":agency",$agency);
     $query->execute();
     databaseError($conn->errorInfo());
     $suppliers = Array();
@@ -210,9 +214,11 @@
     }
 
 
-    $query = 'SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND "childCN" is null and agencyName = \'$agency\'
-GROUP BY lower(supplierName) ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a';
-    $query = $conn->prepare($query);
+    $query = 'SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, "supplierName" FROM contractnotice WHERE (extract ("YEAR" from "contractStart") >= :startYear) AND "childCN" is null and "agencyName" = :agency
+GROUP BY lower("supplierName") ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a';
+    $query = $conn->prepare($query);
+    $query->bindParam(":startYear",$startYear);
+    $query->bindParam(":agency",$agency);
     $query->execute();
     databaseError($conn->errorInfo());
     foreach ($query->fetchAll() as $row) {
@@ -224,8 +230,10 @@
 }
 
 function CnCGraph() {
-    $query = "select procurementMethod, count(1) as count, SUM(value) as val, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice`
-where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month";
+    
+    global $conn;
+    $query = 'select procurementMethod, count(1) as count, SUM(value) as val, MONTH(contractStart) as month, YEAR(contractStart) as year from contractnotice
+where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month';
     $query = $conn->prepare($query);
     $query->execute();
     databaseError($conn->errorInfo());
@@ -267,19 +275,21 @@
         "Consultancies",
         "Confidentialities"
     );
-    $query = 'SELECT \'consultancy\', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ consultancy=\'Yes\' AND "childCN" is null;';
+    $query = 'SELECT \'consultancy\', count(1) FROM contractnotice WHERE $agencyQ $supplierQ consultancy=\'Yes\' AND "childCN" is null;';
     $result = $conn->query($query);
     $row = $result->fetch(PDO::FETCH_ASSOC);
     $attributes[0] = $row[1];
-    $query = 'SELECT \'confidentiality\', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ (confidentialityContract=\'Yes\' OR confidentialityOutputs=\'Yes\') AND "childCN" is null;';
+    $query = 'SELECT \'confidentiality\', count(1) FROM contractnotice WHERE $agencyQ $supplierQ (confidentialityContract=\'Yes\' OR confidentialityOutputs=\'Yes\') AND "childCN" is null;';
     $result = $conn->query($query);
     $row = $result->fetch(PDO::FETCH_ASSOC);
     $attributes[1] = $row[1];
 }
 
 function ContractPublishedGraph() {
+    
+    global $conn;
     $query = 'SELECT YEAR(publishDate), MONTH(publishDate),
-SUM(value) as val, count(1) as count FROM `contractnotice`
+SUM(value) as val, count(1) as count FROM contractnotice
 WHERE (YEAR(publishDate) >= 2008)
 AND "childCN" is null
 GROUP BY MONTH(publishDate), YEAR(publishDate) 
@@ -302,8 +312,10 @@
 }
 
 function ContractStartingGraph() {
+    
+    global $conn;
     $query = 'SELECT YEAR(contractStart), MONTH(contractStart),
-SUM(value) as val, count(1) as count FROM `contractnotice`
+SUM(value) as val, count(1) as count FROM contractnotice
 WHERE (YEAR(contractStart) >= 2008)
 AND "childCN" is null
 GROUP BY MONTH(contractStart), YEAR(contractStart) 
@@ -326,7 +338,9 @@
 }
 
 function MethodCountGraph() {
-    $query = 'select procurementMethod, count(1) as count, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice`
+    
+    global $conn;
+    $query = 'select procurementMethod, count(1) as count, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from contractnotice
 where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month';
     $methods = Array("Direct", "Open", "Select");
     $dates = Array();
@@ -361,7 +375,9 @@
 }
 
 function MethodValueGraph() {
-    $query = "select procurementMethod, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice`
+    
+    global $conn;
+    $query = "select procurementMethod, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from contractnotice
 where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month";
     $methods = Array("Direct", "Open", "Select");
     $dates = Array();