Skip to content

Commit

Permalink
Combine PR #353 with #363 & Code formatting (#371)
Browse files Browse the repository at this point in the history
* 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 9cdd6ed
Show file tree
Hide file tree
Showing 50 changed files with 5,723 additions and 3,088 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
62 changes: 62 additions & 0 deletions CreateStatsMonocle.sql
Original file line number Diff line number Diff line change
@@ -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 ;
62 changes: 62 additions & 0 deletions CreateStatsRocketMap.sql
Original file line number Diff line number Diff line change
@@ -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 ;
53 changes: 26 additions & 27 deletions config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__)));
Expand All @@ -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);
}
120 changes: 59 additions & 61 deletions core/cron/captcha.cron.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

// -----------------------------------------------------------------------------------------------------------
// Pokestops datas
// Total pokestops
Expand All @@ -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
Expand Down
Loading

0 comments on commit 9cdd6ed

Please sign in to comment.