Skip to content
Permalink
Browse files

Combine PR #353 with #363 & Code formatting (#371)

* added no_lures to default config

* Implementet no_lures

* Separated no gyms and show raids on homepage

* added missing setting in example

* styling fixes

* === not ==

* Scrutinizer Auto-Fixes

This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com

* Revert "Scrutinizer Auto-Fixes"

* fix code style

* tab not spaces

* .

* .

* last style fix

* get pokecountdata in crontabs.include

* add IDE files to .gitigonore

* updatet how counts are stored

* remove from data loader

* make scrutinizer happy

* remove lures from dashboard as well

* Update aru.php

* Added query.php and basic quieries for monocle and rocketmap & implemented in tester.php

* woops - the lines in data_loader where in use

* Added support in homepage

* finisched data.loader

* moved to classes instead

* close mysqli on destruct

* added gyms and stops

* add default values for all 801 pokemon

* fixes

* added raids

* added trainers in aru

* finished aru.php

* added trainer graph

* renames

* finished cron

* fixes

* styling fixes

* fixed time_offset for RocketMap

* renamed Hydro to Alt

* revert name change

* add example

* add posgresql for monocle-alt + fixes

* fix nest spawn time

* fix error when no active raids

* Fix Monocle-Alt-Psql tester

* fix monocle mysql

* replace && with AND in quieries

* fix empty last scanned

* init $nestsdatas

* fix getPokemonSinceLastUpdate query logic

* fix pokemon count

* fix top50

* fix top trainers

* removed unused select

* fix typos

* fix nests

* fix netst times

* fixed nest spawn times

* fix nest times

* fix pokemon count for monocle

* use spawn instead of despawn time

* fixe error if file is countfiles are empty

* Added Gymhistory (Not support for Monocle yet)

* fix $_GET used in QueryManagers

* Fixed seen per day

* fix getGymData

* Update home.page.php

* Update aru.php

* make getRecentMythic faster

* make getRecentMythic faster

* add Trainers and GymHistory

* fix recent

* Update QueryManagerMysqlMonocleAlternate.php

* Update QueryManagerPostgresqlMonocleAlternate.php

* Update QueryManagerMysqlMonocleAlternate.php

* Update QueryManagerPostgresqlMonocleAlternate.php

* Update QueryManagerMysqlMonocleAlternate.php

* Update QueryManagerPostgresqlMonocleAlternate.php

* Update QueryManagerMysqlMonocleAlternate.php

* Update QueryManagerPostgresqlMonocleAlternate.php

* fixes

* fix pokemon depolyment time

* Update trainer.content.js

* Update trainer.content.js

* Update trainer.content.js

* Update trainer.content.js

* Update trainer.content.js

* improve some pokemon-page queries

* fix conflict

* fix getTrainerLevelCount for RocketMap

* Improve Pokemon and Raid count storage

* Add Create Stats sql

* fix CreateStatsRocketMap.sql

* # This is a combination of 20 commits.
# The first commit's message is:
improve nests

# The 2nd commit message will be skipped:

#	remove debug comment

# The 3rd commit message will be skipped:

#	update variables example

# The 4th commit message will be skipped:

#	Update index.php

# The 5th commit message will be skipped:

#	scale by size

# The 6th commit message will be skipped:

#	remove

# The 7th commit message will be skipped:

#	add simple support for relations

# The 8th commit message will be skipped:

#	fix woops

# The 9th commit message will be skipped:

#	fix typo and improve error check

# The 10th commit message will be skipped:

#	Update nests.cron.php

# The 11th commit message will be skipped:

#	nature_reserve is not a nest

# The 12th commit message will be skipped:

#	Fix fast update

# The 13th commit message will be skipped:

#	fix order + fix 12h update

# The 14th commit message will be skipped:

#	Update crontabs.include.php

# The 15th commit message will be skipped:

#	Save last update date in case of abort

# The 16th commit message will be skipped:

#	use $prevNestTime

# The 17th commit message will be skipped:

#	improve memory usage (maybe?)

# The 18th commit message will be skipped:

#	fix if core/json/nests.parks.json doesn't exist

# The 19th commit message will be skipped:

#	improved multipolygon

# The 20th commit message will be skipped:

#	run 12h update from 12-24 after migration

* add option for min nest size

