<commit_before><?php

class DataBorrasca {
	
	public $openweathermapsApiKey = null;
	public $language = 'en';
	public $dataOrigin = 'real';
	public $geolocation = null;
	public $timezone = 'Europe/Madrid';
	public $location = 'en';
  public $resultLimit = 10;
  private $openweathermapUrl = 'http://api.openweathermap.org/data/2.5/weather';
  private $aemetXmlUrl = 'http://www.aemet.es/xml/municipios/localidad_';
  private $weirdCharacters = array('á', 'é', 'í', 'ó', 'ú', 'ü', 'à', 'è', 'ì', 'ò', 'ù', 'Á', 'É', 'Í', 'Ó', 'Ú', 'Ü', 'À', 'È', 'Ì', 'Ò', 'Ù');
  private $safeCharacters =  array('a', 'e', 'i', 'o', 'u', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'u', 'a', 'e', 'i', 'o', 'u');
	
	public function pageNowAndHere () {
		$text = file_get_contents($this->openweathermapUrl.'?lat='.$this->geolocation[0].'&lon='.$this->geolocation[1].'&units=metric&mode=json&lang='.$this->language.'&APPID='.$this->openweathermapsApiKey);
		return '{"now": '.$text.'}';
	}
	
	public function pageDetail () {
		$data = array();
		$data['hour'] = $this->dateAfterTimezoneOffset('G', $this->timezone);
		$data['day'] = $this->dateAfterTimezoneOffset('j', $this->timezone);

		$data['now'] = json_decode(file_get_contents($this->openweathermapUrl.'?q='.$this->location.',es&units=metric&mode=json&lang='.$this->language.'&APPID='.$this->openweathermapsApiKey));
		
		return json_encode($data);
	}
	public function pageSearch () {
    $searched = $this->location;

    // SQLITE CONNECT
    $data = array();
    try  {
      $db = new PDO("sqlite:../../data/locations.sqlite");

      $result = $db->query("SELECT id_region, id_location, name_location FROM locations WHERE name_location LIKE '%".$searched."%' LIMIT ".$this->resultLimit);

      $data['result'] = 'OK';
      $data['searched'] = $searched;
      if (count($result) > 0 and strlen($searched) > 0) {
        $data['result_message'] = 'Results fetched';
        $data['locations'] = array();
        $i = 0;
        foreach ($result as $row) {
          $data['locations'][$i] = Array();
          $data['locations'][$i]['name'] = $row['name_location'];
          $data['locations'][$i]['link'] = $row['id_region'].$row['id_location'];
          $i++;
        }
      } else {
        $data['result_message'] = 'No results';
        $data['locations'] = null;
      }
    } catch(PDOException $e) {
      echo $e->getMessage();
      $data['result'] = 'ERROR';
      $data['result_message'] = 'Database not loaded successfully';
    }

    return json_encode($data);
  }
  
  public function locationsGeolocate () {
    //http://es.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
    $url = 'http://nominatim.openstreetmap.org/search?city=@CITY@&country=Spain&format=jsonv2';
  }
  
