| @@ 191-209 (lines=19) @@ | ||
| 188 | return $data; |
|
| 189 | } |
|
| 190 | ||
| 191 | public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 192 | { |
|
| 193 | $req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime, |
|
| 194 | pokemon_id, disappear_time, latitude, longitude, |
|
| 195 | cp, individual_attack, individual_defense, individual_stamina, |
|
| 196 | ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, |
|
| 197 | move_1, move_2, form |
|
| 198 | FROM pokemon |
|
| 199 | WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
| 200 | ORDER BY $top_order_by $top_direction, disappear_time DESC |
|
| 201 | LIMIT 0,50"; |
|
| 202 | $result = $this->mysqli->query($req); |
|
| 203 | $top = array(); |
|
| 204 | while ($data = $result->fetch_object()) { |
|
| 205 | $top[] = $data; |
|
| 206 | } |
|
| 207 | ||
| 208 | return $top; |
|
| 209 | } |
|
| 210 | ||
| 211 | public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 212 | { |
|
| @@ 216-229 (lines=14) @@ | ||
| 213 | return null; |
|
| 214 | } |
|
| 215 | ||
| 216 | public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 217 | { |
|
| 218 | $req = "SELECT latitude, longitude |
|
| 219 | FROM pokemon |
|
| 220 | WHERE pokemon_id = ".$pokemon_id." AND disappear_time BETWEEN '".$start."' AND '".$end."' |
|
| 221 | LIMIT 10000"; |
|
| 222 | $result = $this->mysqli->query($req); |
|
| 223 | $points = array(); |
|
| 224 | while ($data = $result->fetch_object()) { |
|
| 225 | $points[] = $data; |
|
| 226 | } |
|
| 227 | ||
| 228 | return $points; |
|
| 229 | } |
|
| 230 | ||
| 231 | public function getPokemonGraph($pokemon_id) |
|
| 232 | { |
|
| @@ 702-722 (lines=21) @@ | ||
| 699 | return $data; |
|
| 700 | } |
|
| 701 | ||
| 702 | private function getTrainerActivePokemon($trainer_name) |
|
| 703 | { |
|
| 704 | $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 705 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
|
| 706 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
|
| 707 | filtered_gymmember.gym_id, |
|
| 708 | CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, |
|
| 709 | '1' AS active |
|
| 710 | FROM gympokemon INNER JOIN |
|
| 711 | (SELECT gymmember.pokemon_uid, gymmember.gym_id, gymmember.deployment_time FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.deployment_time, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember |
|
| 712 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
|
| 713 | WHERE gympokemon.trainer_name='".$trainer_name."' |
|
| 714 | ORDER BY gympokemon.cp DESC"; |
|
| 715 | $result = $this->mysqli->query($req); |
|
| 716 | $pokemons = array(); |
|
| 717 | while ($data = $result->fetch_object()) { |
|
| 718 | $pokemons[] = $data; |
|
| 719 | } |
|
| 720 | ||
| 721 | return $pokemons; |
|
| 722 | } |
|
| 723 | ||
| 724 | private function getTrainerInactivePokemon($trainer_name) |
|
| 725 | { |
|
| @@ 724-744 (lines=21) @@ | ||
| 721 | return $pokemons; |
|
| 722 | } |
|
| 723 | ||
| 724 | private function getTrainerInactivePokemon($trainer_name) |
|
| 725 | { |
|
| 726 | $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 727 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
|
| 728 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
|
| 729 | null AS gym_id, |
|
| 730 | CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, |
|
| 731 | '0' AS active |
|
| 732 | FROM gympokemon LEFT JOIN |
|
| 733 | (SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember |
|
| 734 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
|
| 735 | WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."' |
|
| 736 | ORDER BY gympokemon.cp DESC"; |
|
| 737 | $result = $this->mysqli->query($req); |
|
| 738 | $pokemons = array(); |
|
| 739 | while ($data = $result->fetch_object()) { |
|
| 740 | $pokemons[] = $data; |
|
| 741 | } |
|
| 742 | ||
| 743 | return $pokemons; |
|
| 744 | } |
|
| 745 | ||
| 746 | ///////// |
|
| 747 | // Cron |
|
| @@ 472-488 (lines=17) @@ | ||
| 469 | // Raids |
|
| 470 | /////////// |
|
| 471 | ||
| 472 | public function getAllRaids($page) |
|
| 473 | { |
|
| 474 | $limit = ' LIMIT '.($page * 10).',10'; |
|
| 475 | $req = 'SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, FROM_UNIXTIME(r.time_spawn) AS spawn, FROM_UNIXTIME(r.time_battle) AS start, FROM_UNIXTIME(r.time_end) AS end, FROM_UNIXTIME(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude |
|
| 476 | FROM forts f |
|
| 477 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
|
| 478 | LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP()) |
|
| 479 | WHERE r.time_end > UNIX_TIMESTAMP() |
|
| 480 | ORDER BY r.level DESC, r.time_battle'.$limit; |
|
| 481 | $result = $this->mysqli->query($req); |
|
| 482 | $raids = array(); |
|
| 483 | while ($data = $result->fetch_object()) { |
|
| 484 | $raids[] = $data; |
|
| 485 | } |
|
| 486 | ||
| 487 | return $raids; |
|
| 488 | } |
|
| 489 | ||
| 490 | //////////////// |
|
| 491 | // Gym History |
|
| @@ 584-598 (lines=15) @@ | ||
| 581 | return array('last_page' => $last_page, 'data' => $history); |
|
| 582 | } |
|
| 583 | ||
| 584 | private function getHistoryForGymPokemon($gym_id, $last_modified) |
|
| 585 | { |
|
| 586 | $req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name |
|
| 587 | FROM gym_history_defenders ghd |
|
| 588 | JOIN gym_defenders gd ON ghd.defender_id = gd.external_id |
|
| 589 | WHERE ghd.fort_id = '".$gym_id."' AND date = '".$last_modified."' |
|
| 590 | ORDER BY gd.deployment_time"; |
|
| 591 | $result = $this->mysqli->query($req); |
|
| 592 | $pokemons = array(); |
|
| 593 | while ($data = $result->fetch_object()) { |
|
| 594 | $pokemons[$data->defender_id] = $data; |
|
| 595 | } |
|
| 596 | ||
| 597 | return $pokemons; |
|
| 598 | } |
|
| 599 | ||
| 600 | ////////////// |
|
| 601 | // Trainers |
|
| @@ 423-437 (lines=15) @@ | ||
| 420 | // Raids |
|
| 421 | /////////// |
|
| 422 | ||
| 423 | public function getAllRaids($page) |
|
| 424 | { |
|
| 425 | $limit = ' LIMIT '.($page * 10).',10'; |
|
| 426 | $req = 'SELECT id AS gym_id, raid_level AS level, raid_pokemon_id AS pokemon_id, raid_pokemon_cp AS cp, raid_pokemon_move_1 AS move_1, raid_pokemon_move_2 AS move_2, FROM_UNIXTIME(raid_spawn_timestamp) AS spawn, FROM_UNIXTIME(raid_battle_timestamp) AS start, FROM_UNIXTIME(raid_end_timestamp) AS end, FROM_UNIXTIME(updated) AS last_scanned, name, lat AS latitude, lon as longitude |
|
| 427 | FROM gym |
|
| 428 | WHERE raid_end_timestamp > UNIX_TIMESTAMP() |
|
| 429 | ORDER BY raid_level DESC, raid_battle_timestamp'.$limit; |
|
| 430 | $result = $this->mysqli->query($req); |
|
| 431 | $raids = array(); |
|
| 432 | while ($data = $result->fetch_object()) { |
|
| 433 | $raids[] = $data; |
|
| 434 | } |
|
| 435 | ||
| 436 | return $raids; |
|
| 437 | } |
|
| 438 | ||
| 439 | //////////////// |
|
| 440 | // Gym History |
|
| @@ 191-209 (lines=19) @@ | ||
| 188 | return $data; |
|
| 189 | } |
|
| 190 | ||
| 191 | public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 192 | { |
|
| 193 | $req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime, |
|
| 194 | pokemon_id, disappear_time, latitude, longitude, |
|
| 195 | cp, individual_attack, individual_defense, individual_stamina, |
|
| 196 | ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, |
|
| 197 | move_1, move_2, form |
|
| 198 | FROM pokemon |
|
| 199 | WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
| 200 | ORDER BY $top_order_by $top_direction, disappear_time DESC |
|
| 201 | LIMIT 0,50"; |
|
| 202 | $result = $this->mysqli->query($req); |
|
| 203 | $top = array(); |
|
| 204 | while ($data = $result->fetch_object()) { |
|
| 205 | $top[] = $data; |
|
| 206 | } |
|
| 207 | ||
| 208 | return $top; |
|
| 209 | } |
|
| 210 | ||
| 211 | public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 212 | { |
|
| @@ 234-247 (lines=14) @@ | ||
| 231 | return $toptrainer; |
|
| 232 | } |
|
| 233 | ||
| 234 | public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 235 | { |
|
| 236 | $req = "SELECT latitude, longitude |
|
| 237 | FROM pokemon |
|
| 238 | WHERE pokemon_id = ".$pokemon_id." AND disappear_time BETWEEN '".$start."' AND '".$end."' |
|
| 239 | LIMIT 10000"; |
|
| 240 | $result = $this->mysqli->query($req); |
|
| 241 | $points = array(); |
|
| 242 | while ($data = $result->fetch_object()) { |
|
| 243 | $points[] = $data; |
|
| 244 | } |
|
| 245 | ||
| 246 | return $points; |
|
| 247 | } |
|
| 248 | ||
| 249 | public function getPokemonGraph($pokemon_id) |
|
| 250 | { |
|
| @@ 720-740 (lines=21) @@ | ||
| 717 | return $data; |
|
| 718 | } |
|
| 719 | ||
| 720 | private function getTrainerActivePokemon($trainer_name) |
|
| 721 | { |
|
| 722 | $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 723 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
|
| 724 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
|
| 725 | filtered_gymmember.gym_id, |
|
| 726 | CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, |
|
| 727 | '1' AS active |
|
| 728 | FROM gympokemon INNER JOIN |
|
| 729 | (SELECT gymmember.pokemon_uid, gymmember.gym_id, gymmember.deployment_time FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.deployment_time, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember |
|
| 730 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
|
| 731 | WHERE gympokemon.trainer_name='".$trainer_name."' |
|
| 732 | ORDER BY gympokemon.cp DESC"; |
|
| 733 | $result = $this->mysqli->query($req); |
|
| 734 | $pokemons = array(); |
|
| 735 | while ($data = $result->fetch_object()) { |
|
| 736 | $pokemons[] = $data; |
|
| 737 | } |
|
| 738 | ||
| 739 | return $pokemons; |
|
| 740 | } |
|
| 741 | ||
| 742 | private function getTrainerInactivePokemon($trainer_name) |
|
| 743 | { |
|
| @@ 742-762 (lines=21) @@ | ||
| 739 | return $pokemons; |
|
| 740 | } |
|
| 741 | ||
| 742 | private function getTrainerInactivePokemon($trainer_name) |
|
| 743 | { |
|
| 744 | $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
| 745 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
|
| 746 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
|
| 747 | null AS gym_id, |
|
| 748 | CONVERT_TZ(filtered_gymmember.deployment_time, '+00:00', '".self::$time_offset."') as deployment_time, |
|
| 749 | '0' AS active |
|
| 750 | FROM gympokemon LEFT JOIN |
|
| 751 | (SELECT * FROM gymmember HAVING gymmember.gym_id <> '') AS filtered_gymmember |
|
| 752 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
|
| 753 | WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."' |
|
| 754 | ORDER BY gympokemon.cp DESC"; |
|
| 755 | $result = $this->mysqli->query($req); |
|
| 756 | $pokemons = array(); |
|
| 757 | while ($data = $result->fetch_object()) { |
|
| 758 | $pokemons[] = $data; |
|
| 759 | } |
|
| 760 | ||
| 761 | return $pokemons; |
|
| 762 | } |
|
| 763 | ||
| 764 | ///////// |
|
| 765 | // Cron |
|