* split nest calc into 0.5x0.5 areas

* hide nest inside nests of same pokemon + fixes and improvements

* fix for relations with multiple polygons

* garden is leisure not landuse

* How did this get here?

* Update nests.cron.php

* fix osm query date and reorder it

* Fix timezone in CreateStatsRocketMap

* fix timezone in CreateStatsRocketMap.sql

* fix getTop50Trainers

* fix getTop50Trainers

* Update CreateStatsRocketMap.sql

* Update CreateStatsRocketMap.sql

* fix timezone in nest update timing

* fix Postgre - Monocle

* fix Postgre - Monocle

* Fix QueryManagerPostgresqlMonocleAlternate

* Format php files

* Format Rocketmap queries

* Temporary disable start and end times of nests spawns

* Fix broken queries

* Format php files

* Fix nest query

* Readd css to cached files

* Minor fix

* Use namespaces

* Minor fix

* Check for file existence
  • Loading branch information...
michikrug authored and Obihoernchen committed Apr 1, 2019
1 parent 328b73c commit 9cdd6ede8b1b8ce6d01f3e639b15e7ddab6bfe04
Showing with 5,723 additions and 3,088 deletions.
  1. +1 −0 .gitignore
  2. +62 −0 CreateStatsMonocle.sql
  3. +62 −0 CreateStatsRocketMap.sql
  4. +26 −27 config.example.php
  5. +59 −61 core/cron/captcha.cron.php
  6. +66 −47 core/cron/crontabs.include.php
  7. +4 −22 core/cron/gym.cron.php
  8. +232 −34 core/cron/nests.cron.php
  9. +0 −65 core/cron/pokedex_counts.cron.php
  10. +0 −61 core/cron/pokedex_raids.cron.php
  11. +38 −42 core/cron/pokedex_rarity.cron.php
  12. +9 −20 core/cron/pokemon.cron.php
  13. +4 −15 core/cron/pokestop.cron.php
  14. +136 −135 core/inc/meta.inc.php
  15. +98 −107 core/js/dashboard.graph.js.php
  16. +1 −1 core/js/gymhistory.content.js
  17. +189 −30 core/js/nests.maps.js.php
  18. +22 −24 core/js/pokemon.graph.js.php
  19. +6 −2 core/js/trainer.content.js
  20. +21 −49 core/js/trainer.graph.js.php
  21. +6 −1 core/json/locales/DE/translations.json
  22. +6 −1 core/json/locales/EN/translations.json
  23. +0 −1 core/json/pokedex.counts.json
  24. +0 −1 core/json/pokedex.raids.json
  25. +4 −3 core/json/variables.examples.json
  26. +673 −949 core/process/aru.php
  27. +289 −409 core/process/data.loader.php
  28. +184 −181 core/process/locales.loader.php
  29. +137 −0 core/process/queries/QueryManager.php
  30. +40 −0 core/process/queries/QueryManagerMysql.php
  31. +781 −0 core/process/queries/QueryManagerMysqlMonocleAlternate.php
  32. +814 −0 core/process/queries/QueryManagerMysqlRocketmap.php
  33. +34 −0 core/process/queries/QueryManagerPostgresql.php
  34. +782 −0 core/process/queries/QueryManagerPostgresqlMonocleAlternate.php
  35. +2 −2 core/process/timezone.loader.php
  36. +332 −225 functions.php
  37. +1 −1 htaccess
  38. +106 −103 index.php
  39. +62 −77 install/tester.php
  40. +1 −1 pages/404.page.php
  41. +30 −22 pages/dashboard.page.php
  42. +29 −27 pages/gym.page.php
  43. +10 −10 pages/gymhistory.page.php
  44. +95 −84 pages/home.page.php
  45. +9 −2 pages/nests.page.php
  46. +16 −14 pages/pokedex.page.php
  47. +187 −175 pages/pokemon.page.php
  48. +17 −17 pages/pokestops.page.php
  49. +7 −7 pages/raids.page.php
  50. +33 −33 pages/trainer.page.php
