Permalink
Browse files

Fix cron jobs for pokedex counts and nests (#370)

* Fix nests cron (start/end time skipped for now)

* Fix pokedex counts cron

(do not use spawnpoint data which is really not required here)
  • Loading branch information...
michikrug authored and Obihoernchen committed Feb 2, 2019
1 parent 6d3aa9e commit 328b73ce26b3b6b1bc7c3057a86d36f968fa7952
Showing with 25 additions and 25 deletions.
  1. +16 −15 core/cron/nests.cron.php
  2. +9 −10 core/cron/pokedex_counts.cron.php
@@ -9,30 +9,31 @@
$pokemon_exclude_sql = "";
if (!empty($config->system->nest_exclude_pokemon)) {
$pokemon_exclude_sql = "AND p.pokemon_id NOT IN (".implode(",", $config->system->nest_exclude_pokemon).")";
$pokemon_exclude_sql = "AND pokemon_id NOT IN (".implode(",", $config->system->nest_exclude_pokemon).")";
}
$req = "SELECT p.pokemon_id, max(p.latitude) AS latitude, max(p.longitude) AS longitude, count(p.pokemon_id) AS total_pokemon, s.kind, s.latest_seen
FROM pokemon p
INNER JOIN spawnpoint s ON (p.spawnpoint_id = s.id)
WHERE p.disappear_time > UTC_TIMESTAMP() - INTERVAL 24 HOUR
".$pokemon_exclude_sql."
GROUP BY p.spawnpoint_id, p.pokemon_id
HAVING count(p.pokemon_id) >= 6
ORDER BY p.pokemon_id";
$req = "SELECT spawnpoint_id, pokemon_id, max(latitude) AS latitude, max(longitude) AS longitude, count(pokemon_id) AS total_pokemon
FROM pokemon
WHERE disappear_time > (UTC_TIMESTAMP() - INTERVAL 24 HOUR)
".$pokemon_exclude_sql."
GROUP BY spawnpoint_id, pokemon_id
HAVING count(pokemon_id) >= 6
ORDER BY pokemon_id";
$result = $mysqli->query($req);
while ($data = $result->fetch_object()) {
$nests['pid'] = $data->pokemon_id;
$nests['c'] = $data->total_pokemon;
$nests['lat'] = $data->latitude;
$nests['lng'] = $data->longitude;
$starttime = $data->latest_seen - substr_count($data->kind, "s") * 900;
if ($starttime < 0) {
$starttime = 3600 + $starttime;
}
$nests['st'] = sprintf('%02d', floor($starttime / 60));
$nests['et'] = sprintf('%02d', floor($data->latest_seen / 60));
// $starttime = $data->latest_seen - substr_count($data->kind, "s") * 900;
// if ($starttime < 0) {
// $starttime = 3600 + $starttime;
// }
// $nests['st'] = sprintf('%02d', floor($starttime / 60));
// $nests['et'] = sprintf('%02d', floor($data->latest_seen / 60));
$nests['st'] = '00';
$nests['et'] = '00';
// Add the data to array
$nestsdatas[] = $nests;
@@ -25,18 +25,17 @@
$last_update = $newpokecountdatas[$pid]['last_update'];
$where = "WHERE p.pokemon_id = '".$pid."' AND (UNIX_TIMESTAMP(p.disappear_time) - (LENGTH(s.kind) - LENGTH( REPLACE ( kind, \"s\", \"\") )) * 900) > '".$last_update."'";
$req = "SELECT count, (UNIX_TIMESTAMP(p.disappear_time) - (LENGTH(s.kind) - LENGTH( REPLACE ( kind, \"s\", \"\") )) * 900) as last_timestamp, (CONVERT_TZ(p.disappear_time, '+00:00', '".$time_offset."')) AS disappear_time_real, p.latitude, p.longitude
$where = "WHERE p.pokemon_id = '".$pid."' AND UNIX_TIMESTAMP(p.last_modified) > '".$last_update."'";
$req = "SELECT count, UNIX_TIMESTAMP(last_modified) as last_modified, (CONVERT_TZ(disappear_time, '+00:00', '".$time_offset."')) AS disappear_time_real, latitude, longitude
FROM pokemon p
JOIN spawnpoint s ON p.spawnpoint_id = s.id
JOIN (
SELECT count(*) as count
LEFT JOIN (
SELECT p.pokemon_id, count(*) as count
FROM pokemon p
JOIN spawnpoint s ON p.spawnpoint_id = s.id
" . $where."
".$where."
) x
" . $where . "
ORDER BY last_timestamp DESC
ON x.pokemon_id = p.pokemon_id
".$where."
ORDER BY last_modified DESC
LIMIT 0,1";
$result = $mysqli->query($req);
$data = $result->fetch_object();
@@ -49,7 +48,7 @@
if ($count != 0) {
$newpokecountdatas[$pid]['count'] += $count;
$newpokecountdatas[$pid]['last_update'] = $data->last_timestamp;
$newpokecountdatas[$pid]['last_update'] = $data->last_modified;
$newpokecountdatas[$pid]['disappear_time'] = $data->disappear_time_real;
$newpokecountdatas[$pid]['latitude'] = $data->latitude;
$newpokecountdatas[$pid]['longitude'] = $data->longitude;

0 comments on commit 328b73c

Please sign in to comment.