wip
This commit is contained in:
1 parent
b004742d47
commit
96334bb1e4
33 files changed
+1650
-2
No files matched your search
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Comparatore;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventBookmaker;
|
||||
use App\Models\Supervisor;
|
||||
use App\Utilities\Notice;
|
||||
use App\Utilities\Supervisorctl;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Comparatore extends Command
|
||||
{
|
||||
public static $events = [];
|
||||
|
||||
public static $sport_id = 0;
|
||||
|
||||
public static $options = [];
|
||||
|
||||
public static $force = 0;
|
||||
|
||||
public static $debug = 0;
|
||||
|
||||
protected $signature = 'com {process=help} {eventid=0} {--d} {--f} {--a} {--p} {--w}';
|
||||
|
||||
protected $description = 'Comparatore';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
self::$options = $this->options();
|
||||
self::$options['supervisor_id'] = $this->argument('process');
|
||||
self::$options['event_id'] = $this->argument('eventid');
|
||||
|
||||
if ($this->argument('process') == 'help') {
|
||||
$txt = PHP_EOL.'a com process [id] eventid [id]'.PHP_EOL;
|
||||
$txt .= '--d debug'.PHP_EOL;
|
||||
$txt .= '--f force update market'.PHP_EOL;
|
||||
$txt .= '--a reload all'.PHP_EOL;
|
||||
$txt .= '--w reload one week'.PHP_EOL;
|
||||
$txt .= '--p print feed'.PHP_EOL.PHP_EOL;
|
||||
$txt .= 'eventid'.PHP_EOL.PHP_EOL;
|
||||
$txt .= 'use "com l" to show options'.PHP_EOL;
|
||||
Notice::note($txt, 'b', 1);
|
||||
} elseif ($this->argument('process') == 'l') {
|
||||
$txt = 'list of comparatore processes';
|
||||
$txt .= Supervisor::list('com');
|
||||
Notice::note($txt, 'b', 1);
|
||||
}
|
||||
|
||||
Supervisorctl::start(self::$options);
|
||||
|
||||
$res = Event::where('time', '>', Carbon::now()->toDateTimeString())->get();
|
||||
|
||||
foreach ($res as $event) {
|
||||
$bookmaker = EventBookmaker::where('event_id', $event->id)->get();
|
||||
if ($bookmaker->count() != null) {
|
||||
dd($bookmaker);
|
||||
}
|
||||
}
|
||||
|
||||
Supervisorctl::end(self::$options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper;
|
||||
|
||||
use App\Console\Commands\Grapper\TxOdds\TxOdds;
|
||||
use App\Models\Supervisor;
|
||||
use App\Utilities\Notice;
|
||||
use App\Utilities\Supervisorctl;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class Grapper extends Command
|
||||
{
|
||||
public static $event = [];
|
||||
|
||||
public static $_send = [];
|
||||
|
||||
public static $sport_id = 0;
|
||||
|
||||
public static $options = [];
|
||||
|
||||
public static $force = 0;
|
||||
|
||||
public static $debug = 0;
|
||||
|
||||
public static $domain = '';
|
||||
|
||||
public static $auth = '';
|
||||
|
||||
protected $signature = 'gra {process=help} {eventid=0} {--d} {--f} {--a} {--p} {--w}';
|
||||
|
||||
protected $description = 'Grapper';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
self::$options = $this->options();
|
||||
self::$options['supervisor_id'] = $this->argument('process');
|
||||
self::$options['event_id'] = $this->argument('eventid');
|
||||
|
||||
if ($this->argument('process') == 'help') {
|
||||
$txt = PHP_EOL.'a gra process [id] eventid [id]'.PHP_EOL;
|
||||
$txt .= '--d debug'.PHP_EOL;
|
||||
$txt .= '--f force update market'.PHP_EOL;
|
||||
$txt .= '--a reload all'.PHP_EOL;
|
||||
$txt .= '--w reload one week'.PHP_EOL;
|
||||
$txt .= '--p print odds'.PHP_EOL.PHP_EOL;
|
||||
$txt .= 'eventid'.PHP_EOL.PHP_EOL;
|
||||
$txt .= 'use "gra l" to show options'.PHP_EOL;
|
||||
Notice::note($txt, 'b', 1);
|
||||
} elseif ($this->argument('process') == 'l') {
|
||||
$txt = 'list of grapper processes';
|
||||
$txt .= Supervisor::list('gra');
|
||||
Notice::note($txt, 'b', 1);
|
||||
}
|
||||
|
||||
Supervisorctl::start(self::$options);
|
||||
|
||||
Helper::get_auth_string();
|
||||
|
||||
switch (self::$options['provider_id']) {
|
||||
case 1:
|
||||
case 2:
|
||||
TxOdds::switch();
|
||||
break;
|
||||
case 3:
|
||||
// betsapi
|
||||
break;
|
||||
default:
|
||||
Note::notice('Provider not defined', 'r', 1);
|
||||
break;
|
||||
}
|
||||
|
||||
Supervisorctl::end(self::$options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper;
|
||||
|
||||
use App\Utilities\Notice;
|
||||
|
||||
class Helper
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public static function get_auth_string()
|
||||
{
|
||||
if (Grapper::$options['provider_id'] == 1) {
|
||||
// txodds soccer
|
||||
Grapper::$auth = 'ident=betaid1&passwd=Dy59vpRC';
|
||||
Grapper::$domain = 'https://xml2.txodds.com/';
|
||||
} elseif (Grapper::$options['provider_id'] == 3) {
|
||||
// txodds others
|
||||
Grapper::$auth = 'ident=betaid2&passwd=Dy59vpRC';
|
||||
Grapper::$domain = 'https://xml2.txodds.com/';
|
||||
} else {
|
||||
Notice::note('error txodds provider', 'r', 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static function margin($arr)
|
||||
{
|
||||
$r = 0;
|
||||
foreach ($arr as $key => $value) {
|
||||
$r += 100 / $value;
|
||||
}
|
||||
|
||||
return round($r, 3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\TxOdds;
|
||||
|
||||
use App\Console\Commands\Grapper\Grapper;
|
||||
use App\Models\Country;
|
||||
use App\Utilities\Notice;
|
||||
|
||||
class Countries
|
||||
{
|
||||
public static function grap()
|
||||
{
|
||||
Notice::note('disabled as txodds data is a mess, had to fix all manually', 'r', 1);
|
||||
|
||||
$response = simplexml_load_file(Grapper::$domain.'feed/countries.php', null, LIBXML_NOCDATA);
|
||||
|
||||
foreach ($response->country as $country) {
|
||||
$res = Country::where('txid', $country->id)->first();
|
||||
if ($res !== null) {
|
||||
// $res->txid = $country->id;
|
||||
// $res->txid = $country->id;
|
||||
// $res->save();
|
||||
} else {
|
||||
$res = new Country;
|
||||
$res->name = $country->name;
|
||||
$res->iso3 = $country->cc;
|
||||
$res->txid = $country->id;
|
||||
$res->tx_only = 1;
|
||||
$res->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\TxOdds;
|
||||
|
||||
use App\Console\Commands\Grapper\Grapper;
|
||||
use App\Models\Event;
|
||||
use App\Utilities\Notice;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Events
|
||||
{
|
||||
public static function grap()
|
||||
{
|
||||
|
||||
Notice::note('txodd fixture sport: '.Grapper::$options['sport_id'], 'b');
|
||||
|
||||
$debug = Grapper::$options['d'] ?? 0;
|
||||
|
||||
$now = Carbon::tomorrow();
|
||||
for ($i = 0; $i < 60; $i++) {
|
||||
|
||||
$from = $now->toDateString();
|
||||
$to = $now->addDays(1)->toDateString();
|
||||
$url = Grapper::$domain.'feed/result/xml.php?'.Grapper::$auth."&date=$from,$to";
|
||||
if ($debug) {
|
||||
Notice::note($url, 'y');
|
||||
}
|
||||
$xml = simplexml_load_file($url, null, LIBXML_NOCDATA);
|
||||
foreach ($xml->match as $_match) {
|
||||
|
||||
Event::updateOrCreate([
|
||||
'txid' => (int) $_match['id'],
|
||||
'spid' => Grapper::$options['sport_id'],
|
||||
'prid' => Grapper::$options['provider_id'],
|
||||
|
||||
'cnid' => (int) $_match->group['cnid'], // country_id
|
||||
'grid' => (int) $_match->group['id'], // group_id
|
||||
'cgid' => (int) $_match->group['cgid'], // competition_group_id
|
||||
|
||||
'hoid' => (int) $_match->hteam['id'],
|
||||
'awid' => (int) $_match->ateam['id'],
|
||||
'home' => (string) $_match->hteam,
|
||||
'away' => (string) $_match->ateam,
|
||||
'liga' => (string) $_match->group['cname'],
|
||||
], [
|
||||
'time' => Carbon::parse($_match->time)->toDateTimeString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\TxOdds;
|
||||
|
||||
use App\Console\Commands\Grapper\Grapper;
|
||||
use App\Console\Commands\Grapper\Helper;
|
||||
use App\Models\Event;
|
||||
use App\Models\EventBookmaker;
|
||||
use App\Utilities\Notice;
|
||||
use App\Utilities\Supervisorctl;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Odds
|
||||
{
|
||||
public static function grap()
|
||||
{
|
||||
|
||||
Notice::note('txodd odd sport: '.Grapper::$options['sport_id'], 'b');
|
||||
|
||||
/*************************************************
|
||||
* SINGLE SOCCER
|
||||
* https://xml2.txodds.com/feed/odds/xml.php?ident=betaid1&passwd=Dy59vpRC&peid=3118930
|
||||
|
||||
* SINGLE OTHER
|
||||
*************************************************
|
||||
* https://xml2.txodds.com/feed/odds/xml.php?ident=betaid2&passwd=Dy59vpRC&peid=3118930
|
||||
|
||||
*************************************************
|
||||
* https://xml2.txodds.com/feed/odds_types.php
|
||||
|
||||
* BETTYPE IDS
|
||||
0 3-WAY
|
||||
1 2-WAY
|
||||
3 POINTS
|
||||
4 TOTALS
|
||||
5 Asian
|
||||
65536 3-WAY HALF TIME
|
||||
131072 3 WAY QUARTER TIME
|
||||
65539 POINTS HALF TIME
|
||||
131075 POINTS QUARTER TIME
|
||||
262147 POINTS OVER TIME
|
||||
65540 TOTALS HALF TIME
|
||||
131076 TOTALS QUARTER TIME
|
||||
262148 TOTALS OVER TIME
|
||||
11534337 GG/NG (both teams to score)
|
||||
5242880 DOUBLE CHANCE
|
||||
7340033 TO PROGRESS (to_qualify)
|
||||
|
||||
Not used:
|
||||
|
||||
65537 2-WAY HALF TIME
|
||||
327680 3-WAY 2ND HALF
|
||||
327681 2-WAY 2ND HALF
|
||||
327683 POINT 2ND HALF
|
||||
327684 TOTALS 2ND HALF
|
||||
1048577 GOAL / NO GOAL
|
||||
|
||||
2097153 ODD / EVEN
|
||||
4194304 TOTAL GOALS
|
||||
6291457 DRAW NO BET
|
||||
8388608 1X2 EURO HANDCIAP
|
||||
9437188 TOTAL CORNERS
|
||||
9502724 TOTAL CORNERS 1ST HALF
|
||||
20971520 3-WAY CORNERS
|
||||
28311555 HANDICAP SETS
|
||||
28311556 TOTAL SETS
|
||||
|
||||
*************************************************/
|
||||
|
||||
$debug = Grapper::$options['d'] ?? 0;
|
||||
|
||||
switch (Grapper::$options['sport_id']) {
|
||||
case 1:
|
||||
$markets = '0,4,11534337,5242880,7340033';
|
||||
break;
|
||||
case 2:
|
||||
// needs check
|
||||
$markets = '0,1,3,4,262148,131072,131076';
|
||||
break;
|
||||
case 3:
|
||||
// needs check
|
||||
$markets = '0,1,3,4,262147,262148,65539,65540,131075,131076';
|
||||
break;
|
||||
case 5:
|
||||
$markets = '1,3,4';
|
||||
break;
|
||||
case 8:
|
||||
$markets = '0,3,4';
|
||||
break;
|
||||
default:
|
||||
Notice::note('sport not defined', 'r', 1);
|
||||
break;
|
||||
}
|
||||
|
||||
/*************************************************
|
||||
* URL
|
||||
*************************************************/
|
||||
|
||||
$url = Grapper::$domain.'feed/odds/xml.php?'.Grapper::$auth.'&all_odds=2&spid='.Grapper::$options['sport_id'];
|
||||
$_calls = [];
|
||||
if (Grapper::$options['event_id']) {
|
||||
$_calls[] = $url."&ot=$markets&peid=".Grapper::$options['event_id'];
|
||||
} elseif (Grapper::$options['a']) {
|
||||
$res = Event::where('time', '>', Carbon::now()->toDateTimeString())->pluck('txid');
|
||||
foreach ($res as $id) {
|
||||
$_calls[] = $url."&ot=$markets&peid=".$id;
|
||||
}
|
||||
} elseif (Grapper::$options['w']) {
|
||||
$res = Event::where('time', '>', Carbon::now()->toDateTimeString())->where('time', '<', Carbon::now()->addDays(7)->toDateTimeString())->pluck('txid');
|
||||
foreach ($res as $id) {
|
||||
$_calls[] = $url."&ot=$markets&peid=".$id;
|
||||
}
|
||||
} else {
|
||||
$_calls[] = $url.'&last='.Grapper::$options['lastcall'];
|
||||
}
|
||||
|
||||
/*************************************************
|
||||
* CALL
|
||||
*************************************************/
|
||||
foreach ($_calls as $url) {
|
||||
Notice::note($url, 'r');
|
||||
|
||||
$xml = simplexml_load_file($url, null, LIBXML_NOCDATA);
|
||||
|
||||
if (Grapper::$options['p']) {
|
||||
Notice::note($url);
|
||||
foreach ($xml->match as $match) {
|
||||
print_r($match);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
Supervisorctl::set_lastcall($xml['timestamp']);
|
||||
|
||||
foreach ($xml->match as $m) {
|
||||
|
||||
if (Grapper::$options['d']) {
|
||||
Notice::note((int) $m['id'].' : '.$m->hteam.' - '.$m->ateam);
|
||||
}
|
||||
|
||||
$evid = Event::where('txid', (int) $m['id'])->pluck('id')->first();
|
||||
|
||||
if ($evid) {
|
||||
$fixed_array = [];
|
||||
$fixed_array['event_id'] = $evid;
|
||||
|
||||
Event::where('id', $evid)->update(['cnt_bkm_tx' => count($m->bookmaker)]);
|
||||
|
||||
foreach ($m->bookmaker as $bookmaker) {
|
||||
|
||||
$fixed_array['bkid'] = (int) $bookmaker['bid'];
|
||||
|
||||
$value_array = [];
|
||||
|
||||
foreach ($bookmaker->offer as $offer) {
|
||||
switch ($offer['ot']) {
|
||||
case '0':
|
||||
|
||||
$value_array['f3w'] = (int) $offer['flags'] ?? 0;
|
||||
$value_array['boid'] = (string) $offer['bmoid'] ?? 0;
|
||||
$value_array['time'] = Carbon::parse($offer->odds['starting_time'])->toDateTimeString();
|
||||
|
||||
$tmp = [];
|
||||
$tmp['h3w'] = (float) $offer->odds->o1 ?? 1;
|
||||
$tmp['d3w'] = (float) $offer->odds->o2 ?? 1;
|
||||
$tmp['a3w'] = (float) $offer->odds->o3 ?? 1;
|
||||
$tmp['m3w'] = Helper::margin($tmp);
|
||||
$value_array += $tmp;
|
||||
break;
|
||||
|
||||
case '1':
|
||||
|
||||
$value_array['f2w'] = (int) $offer['flags'] ?? 0;
|
||||
$value_array['boid'] = (string) $offer['bmoid'] ?? 0;
|
||||
$value_array['time'] = Carbon::parse($offer->odds['starting_time'])->toDateTimeString();
|
||||
|
||||
$tmp = [];
|
||||
$tmp['h2w'] = (float) $offer->odds->o1 ?? 1;
|
||||
$tmp['a2w'] = (float) $offer->odds->o3 ?? 1;
|
||||
$tmp['m2w'] = Helper::margin($tmp);
|
||||
$value_array += $tmp;
|
||||
break;
|
||||
|
||||
case '4':
|
||||
$hc = (float) $offer->odds->o3;
|
||||
if (Grapper::$options['sport_id'] == 1 && $hc == 2.5) {
|
||||
$tmp = [];
|
||||
$tmp['ov'] = (float) $offer->odds->o1 ?? 1;
|
||||
$tmp['un'] = (float) $offer->odds->o2 ?? 1;
|
||||
$tmp['mto'] = Helper::margin($tmp);
|
||||
$tmp['fto'] = (int) $offer->odd['flags'] ?? 0;
|
||||
$tmp['hc'] = 2.5;
|
||||
$value_array += $tmp;
|
||||
}
|
||||
break;
|
||||
|
||||
case '5242880':
|
||||
// Double Chance (dc1x,dc12,dcx2)
|
||||
$value_array['fdc'] = (int) $offer['flags'] ?? 0;
|
||||
$tmp = [];
|
||||
$tmp['dc1x'] = (float) $offer->odds->o1 ?? 1;
|
||||
$tmp['dc12'] = (float) $offer->odds->o2 ?? 1;
|
||||
$tmp['dcx2'] = (float) $offer->odds->o3 ?? 1;
|
||||
$tmp['mdc'] = Helper::margin($tmp);
|
||||
$value_array += $tmp;
|
||||
break;
|
||||
|
||||
case '11534337':
|
||||
// goal/nogoal (gg,ng)
|
||||
$value_array['fgg'] = (int) $offer['flags'] ?? 0;
|
||||
$tmp = [];
|
||||
$tmp['gg'] = (float) $offer->odds->o1 ?? 1;
|
||||
$tmp['ng'] = (float) $offer->odds->o3 ?? 1;
|
||||
$tmp['mgg'] = Helper::margin($tmp);
|
||||
$value_array += $tmp;
|
||||
break;
|
||||
|
||||
case '7340033':
|
||||
// to qualify (htq,atq)
|
||||
$value_array['ftq'] = (int) $offer['flags'] ?? 0;
|
||||
$tmp = [];
|
||||
$tmp['htq'] = (float) $offer->odds->o1 ?? 1;
|
||||
$tmp['atq'] = (float) $offer->odds->o3 ?? 1;
|
||||
$tmp['mtq'] = Helper::margin($tmp);
|
||||
$value_array += $tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EventBookmaker::updateOrCreate($fixed_array, $value_array);
|
||||
if (Grapper::$options['d']) {
|
||||
Notice::note($fixed_array + $value_array, 'b');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Grapper\TxOdds;
|
||||
|
||||
use App\Console\Commands\Grapper\Grapper;
|
||||
|
||||
class TxOdds
|
||||
{
|
||||
/**
|
||||
* https://docs.guzzlephp.org/en/latest/
|
||||
*/
|
||||
public static function switch()
|
||||
{
|
||||
switch (Grapper::$options['option_id']) {
|
||||
case 1:
|
||||
// Leages
|
||||
break;
|
||||
case 2:
|
||||
Events::grap();
|
||||
break;
|
||||
case 3:
|
||||
// Flags
|
||||
break;
|
||||
case 4:
|
||||
Odds::grap();
|
||||
break;
|
||||
case 5:
|
||||
Countries::grap();
|
||||
break;
|
||||
default:
|
||||
Note::notice('Provider not defined', 'r', 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
$schedule->command('model:prune')->daily();
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user