@@ -29,4 +29,5 @@ config.php
/core/json/pokedex.raids.json
/core/json/captcha.stats.json
/core/json/nests.stats.json
/core/json/nests.parks.json
analyticstracking.php
@@ -0,0 +1,62 @@
# POKEMON
CREATE TABLE pokemon_stats (
pid smallint(6) NOT NULL,
count int(11) NOT NULL,
last_seen int(11) NOT NULL,
latitude double(18,14) NOT NULL,
longitude double(18,14) NOT NULL,
PRIMARY KEY (pid)
);

INSERT INTO pokemon_stats
SELECT pokemon_id, COUNT(*), MAX(expire_timestamp), 0.0, 0.0
FROM sightings
GROUP BY pokemon_id;

CREATE TRIGGER sightings_inserted
AFTER INSERT ON sightings
FOR EACH ROW
INSERT INTO pokemon_stats
VALUES
(NEW.pokemon_id, 1, NEW.expire_timestamp, NEW.lat, NEW.lon)
ON DUPLICATE KEY UPDATE
count = count + 1,
last_seen = NEW.expire_timestamp,
latitude = NEW.lat,
longitude = NEW.lon;



# RAIDS
CREATE TABLE raid_stats (
pid smallint(6) NOT NULL,
count int(11) NOT NULL,
last_seen int(11) NOT NULL,
latitude double(18,14) NOT NULL,
longitude double(18,14) NOT NULL,
PRIMARY KEY (pid)
);

INSERT INTO raid_stats
SELECT pokemon_id, COUNT(*), MAX(time_end), 0.0, 0.0
FROM raids
WHERE pokemon_id IS NOT NULL
GROUP BY pokemon_id;

DELIMITER $$
CREATE TRIGGER raids_updated
BEFORE UPDATE ON raids
FOR EACH ROW BEGIN
SELECT lat, lon FROM forts WHERE id = NEW.fort_id INTO @lat, @lon;
IF (OLD.pokemon_id IS NULL AND NEW.pokemon_id IS NOT NULL) THEN
INSERT INTO raid_stats
VALUES
(NEW.pokemon_id, 1, NEW.time_end, @lat, @lon)
ON DUPLICATE KEY UPDATE
count = count + 1,
last_seen = NEW.time_end,
latitude = @lat,
longitude = @lon;
END IF;
END$$
DELIMITER ;
@@ -0,0 +1,62 @@
# POKEMON
CREATE TABLE pokemon_stats (
pid smallint(6) NOT NULL,
count int(11) NOT NULL,
last_seen int(11) NOT NULL,
latitude double(18,14) NOT NULL,
longitude double(18,14) NOT NULL,
PRIMARY KEY (pid)
);

INSERT INTO pokemon_stats
SELECT pokemon_id, COUNT(*), UNIX_TIMESTAMP(CONVERT_TZ(MAX(disappear_time), '+00:00', @@time_zone)), 0.0, 0.0
FROM pokemon
GROUP BY pokemon_id;

CREATE TRIGGER pokemon_inserted
AFTER INSERT ON pokemon
FOR EACH ROW
INSERT INTO pokemon_stats
VALUES
(NEW.pokemon_id, 1, UNIX_TIMESTAMP(CONVERT_TZ(NEW.disappear_time, '+00:00', @@time_zone)), NEW.latitude, NEW.longitude)
ON DUPLICATE KEY UPDATE
count = count + 1,
last_seen = UNIX_TIMESTAMP(CONVERT_TZ(NEW.disappear_time, '+00:00', @@time_zone)),
latitude = NEW.latitude,
longitude = NEW.longitude;



# RAIDS
CREATE TABLE raid_stats (
pid smallint(6) NOT NULL,
count int(11) NOT NULL,
last_seen int(11) NOT NULL,
latitude double(18,14) NOT NULL,
longitude double(18,14) NOT NULL,
PRIMARY KEY (pid)
);

INSERT INTO raid_stats
SELECT pokemon_id, COUNT(*), UNIX_TIMESTAMP(CONVERT_TZ(MAX(end), '+00:00', @@time_zone)), 0.0 ,0.0
FROM raid
WHERE pokemon_id IS NOT NULL
GROUP BY pokemon_id;