  public function makeLocationsSearchable () {
    $pattern = "/, (las|los|el|la|a|o|l'|els|les)$/";
    try  {
    $db = new PDO("sqlite:../data/locations.sqlite");
    $result = $db->query("SELECT * FROM locations WHERE name_searchable IS NULL LIMIT 100");
    if (count($result) > 0) {
      foreach ($result as $row) {
        $searchable_location = strtolower($row['name_location']);
        if (preg_match($pattern, strtolower($row['name_location']), $matches)) {
          $fragments = explode(', ', $searchable_location);
          $searchable_location = $fragments[1].' '.$fragments[0];
        }
        $searchable_location = str_replace($this->weirdCharacters, $this->safeCharacters, $searchable_location);
        $db->query("UPDATE locations SET name_searchable='".$searchable_location."' WHERE id_region='".$row['id_region']."' AND	id_location='".$row['id_location']."'");
        echo '<p>'.$row['name_location'].' ----> '.$searchable_location.'</p>';
      }
    }
    } catch(PDOException $e) {<commit_msg>changed to 1000<commit_after><?php

class DataBorrasca {
	
	public $openweathermapsApiKey = null;
	public $language = 'en';
	public $dataOrigin = 'real';
	public $geolocation = null;
	public $timezone = 'Europe/Madrid';
	public $location = 'en';
  public $resultLimit = 10;
  private $openweathermapUrl = 'http://api.openweathermap.org/data/2.5/weather';
  private $aemetXmlUrl = 'http://www.aemet.es/xml/municipios/localidad_';
  private $weirdCharacters = array('á', 'é', 'í', 'ó', 'ú', 'ü', 'à', 'è', 'ì', 'ò', 'ù', 'Á', 'É', 'Í', 'Ó', 'Ú', 'Ü', 'À', 'È', 'Ì', 'Ò', 'Ù');
  private $safeCharacters =  array('a', 'e', 'i', 'o', 'u', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'u', 'a', 'e', 'i', 'o', 'u');
	
	public function pageNowAndHere () {
		$text = file_get_contents($this->openweathermapUrl.'?lat='.$this->geolocation[0].'&lon='.$this->geolocation[1].'&units=metric&mode=json&lang='.$this->language.'&APPID='.$this->openweathermapsApiKey);
		return '{"now": '.$text.'}';
	}
	
	public function pageDetail () {
		$data = array();
		$data['hour'] = $this->dateAfterTimezoneOffset('G', $this->timezone);
		$data['day'] = $this->dateAfterTimezoneOffset('j', $this->timezone);

		$data['now'] = json_decode(file_get_contents($this->openweathermapUrl.'?q='.$this->location.',es&units=metric&mode=json&lang='.$this->language.'&APPID='.$this->openweathermapsApiKey));
		
		return json_encode($data);
	}
	public function pageSearch () {
    $searched = $this->location;

    // SQLITE CONNECT
    $data = array();
    try  {
      $db = new PDO("sqlite:../../data/locations.sqlite");

      $result = $db->query("SELECT id_region, id_location, name_location FROM locations WHERE name_location LIKE '%".$searched."%' LIMIT ".$this->resultLimit);

      $data['result'] = 'OK';
      $data['searched'] = $searched;
      if (count($result) > 0 and strlen($searched) > 0) {
        $data['result_message'] = 'Results fetched';
        $data['locations'] = array();
        $i = 0;
        foreach ($result as $row) {
          $data['locations'][$i] = Array();
          $data['locations'][$i]['name'] = $row['name_location'];
          $data['locations'][$i]['link'] = $row['id_region'].$row['id_location'];
          $i++;
        }
      } else {
        $data['result_message'] = 'No results';
        $data['locations'] = null;
      }
    } catch(PDOException $e) {
      echo $e->getMessage();
      $data['result'] = 'ERROR';
      $data['result_message'] = 'Database not loaded successfully';
    }

    return json_encode($data);
  }
  
  public function locationsGeolocate () {
    //http://es.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
    $url = 'http://nominatim.openstreetmap.org/search?city=@CITY@&country=Spain&format=jsonv2';
  }
  
  public function makeLocationsSearchable () {
    $pattern = "/, (las|los|el|la|a|o|l'|els|les)$/";
    try  {
    $db = new PDO("sqlite:../data/locations.sqlite");
    $result = $db->query("SELECT * FROM locations WHERE name_searchable IS NULL LIMIT 1000");
    if (count($result) > 0) {
      foreach ($result as $row) {
        $searchable_location = strtolower($row['name_location']);
        if (preg_match($pattern, strtolower($row['name_location']), $matches)) {
          $fragments = explode(', ', $searchable_location);
          $searchable_location = $fragments[1].' '.$fragments[0];
        }
        $searchable_location = str_replace($this->weirdCharacters, $this->safeCharacters, $searchable_location);
        $db->query("UPDATE locations SET name_searchable='".$searchable_location."' WHERE id_region='".$row['id_region']."' AND	id_location='".$row['id_location']."'");
        echo '<p>'.$row['name_location'].' ----> '.$searchable_location.'</p>';
      }
    }
    } catch(PDOException $e) {
{'fraction_non_alphanumeric': 0.21916721744877726, 'fraction_numerical': 0.006741573033707865, 'mean_word_length': 3.767485822306238, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4008608', 'n_tokens_mistral': 2740, 'n_tokens_neox': 2642, 'n_words': 472}