<commit_before><?php

error_reporting(~0);
ini_set('display_errors', 1);

$db_file = "data/airports.sqlite";
$messages = array();
$mode = "list";
$query = "";
$runways = 0;

if (!empty($_GET))
{
    if (isset($_GET['id']))
    {
        $mode = "id"; 
        $query = $_GET['id'];
        $query = strtoupper($query);
        $query = preg_replace("/[^[:alnum:]-]/", '', $query);
    }
    else if (isset($_GET['search']))
    {
        $mode = "search"; 
        $query = $_GET['search'];
        $query = strtoupper($query);
        $query = preg_replace("/%20/", ' ', $query);
        $query = preg_replace("/[^[:alnum:]- ]/", '', $query);
    }
    else if (isset($_GET['random']))
    {
      $mode = "random";
      if (isset($_GET['runways']) && is_numeric($_GET['runways']))
      {
        $runways = intval($_GET['runways']);
      }
    } 
}

class AirportsDB extends PDO 
{
    public function __construct($dsn, $username = null, $password = null, array $driver_options = null) 
    {
         parent :: __construct($dsn, $username, $password, $driver_options);
         $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $this->exec("CREATE TABLE IF NOT EXISTS airports (id TEXT, iata TEXT, name TEXT, type TEXT, country TEXT, city TEXT, lat1 DECIMAL(9,6), lon1 DECIMAL(9,6),  lat2 DECIMAL(9,6), lon2 DECIMAL(9,6), PRIMARY KEY (id));");
    }
    
    public function get_ids()
    {
        $ids = array();
        $result = $this->query('SELECT id FROM airports;');
        foreach ($result as $m) 
        {
            array_push($ids, $m['id']);
        }
        return $ids;
    }
    
    public function get_airport($id)
    {
      $result = $this->query('SELECT * FROM airports WHERE id IS "' . $id .'" COLLATE NOCASE LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      return array();
    }
    
    public function search_airport($query)
    {
      if ($query == "") 
      {
        return array();  
      }
      
      $result = $this->query('SELECT * FROM airports WHERE id IS "' . $query .'"  COLLATE NOCASE LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      
      $result = $this->query('SELECT * FROM airports WHERE iata IS "' . $query .'"  COLLATE NOCASE LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      
      $result = $this->query('SELECT * FROM airports WHERE name LIKE "%' . $query .'%"  COLLATE NOCASE LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      
      $result = $this->query('SELECT * FROM airports WHERE city LIKE "%' . $query .'%"  COLLATE NOCASE LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      
      return array();
    }
    
    public function get_random_airport($runways)
    {
      $result = $this->query('SELECT * FROM airports WHERE runways >= ' . $runways . ' ORDER BY RANDOM() LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      return array();<commit_msg>preferring larger airports when searching by name<commit_after><?php

error_reporting(~0);
ini_set('display_errors', 1);

$db_file = "data/airports.sqlite";
$messages = array();
$mode = "list";
$query = "";
$runways = 0;

if (!empty($_GET))
{
    if (isset($_GET['id']))
    {
        $mode = "id"; 
        $query = $_GET['id'];
        $query = strtoupper($query);
        $query = preg_replace("/[^[:alnum:]-]/", '', $query);
    }
    else if (isset($_GET['search']))
    {
        $mode = "search"; 
        $query = $_GET['search'];
        $query = strtoupper($query);
        $query = preg_replace("/%20/", ' ', $query);
        $query = preg_replace("/[^[:alnum:]- ]/", '', $query);
    }
    else if (isset($_GET['random']))
    {
      $mode = "random";
      if (isset($_GET['runways']) && is_numeric($_GET['runways']))
      {
        $runways = intval($_GET['runways']);
      }
    } 
}

class AirportsDB extends PDO 
{
    public function __construct($dsn, $username = null, $password = <PASSWORD>, array $driver_options = null) 
    {
         parent :: __construct($dsn, $username, $password, $driver_options);
         $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $this->exec("CREATE TABLE IF NOT EXISTS airports (id TEXT, iata TEXT, name TEXT, type TEXT, country TEXT, city TEXT, lat1 DECIMAL(9,6), lon1 DECIMAL(9,6),  lat2 DECIMAL(9,6), lon2 DECIMAL(9,6), PRIMARY KEY (id));");
    }
    
    public function get_ids()
    {
        $ids = array();
        $result = $this->query('SELECT id FROM airports;');
        foreach ($result as $m) 
        {
            array_push($ids, $m['id']);
        }
        return $ids;
    }
    
    public function get_airport($id)
    {
      $result = $this->query('SELECT * FROM airports WHERE id IS "' . $id .'" COLLATE NOCASE LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      return array();
    }
    
    public function search_airport($query)
    {
      if ($query == "") 
      {
        return array();  
      }
      
      $result = $this->query('SELECT * FROM airports WHERE id IS "' . $query .'"  COLLATE NOCASE LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      
      $result = $this->query('SELECT * FROM airports WHERE iata IS "' . $query .'"  COLLATE NOCASE LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      
      $result = $this->query('SELECT * FROM airports WHERE name LIKE "%' . $query .'%"  COLLATE NOCASE ORDER BY runways DESC LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      
      $result = $this->query('SELECT * FROM airports WHERE city LIKE "%' . $query .'%"  COLLATE NOCASE ORDER BY runways DESC LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      
      return array();
    }
    
    public function get_random_airport($runways)
    {
      $result = $this->query('SELECT * FROM airports WHERE runways >= ' . $runways . ' ORDER BY RANDOM() LIMIT 1;');
      foreach ($result as $m) 
      {
          return array("id" => $m["id"], "iata" => $m["iata"], "name" => $m["name"], "type" => $m["type"], "country" => $m["country"], "city" => $m["city"], 
                       "lat1" => $m["lat1"], "lng1" => $m["lng1"], "lat2" => $m["lat2"], "lng2" => $m["lng2"]);
      }
      return array();
{'fraction_non_alphanumeric': 0.2455376578145407, 'fraction_numerical': 0.01545494122768829, 'mean_word_length': 2.505913773368943, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 144, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2378045', 'n_tokens_mistral': 3360, 'n_tokens_neox': 3267, 'n_words': 733}