@@ 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 |
@@ 143-160 (lines=18) @@ | ||
140 | return $data; |
|
141 | } |
|
142 | ||
143 | public function getRecentMythic($mythic_pokemon) |
|
144 | { |
|
145 | $req = 'SELECT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
|
146 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
|
147 | FROM sightings |
|
148 | WHERE pokemon_id IN ('.implode(',', $mythic_pokemon).') |
|
149 | ORDER BY updated DESC |
|
150 | LIMIT 0,12'; |
|
151 | $result = $this->mysqli->query($req); |
|
152 | $data = array(); |
|
153 | if ($result->num_rows > 0) { |
|
154 | while ($row = $result->fetch_object()) { |
|
155 | $data[] = $row; |
|
156 | } |
|
157 | } |
|
158 | ||
159 | return $data; |
|
160 | } |
|
161 | ||
162 | /////////////////// |
|
163 | // Single Pokemon |
|
@@ 191-208 (lines=18) @@ | ||
188 | return $data; |
|
189 | } |
|
190 | ||
191 | public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
192 | { |
|
193 | $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS distime, pokemon_id as pokemon_id, FROM_UNIXTIME(expire_timestamp) as disappear_time, lat as latitude, lon as longitude, |
|
194 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
|
195 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS IV, move_1 as move_1, move_2, form |
|
196 | FROM sightings |
|
197 | WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
198 | ORDER BY $top_order_by $top_direction, expire_timestamp DESC |
|
199 | LIMIT 0,50"; |
|
200 | ||
201 | $result = $this->mysqli->query($req); |
|
202 | $top = array(); |
|
203 | while ($data = $result->fetch_object()) { |
|
204 | $top[] = $data; |
|
205 | } |
|
206 | ||
207 | return $top; |
|
208 | } |
|
209 | ||
210 | public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
211 | { |
|
@@ 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 |
@@ 142-159 (lines=18) @@ | ||
139 | return $data; |
|
140 | } |
|
141 | ||
142 | public function getRecentMythic($mythic_pokemon) |
|
143 | { |
|
144 | $req = 'SELECT pokemon_id, id as encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
|
145 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
|
146 | FROM pokemon |
|
147 | WHERE pokemon_id IN ('.implode(',', $mythic_pokemon).') |
|
148 | ORDER BY changed DESC |
|
149 | LIMIT 0,12'; |
|
150 | $result = $this->mysqli->query($req); |
|
151 | $data = array(); |
|
152 | if ($result->num_rows > 0) { |
|
153 | while ($row = $result->fetch_object()) { |
|
154 | $data[] = $row; |
|
155 | } |
|
156 | } |
|
157 | ||
158 | return $data; |
|
159 | } |
|
160 | ||
161 | /////////////////// |
|
162 | // Single Pokemon |
|
@@ 183-200 (lines=18) @@ | ||
180 | return $data; |
|
181 | } |
|
182 | ||
183 | public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
184 | { |
|
185 | $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS distime, pokemon_id as pokemon_id, FROM_UNIXTIME(expire_timestamp) as disappear_time, lat as latitude, lon as longitude, |
|
186 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
|
187 | iv AS IV, move_1 as move_1, move_2, form |
|
188 | FROM pokemon |
|
189 | WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
|
190 | ORDER BY $top_order_by $top_direction, expire_timestamp DESC |
|
191 | LIMIT 0,50"; |
|
192 | ||
193 | $result = $this->mysqli->query($req); |
|
194 | $top = array(); |
|
195 | while ($data = $result->fetch_object()) { |
|
196 | $top[] = $data; |
|
197 | } |
|
198 | ||
199 | return $top; |
|
200 | } |
|
201 | ||
202 | public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
203 | { |