<?php | <?php |
include_once("./lib/common.inc.php"); | include_once("./lib/common.inc.php"); |
/* | /* |
agencies that use alot of consultacies | agencies that use alot of consultacies |
suppliers that provide alot | suppliers that provide alot |
how much is spent overall per year | how much is spent overall per year |
*/ | */ |
include_header("Consultancies"); | include_header("Consultancies"); |
$query = ' | $query = ' |
SELECT SUM(value) as value, count(*), min("supplierName"), unnest(string_to_array("consultancyReason",\';\')) reason | SELECT SUM(value) as value, count(*), text_mode("supplierName"), unnest(string_to_array("consultancyReason",\';\')) reason |
FROM contractnotice where ' .$yearQ . ' "consultancy" = \'Yes\' and "childCN" is null | FROM contractnotice where ' .$yearQ . ' "consultancy" = \'Yes\' and "childCN" is null |
GROUP BY "supplierABN",reason order by value desc | GROUP BY "supplierABN",reason order by value desc |
'; | '; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
echo "<table>"; | echo "<table>"; |
foreach ($query->fetchAll() as $row) { | foreach ($query->fetchAll() as $row) { |
setlocale(LC_MONETARY, 'en_US'); | setlocale(LC_MONETARY, 'en_US'); |
$value = number_format(doubleval($row[0]),2); | $value = number_format(doubleval($row[0]),2); |
echo ("<tr><td><b>{$row[2]}</b></td><td>{$row[3]}</td><td>{$row[1]} contracts</td><td>\$$value</td></tr>"); | echo ("<tr><td><b>{$row[2]}</b></td><td>{$row[3]}</td><td>{$row[1]} contracts</td><td>\$$value</td></tr>"); |
} | } |
echo "</table>"; | echo "</table>"; |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
include_once("./lib/common.inc.php"); | include_once("./lib/common.inc.php"); |
$query = 'SELECT * | $query = 'SELECT * |
FROM contractnotice | FROM contractnotice |
WHERE "CNID" = :CNID LIMIT 1'; | WHERE "CNID" = :CNID LIMIT 1'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->bindParam(":CNID", $_REQUEST['CNID']); | $query->bindParam(":CNID", $_REQUEST['CNID']); |
$query->execute(); | $query->execute(); |
$contractResult = $query->fetch(PDO::FETCH_ASSOC); | $contractResult = $query->fetch(PDO::FETCH_ASSOC); |
if (!$contractResult) { | if (!$contractResult) { |
header("Status: 404 Not Found"); | header("Status: 404 Not Found"); |
header("HTTP/1.0 404 Not Found"); | header("HTTP/1.0 404 Not Found"); |
include_header("Contract Not Found"); | include_header("Contract Not Found"); |
echo "<center><h1>No Contract Notice with that ID found</h1></center>"; | echo "<center><h1>No Contract Notice with that ID found</h1></center>"; |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
} else { | } else { |
$description = ucsmart($contractResult["description"]); | $description = ucsmart($contractResult["description"]); |
include_header($description); | include_header($description); |
echo '<center><h1>'.$description.'</h1></center> | echo '<center><h1>'.$description.'</h1></center> |
<div about="http://contracts.disclosurelo.gs/displayContract.php?CNID='.$contractResult["CNID"].'" typeof="pc:Contract">'; | <div about="http://contracts.disclosurelo.gs/displayContract.php?CNID='.$contractResult["CNID"].'" typeof="pc:Contract">'; |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
setlocale(LC_MONETARY, 'en_US'); | setlocale(LC_MONETARY, 'en_US'); |
foreach (array_filter($contractResult) as $key => $value) { | foreach (array_filter($contractResult) as $key => $value) { |
echo "<b>$key</b> "; | echo "<b>$key</b> "; |
switch ($key) { | switch ($key) { |
case "supplierABN": | case "supplierABN": |
break; | break; |
case "supplierName": | case "supplierName": |
echo ' | echo ' |
<a href="displaySupplier.php?supplier=' . $contractResult['supplierABN'] . '-' . urlencode($contractResult['supplierName']) . '"> | <a href="displaySupplier.php?supplier=' . $contractResult['supplierABN'] . '-' . urlencode($contractResult['supplierName']) . '"> |
<span rel="pc:contractingAuthority" typeof="gr:BusinessEntity"> | <span rel="pc:contractingAuthority" typeof="gr:BusinessEntity"> |
<span property="gr:legalName">' | <span property="gr:legalName">' |
. $contractResult['supplierName'] . | . $contractResult['supplierName'] . |
'</span>'. | '</span>'. |
(isset($contractResult['supplierABN']) && $contractResult['supplierABN'] != '' ? ' (ABN: <span property="br:officialNumber" lang="">'.$contractResult['supplierABN'].'</span>)' : '') | (isset($contractResult['supplierABN']) && $contractResult['supplierABN'] != '' ? ' (ABN: <span property="br:officialNumber" lang="">'.$contractResult['supplierABN'].'</span>)' : '') |
.'</span></a>'; | .'</span></a>'; |
break; | break; |
case "CNID": | case "CNID": |
echo '<span property="pc:referenceNumber" lang="">'.$value.'</span>'; | echo '<span property="pc:referenceNumber" lang="">'.$value.'</span>'; |
break; | |
case "categoryUNSPSC": | |
break; | break; |
case "category": | case "category": |
echo '<span rel="pc:mainObject" resource="[unspsc:'.$contractResult["categoryUNSPSC"].']">'.$value.'</span>'; | echo '<span rel="pc:mainObject" resource="[unspsc:'.$contractResult["categoryUNSPSC"].']">'.$value.'</span>'; |
break; | break; |
case "SONID": | case "SONID": |
echo '<a href="displaySON.php?SONID=' . urlencode($value) . '">' . $value . "</a>"; | echo '<a href="displaySON.php?SONID=' . urlencode($value) . '">' . $value . "</a>"; |
break; | break; |
case "agencyName": | case "agencyName": |
echo '<a href="displayAgency.php?agency=' . urlencode($value) . '">' . $value . "</a>"; | echo '<a href="displayAgency.php?agency=' . urlencode($value) . '">' . $value . "</a>"; |
break; | break; |
case "contractStart": | case "contractStart": |
echo '<span property="pc:startDate" content="'.$value.'" datatype="xsd:date">'.$value.'</span>'; | echo '<span property="pc:startDate" content="'.$value.'" datatype="xsd:date">'.$value.'</span>'; |
break; | break; |
case "contractEnd": | case "contractEnd": |
echo '<span property="pc:endDate" content="'.$value.'" datatype="xsd:date">'.$value.'</span>'; | echo '<span property="pc:endDate" content="'.$value.'" datatype="xsd:date">'.$value.'</span>'; |
break; | break; |
case "value": | case "value": |
echo '<span rel="pc:agreedPrice" typeof="gr:PriceSpecification"> | echo '<span rel="pc:agreedPrice" typeof="gr:PriceSpecification"> |
<span property="gr:hasCurrency" content="AUD" lang="">$ </span> | <span property="gr:hasCurrency" content="AUD" lang="">$ </span> |
<span property="gr:hasCurrencyValue" content="'.doubleval($value).'" datatype="xsd:float">' . number_format(doubleval($value), 2) | <span property="gr:hasCurrencyValue" content="'.doubleval($value).'" datatype="xsd:float">' . number_format(doubleval($value), 2) |
.'</span></span>'; | .'</span></span>'; |
break; | break; |
case "description": | case "description": |
echo '<span property="dcterms:title">'.$value.'</span>'; | echo '<span property="dcterms:title">'.$value.'</span>'; |
break; | break; |
default: | default: |
echo str_replace(" ", "<br>", ucsmart($value)); | echo str_replace(" ", "<br>", ucsmart($value)); |
} | } |
echo "<br>\n"; | echo "<br>\n"; |
} | } |
echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN' . $_REQUEST['CNID'] . '"> View original record @ tenders.gov.au</a><br> | echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN' . $_REQUEST['CNID'] . '"> View original record @ tenders.gov.au</a><br> |
</div>'; | </div>'; |
/*$query = $solr_client->createMoreLikeThis(); | /*$query = $solr_client->createMoreLikeThis(); |
$query->setQuery('id:'.$_REQUEST['CNID']); | $query->setQuery('id:'.$_REQUEST['CNID']); |
$query->setMltFields('description'); | $query->setMltFields('description'); |
$query->setMinimumDocumentFrequency(1); | $query->setMinimumDocumentFrequency(1); |
$query->setMinimumTermFrequency(1); | $query->setMinimumTermFrequency(1); |
$query->setInterestingTerms('description'); | $query->setInterestingTerms('description'); |
$query->setMatchInclude(true); | $query->setMatchInclude(true); |
// this executes the query and returns the result | // this executes the query and returns the result |
$resultset = $solr_client->select($query); | $resultset = $solr_client->select($query); |
// display the total number of documents found by solr | // display the total number of documents found by solr |
echo 'Found '.$resultset->getNumFound(). ' similar results: <table>'; | echo 'Found '.$resultset->getNumFound(). ' similar results: <table>'; |
foreach ($resultset as $row) { | foreach ($resultset as $row) { |
setlocale(LC_MONETARY, 'en_US'); | setlocale(LC_MONETARY, 'en_US'); |
$value = number_format(doubleval($row['value'][0]), 2); | $value = number_format(doubleval($row['value'][0]), 2); |
echo ("<tr> | echo ("<tr> |
<td><a href=\"displayContract.php?CNID={$row['id']}\">{$row['id']}</a></td> | <td><a href=\"displayContract.php?CNID={$row['id']}\">{$row['id']}</a></td> |
<td><b>{$row['description'][0]}</b></a></td> | <td><b>{$row['description'][0]}</b></a></td> |
<td>\$$value</td><td>{$row['agencyName'][0]}</td> | <td>\$$value</td><td>{$row['agencyName'][0]}</td> |
<td>{$row['contractStart'][0]}</td> | <td>{$row['contractStart'][0]}</td> |
<td>{$row['supplierName'][0]}</td> | <td>{$row['supplierName'][0]}</td> |
</tr>"); | </tr>"); |
} | } |
echo "</table>";*/ | echo "</table>";*/ |
$query = 'SELECT * FROM heuristic_results where "CNID" = :CNID'; | $query = 'SELECT * FROM heuristic_results where "CNID" = :CNID'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$agencyName = $input . '%'; | $agencyName = $input . '%'; |
$query->bindParam(":CNID", $_REQUEST['CNID']); | $query->bindParam(":CNID", $_REQUEST['CNID']); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
foreach ($query->fetchAll() as $r) { | foreach ($query->fetchAll() as $r) { |
echo "<b>{$r['heuristic_name']}</b>: {$r['heuristic_value']} (raw value: {$r['raw_value']}, mean: {$r['mean']}, stddev: {$r['stddev']})<br>"; | echo "<b>{$r['heuristic_name']}</b>: {$r['heuristic_value']} (raw value: {$r['raw_value']}, mean: {$r['mean']}, stddev: {$r['stddev']})<br>"; |
} | } |
} | } |
include_footer(); | include_footer(); |
?> | ?> |
<?php | <?php |
include_once("./lib/common.inc.php"); | include_once("./lib/common.inc.php"); |
// TODO | // TODO |
// color suppliers based on value? static list of high value suppliers? | // color suppliers based on value? static list of high value suppliers? |
// TODO sigma | // TODO sigma |
// link on contracts site? | // link on contracts site? |
// allow higher zoom levels | // allow higher zoom levels |
// describe methodology and yellow/red color meaning, creative commons attribution | // describe methodology and yellow/red color meaning, creative commons attribution |
$used_node_ids = Array(); | $used_node_ids = Array(); |
$included_panel_ids = Array(); | $included_panel_ids = Array(); |
$used_edge_ids = Array(); | $used_edge_ids = Array(); |
function add_node($id, $label, $parent = "", $panel = false) | function add_node($id, $label, $parent = "", $panel = false) |
{ | { |
global $used_node_ids; | global $used_node_ids; |
if (!in_array($id, $used_node_ids)) { | if (!in_array($id, $used_node_ids)) { |
echo "<node id='" . urlencode($id) . "' label=\"" . str_replace('"','',str_replace("&", "and", $label)) . "\" " . ($parent != "" ? "pid='$parent'><viz:size value='" . rand(1, 50) . "'/>" : "><viz:size value='2'/>") | echo "<node id='" . urlencode($id) . "' label=\"" . str_replace('"','',str_replace("&", "and", $label)) . "\" " . ($parent != "" ? "pid='$parent'><viz:size value='" . rand(1, 50) . "'/>" : "><viz:size value='2'/>") |
. "<viz:color b='" . ($panel ? 0 : 0) . "' g='" . ($panel ? 0 : 255) . "' r='" . ($panel ? 255 : 255) . "'/>"; | . "<viz:color b='" . ($panel ? 0 : 0) . "' g='" . ($panel ? 0 : 255) . "' r='" . ($panel ? 255 : 255) . "'/>"; |
echo "</node>" . PHP_EOL; | echo "</node>" . PHP_EOL; |
$used_node_ids[] = $id; | $used_node_ids[] = $id; |
} | } |
} | } |
function add_edge($from, $to, $weight = '1.0') | function add_edge($from, $to, $weight = '1.0') |
{ | { |
global $used_edge_ids, $included_panel_ids; | global $used_edge_ids, $included_panel_ids; |
$id = urlencode($from . '-' . $to); | $id = urlencode($from . '-' . $to); |
if (!in_array($id, $used_edge_ids)) { | if (!in_array($id, $used_edge_ids)) { |
echo "<edge id='" . $id . "' source='" . urlencode($from) . "' target='" . urlencode($to) . "' weight='" . $weight . "'>" . PHP_EOL; | echo "<edge id='" . $id . "' source='" . urlencode($from) . "' target='" . urlencode($to) . "' weight='" . $weight . "'>" . PHP_EOL; |
if ($weight != 0.1) { | if ($weight != 0.1) { |
echo "<viz:color b='192' g='192' r='192'/>"; | echo "<viz:color b='192' g='192' r='192'/>"; |
} else { | } else { |
echo "<viz:color b='0' g='0' r='255'/>"; | echo "<viz:color b='0' g='0' r='255'/>"; |
} | } |
echo "</edge>" . PHP_EOL; | echo "</edge>" . PHP_EOL; |
$used_edge_ids[] = $id; | $used_edge_ids[] = $id; |
} | } |
} | } |
$edges = Array(); | $edges = Array(); |
header('Content-Type: application/gexf+xml'); | header('Content-Type: application/gexf+xml'); |
echo '<?xml version="1.0" encoding="UTF-8"?> | echo '<?xml version="1.0" encoding="UTF-8"?> |
<gexf xmlns="http://www.gexf.net/1.2draft" xmlns:viz="http://www.gexf.net/1.2draft/viz" version="1.2"> | <gexf xmlns="http://www.gexf.net/1.2draft" xmlns:viz="http://www.gexf.net/1.2draft/viz" version="1.2"> |
<meta lastmodifieddate="2009-03-20"> | <meta lastmodifieddate="2009-03-20"> |
<creator>Gexf.net</creator> | <creator>Gexf.net</creator> |
<description>A hello world! file</description> | <description>A hello world! file</description> |
</meta> | </meta> |
<graph mode="static" defaultedgetype="directed"> | <graph mode="static" defaultedgetype="directed"> |
<nodes>' . PHP_EOL; | <nodes>' . PHP_EOL; |
$query = ' | $query = ' |
SELECT "supplierABN", min("supplierName") AS "supplierName", contractnotice."SONID", count(*), sum(value) AS value | SELECT "supplierABN", text_mode("supplierName") AS "supplierName", contractnotice."SONID", count(*), sum(value) AS value |
FROM contractnotice | FROM contractnotice |
WHERE "childCN" IS NULL | WHERE "childCN" IS NULL |
AND extract(year from "publishDate") = \'2016\' | AND extract(year from "publishDate") = \'2016\' |
AND "supplierABN" in (select distinct "supplierABN" from contractnotice where (left("categoryUNSPSC"::text,2) = \'43\' or left("categoryUNSPSC"::text,2) = \'80\') ) | AND "supplierABN" in (select distinct "supplierABN" from contractnotice where (left("categoryUNSPSC"::text,2) = \'43\' or left("categoryUNSPSC"::text,2) = \'80\') ) |
AND contractnotice."SONID" != \'\' AND contractnotice."SONID" IS NOT NULL GROUP BY "supplierABN", contractnotice."SONID"'; | AND contractnotice."SONID" != \'\' AND contractnotice."SONID" IS NOT NULL GROUP BY "supplierABN", contractnotice."SONID"'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
foreach ($query->fetchAll() as $row) { | foreach ($query->fetchAll() as $row) { |
add_node($row['supplierABN'], $row['supplierName'], "",false); | add_node($row['supplierABN'], $row['supplierName'], "",false); |
$included_panel_ids[] = $row['SONID']; | $included_panel_ids[] = $row['SONID']; |
$edges[] = array("head" => $row['SONID'], "tail" => $row['supplierABN'], "weight" => $row['count']); | $edges[] = array("head" => $row['SONID'], "tail" => $row['supplierABN'], "weight" => $row['count']); |
} | } |
$query = 'SELECT "SONID", title FROM standingoffers'; | $query = 'SELECT "SONID", title FROM standingoffers'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
foreach ($query->fetchAll() as $row) { | foreach ($query->fetchAll() as $row) { |
// if (in_array($row['SONID'], $included_panel_ids)){ | // if (in_array($row['SONID'], $included_panel_ids)){ |
add_node($row['SONID'], $row['title'], "", true); | add_node($row['SONID'], $row['title'], "", true); |
// } | // } |
} | } |
$query = 'select "SONID", abn,name from standingoffer_suppliers'; | $query = 'select "SONID", abn,name from standingoffer_suppliers'; |
$query = $conn->prepare($query); | $query = $conn->prepare($query); |
$query->execute(); | $query->execute(); |
databaseError($conn->errorInfo()); | databaseError($conn->errorInfo()); |
foreach ($query->fetchAll() as $row) { | foreach ($query->fetchAll() as $row) { |
add_node($row['abn'], $row['name']); | add_node($row['abn'], $row['name']); |
$edges[] = array("head"=>$row['SONID'], "tail"=>$row['abn'], "weight"=> 0.1); | $edges[] = array("head"=>$row['SONID'], "tail"=>$row['abn'], "weight"=> 0.1); |
} | } |
echo '</nodes> | echo '</nodes> |
<edges>' . PHP_EOL; | <edges>' . PHP_EOL; |
foreach ($edges as $edge) { | foreach ($edges as $edge) { |
add_edge($edge['head'], $edge['tail']); | add_edge($edge['head'], $edge['tail']); |
} | } |
echo ' </edges> | echo ' </edges> |
</graph> | </graph> |
</gexf>' . PHP_EOL; | </gexf>' . PHP_EOL; |
?> | ?> |