Tidy up imports
[contractdashboard.git] / heuristics / valueHeuristics.php
blob:a/heuristics/valueHeuristics.php -> blob:b/heuristics/valueHeuristics.php
  <?php
  /* - large contract value
  - standard dev from mean/median
  - percent of total contracts for supplier/agency*/
  $heuristics["VALUE_LARGE_CONTRACT_OVERALL"] = Array(
  "description" => "unusual value for time of year");
  function METADATA_DUPLICATED_DESCRIPTION($cn)
  {
  $averageContractPeriod = getAverageContractPeriod();
  $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']);
  $days = intval($diff / 24);
  return ($days > 45 ? 1 : 0);
  }
   
- large contract value /* - peculiar value
- chi-square test for outliers / standard dev from mean/median - Just under 80k, amplified if other contracts with same supplier are just under
- percent of total contracts for supplier/agency */
  $heuristics["VALUE_NEAR_THRESHOLD"] = Array(
  "description" => "unusual value for time of year");
  /*
  - unusual variation amount - absolute value; large reductions as well as large increases
  */
  $heuristics["VALUE_LARGE_VARIATION"] = Array(
  "description" => "unusual value for time of year");
  function METADATA_DUPLICATED_DESCRIPTION($cn)
  {
  $averageContractPeriod = getAverageContractPeriod();
  $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']);
  $days = intval($diff / 24);
  return ($days > 45 ? 1 : 0);
  }
   
  /* - unusual value for time of year
- peculiar value - compare to all other records in last 2 weeks
- Just under 80k, amplified if other contracts with same supplier are just under - ie. many large contracts in june so takes more to standout*/
- unusual variation amount $heuristics["VALUE_HIGH_FOR_MONTH"] = Array(
- absolute value; large reductions as well as large increases "description" => "unusual value for time of year"
  );
  function VALUE_HIGH_FOR_MONTH($cn, $monthAsInt)
  {
  $averageContractPeriod = getAverageContractPeriod();
  $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']);
  $days = intval($diff / 24);
  return ($days > 45 ? 1 : 0);
  }
  $monthlyValueAverage = Array();
  function getAgencyTransactions($agencyName)
  {
  global $agencyTransactions;
  if (!$agencyTransactions[$agencyName]) {
  $query = 'select count(*) from contractnotice where agencyName = "' . $agencyName . '"';
  $result = mysql_query($query);
  $r = mysql_fetch_array($result, MYSQL_BOTH);
  $agencyTransactions[$agencyName] = $r[0];
  }
  return $agencyTransactions[$agencyName];
  }
  ?>