DELIMITER $$
CREATE TRIGGER raid_updated
BEFORE UPDATE ON raid
FOR EACH ROW BEGIN
SELECT latitude, longitude FROM gym WHERE gym_id = NEW.gym_id INTO @lat, @lon;
IF (OLD.pokemon_id IS NULL AND NEW.pokemon_id IS NOT NULL) THEN
INSERT INTO raid_stats
VALUES
(NEW.pokemon_id, 1, UNIX_TIMESTAMP(CONVERT_TZ(NEW.end, '+00:00', @@time_zone)), @lat, @lon)
ON DUPLICATE KEY UPDATE
count = count + 1,
last_seen = UNIX_TIMESTAMP(CONVERT_TZ(NEW.end, '+00:00', @@time_zone)),
latitude = @lat,
longitude = @lon;
END IF;
END$$
DELIMITER ;
@@ -5,22 +5,22 @@
* A single location to store configuration.
*/
// EDIT ME PLEASE
# EDIT ME PLEASE
// mysql db name
// db name
define('SYS_DB_NAME', '#SYS_DB_NAME#');
// mysql username
// db username
define('SYS_DB_USER', '#SYS_DB_USER#');
// mysql password
// db password
define('SYS_DB_PSWD', '#SYS_DB_PSWD#');
// mysql server name
// db server name
define('SYS_DB_HOST', '#SYS_DB_HOST#');
// mysql server port
// db server port
define('SYS_DB_PORT', 3306);
// db scanner type
define('SYS_DB_TYPE', 'rocketmap'); // 'rocketmap', 'monocle-alt-mysql' or 'monocle-alt-pgsql'
# Please, do not touch me, I'm fine ;)
// Please, do not touch me, I'm fine ;)
// full path
define('SYS_PATH', realpath(dirname(__FILE__)));
@@ -29,30 +29,29 @@
// debug mode
define('SYS_DEVELOPMENT_MODE', false);
if (directory() != '') {
$subdirectory = '/'.directory().'/';
if ('' != directory()) {
$subdirectory = '/'.directory().'/';
} else {
$subdirectory = '/';
$subdirectory = '/';
}
if (isset($_SERVER['HTTP_HOST'])) {
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
define('HOST_URL', $_SERVER['HTTP_X_FORWARDED_PROTO'].'://'.$_SERVER['HTTP_HOST'].$subdirectory);
} else if (isset($_SERVER['REQUEST_SCHEME'])) {
define('HOST_URL', $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$subdirectory);
} else {
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
define('HOST_URL', 'https://'.$_SERVER['HTTP_HOST'].$subdirectory);
} else {
define('HOST_URL', 'http://'.$_SERVER['HTTP_HOST'].$subdirectory);
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
define('HOST_URL', $_SERVER['HTTP_X_FORWARDED_PROTO'].'://'.$_SERVER['HTTP_HOST'].$subdirectory);
} elseif (isset($_SERVER['REQUEST_SCHEME'])) {
define('HOST_URL', $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$subdirectory);
} else {
if (isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS']) {
define('HOST_URL', 'https://'.$_SERVER['HTTP_HOST'].$subdirectory);
} else {
define('HOST_URL', 'http://'.$_SERVER['HTTP_HOST'].$subdirectory);
}
}
}
## Subdirectory trick
//# Subdirectory trick
function directory()
{
##https://stackoverflow.com/questions/2090723/how-to-get-the-relative-directory-no-matter-from-where-its-included-in-php
return substr(str_replace('\\', '/', realpath(dirname(__FILE__))), strlen(str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT']))) + 1);
//#https://stackoverflow.com/questions/2090723/how-to-get-the-relative-directory-no-matter-from-where-its-included-in-php
return substr(str_replace('\\', '/', realpath(dirname(__FILE__))), strlen(str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT']))) + 1);
}
@@ -1,4 +1,5 @@
<?php
// -----------------------------------------------------------------------------------------------------------
// Pokestops datas
// Total pokestops
@@ -7,76 +8,73 @@
$captcha_file = SYS_PATH.'/core/json/captcha.stats.json';
if (is_file($captcha_file)) {
$capdatas = json_decode(file_get_contents($captcha_file), true);
// Trim json stats files to last 7 days of data
$capdatas = trim_stats_json($capdatas, $timestamp_lastweek);
$capdatas = json_decode(file_get_contents($captcha_file), true);
// Trim json stats files to last 7 days of data
$capdatas = trim_stats_json($capdatas, $timestamp_lastweek);
}
$variables_secret = SYS_PATH.'/core/json/variables.secret.json';
$config_secret = json_decode(file_get_contents($variables_secret));
if ($config_secret->captcha_key == "") {
$captcha['timestamp'] = $timestamp;
// get amount of accounts requiring a captcha
$req = "SELECT SUM(accounts_captcha) AS total FROM mainworker";
$result = $mysqli->query($req);
$data = $result->fetch_object();
$captcha['captcha_accs'] = $data->total;
// Add the datas in file
$capdatas[] = $captcha;
if ('' == $config_secret->captcha_key) {
$captcha['timestamp'] = $timestamp;
// get amount of accounts requiring a captcha
$data = $manager->getCaptchaCount();
$captcha['captcha_accs'] = $data->total;
// Add the datas in file
$capdatas[] = $captcha;
} else {
if (!empty($capdatas)) {
$lastCaptcha = array_pop($capdatas);
} else {
$lastCaptcha["timestamp"] = strtotime("-7 days", strtotime(date("Y-m-d")));
}
$lastCaptchaDate = date("Y-m-d", $lastCaptcha["timestamp"]);
$startTime = strtotime($lastCaptchaDate);
$endTime = strtotime(date("Y-m-d")) + date("Z");
$timeDiff = abs($endTime - $startTime);
$numberDays = intval($timeDiff / 86400); // 86400 seconds in one day
if ($numberDays > 7) {
$numberDays = 7;
}
while ($numberDays >= 0) {
$day = $endTime - ($numberDays * 86400);
$captchaUrl =
"http://2captcha.com/res.php?key=".
$config_secret->captcha_key."&action=getstats&date=".date("Y-m-d", $day);
if (!empty($capdatas)) {
$lastCaptcha = array_pop($capdatas);
} else {
$lastCaptcha['timestamp'] = strtotime('-7 days', strtotime(date('Y-m-d')));
}
$lastCaptchaDate = date('Y-m-d', $lastCaptcha['timestamp']);
$startTime = strtotime($lastCaptchaDate);
$endTime = strtotime(date('Y-m-d')) + date('Z');
$timeDiff = abs($endTime - $startTime);
$numberDays = intval($timeDiff / 86400); // 86400 seconds in one day
if ($numberDays > 7) {
$numberDays = 7;
}
while ($numberDays >= 0) {
$day = $endTime - ($numberDays * 86400);
$captchaUrl =
'http://2captcha.com/res.php?key='.
$config_secret->captcha_key.'&action=getstats&date='.date('Y-m-d', $day);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $captchaUrl);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$fileContents = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
echo "\n<br />";
$fileContents = '';
} else {
curl_close($ch);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $captchaUrl);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$fileContents = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
echo "\n<br />";
$fileContents = '';
} else {
curl_close($ch);
}
if (!is_string($fileContents) || !strlen($fileContents)) {
echo "Failed to get contents.";
$fileContents = '';
}
$capXml = simplexml_load_string($fileContents);
if (!is_string($fileContents) || !strlen($fileContents)) {
echo 'Failed to get contents.';
$fileContents = '';
}
$capXml = simplexml_load_string($fileContents);
foreach ($capXml as $key => $value) {
if (($numberDays == 0
&& ((int) $value->Attributes()->hour >= (int) date("H", $lastCaptcha["timestamp"])
&& ((int) $value->Attributes()->hour <= (int) date("H")))
) || $numberDays > 0) {
$captcha['timestamp'] =
strtotime(date("Y-m-d", $day)." ".$value->Attributes()->hour.":00") + date("Z");
$captcha['captcha_accs'] = (string) $value->volume;
$capdatas[] = $captcha;
}
}
--$numberDays;
}
foreach ($capXml as $key => $value) {
if ((0 == $numberDays
&& ((int) $value->Attributes()->hour >= (int) date('H', $lastCaptcha['timestamp'])
&& ((int) $value->Attributes()->hour <= (int) date('H')))
) || $numberDays > 0) {
$captcha['timestamp'] =
strtotime(date('Y-m-d', $day).' '.$value->Attributes()->hour.':00') + date('Z');
$captcha['captcha_accs'] = (string) $value->volume;
$capdatas[] = $captcha;
}
}
--$numberDays;
}
}
// Write to file
Oops, something went wrong.

0 comments on commit 9cdd6ed

Please sign in to comment.
You can’t perform that action at this time.