<commit_before><?php

class MonkeyFork {
  public function get_gyms($swLat, $swLng, $neLat, $neLng, $tstamp = 0, $oSwLat = 0, $oSwLng = 0, $oNeLat = 0, $oNeLng = 0) {
    global $db;

	$query = "SELECT f.external_id as gym_id,
       fs.last_modified last_modified,
       f.latitude,
        f.longitude,
        f.name,
       fs.team team_id,
       fs.guard_pokemon_id,
       fs.slots_available,
       r.level raid_level,
       r.pokemon_id raid_pokemon_id,
       r.time_spawn,
       r.time_battle,
       r.time_end,
       r.cp raid_cp,
       r.move_1 raid_move_1,
       r.move_2 raid_move_2
FROM
  (SELECT f.id,
          f.lat latitude,
          f.lon longitude,
   		f.external_id,
   	    f.name,
          MAX(fs.id) fort_sighting_id
   FROM forts f
LEFT JOIN fort_sightings fs ON fs.fort_id = f.id
   WHERE f.lat > 38.59554697220179
     AND f.lon > -9.5130000327149
     AND f.lat < 38.92002611234014
     AND f.lon < -8.5901484702149
   GROUP BY f.id) f
LEFT JOIN fort_sightings fs ON fs.id = f.fort_sighting_id
LEFT JOIN raids r ON r.fort_id = f.id";

    $gyms = $db->query($query, [])->fetchAll(PDO::FETCH_ASSOC);

$data = array();
    foreach ($gyms as $gym) {
	$gym["enabled"] = true;
	$gym["pokemon"] = [];
	$gym["latitude"] = floatval($gym["latitude"]);
	$gym["longitude"] = floatval($gym["longitude"]);
	$gym["last_modified"] = $gym["last_modified"] * 1000;
	$data[$gym["gym_id"]] = $gym;
    }
	
    return $data;
  }
}<commit_msg>[add]monkey raids<commit_after><?php

class MonkeyFork {
  public function get_gym($gymId) {
    //Fill in the blank
    return array();
  }

  public function get_gyms($swLat, $swLng, $neLat, $neLng, $tstamp = 0, $oSwLat = 0, $oSwLng = 0, $oNeLat = 0, $oNeLng = 0) {
    global $db;

    // TODO: Should not be doing it here 
    $json_poke = "static/data/pokemon.json";
    $json_contents = file_get_contents($json_poke);
    $pokemon_data = json_decode($json_contents, TRUE);

    $conds = array();
    $params = array();

    $query = "SELECT f.external_id as gym_id,
      fs.last_modified last_modified,
      f.latitude,
      f.longitude,
      f.name,
      fs.team team_id,
      fs.guard_pokemon_id,
      fs.slots_available,
      r.level raid_level,
      r.pokemon_id raid_pokemon_id,
      r.time_battle raid_start,
      r.time_end raid_end,
      r.cp raid_pokemon_cp,
      r.move_1 raid_pokemon_move_1,
      r.move_2 raid_pokemon_move_2
        FROM
        (SELECT f.id,
         f.lat latitude,
         f.lon longitude,
         f.external_id,
         f.name,
         MAX(fs.id) fort_sighting_id,
         MAX(r.id) raid_id
         FROM forts f
         LEFT JOIN fort_sightings fs ON fs.fort_id = f.id
         LEFT JOIN raids r ON r.fort_id = f.id
         WHERE :conditions
         GROUP BY f.id) f
        LEFT JOIN fort_sightings fs ON fs.id = f.fort_sighting_id
        LEFT JOIN raids r ON r.id = f.raid_id";

    $conds[] = "f.lat > :swLat AND f.lon > :swLng AND f.lat < :neLat AND f.lon < :neLng";
    $params[':swLat'] = $swLat;
    $params[':swLng'] = $swLng;
    $params[':neLat'] = $neLat;
    $params[':neLng'] = $neLng;

    if ($swLat == 0) {
      $conds[] = "1 = 0";
    }

    if ($oSwLat != 0) {
      $conds[] = "NOT (f.lat > :oswLat AND f.lon > :oswLng AND f.lat < :oneLat AND f.lon < :oneLng)";
      $params[':oswLat'] = $oSwLat;
      $params[':oswLng'] = $oSwLng;
      $params[':oneLat'] = $oNeLat;
      $params[':oneLng'] = $oNeLng;
    }

    if ($tstamp != 0) {
      $conds[] = "fs.last_modified > :timestamp";
      $params[':timestamp'] = $tstamp;
    }

    $query = str_replace(":conditions", join(" AND ", $conds), $query); 

    $gyms = $db->query($query, $params)->fetchAll(PDO::FETCH_ASSOC);

    $data = array();
    foreach ($gyms as $gym) {
      $gym["enabled"] = true;
      $gym["pokemon"] = [];
      $gym["raid_pokemon_name"] = i8ln($pokemon_data[$gym["raid_pokemon_id"]]["name"]);
      $gym["latitude"] = floatval($gym["latitude"]);
      $gym["longitude"] = floatval($gym["longitude"]);
      $gym["last_modified"] = $gym["last_modified"] * 1000;
      $gym["raid_start"] = $gym["raid_start"] * 1000; // needs to be banged do that raid_start * 1000
      $gym["raid_end"] = $gym["raid_end"] * 1000; // something has to be changed here so that raid_end is *1000
      $data[$gym["gym_id"]] = $gym;
    }
    return $data;
  }
}
{'fraction_non_alphanumeric': 0.15689418231791114, 'fraction_numerical': 0.024736601007787448, 'mean_word_length': 2.5765765765765765, 'pattern_counts': {'":': 1, '<': 11, '<?xml version=': 0, '>': 14, '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': '1253628', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1734, 'n_words': 363}