grapper wip

This commit is contained in:
salam committed 2026-01-18 14:35:30 +01:00
1 parent 562c65f331
commit 4184acdb8a
60 files changed
+28840 -398

No files matched your search

@@ -2,47 +2,56 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds\Tools;
use App\Console\Commands\Nuh;
use Illuminate\Support\Facades\DB;
class ActiveSpread
{
public static $collector = [];
public static $event_id = 0;
public static $provider_id = 0;
public static function collect($odds, $bettype)
{
if (! isset(Nuh::$collector[$bettype][Nuh::$bookmaker_id]['difference'])) {
Nuh::$collector[$bettype][Nuh::$bookmaker_id]['difference'] = $odds['difference'];
if ($odds['event_id'] != self::$event_id) {
self::$event_id = $odds['event_id'];
self::$provider_id = $odds['provider_id'];
self::$collector = [];
}
if (! isset(self::$collector[$bettype][$odds['bookmaker_id']]['difference'])) {
self::$collector[$bettype][$odds['bookmaker_id']]['difference'] = $odds['difference'];
if (isset($odds['handicap'])) {
Nuh::$collector[$bettype][Nuh::$bookmaker_id]['active_spread'] = $odds['handicap'];
self::$collector[$bettype][$odds['bookmaker_id']]['active_spread'] = $odds['handicap'];
} else {
Nuh::$collector[$bettype][Nuh::$bookmaker_id]['active_spread'] = $odds['total'];
self::$collector[$bettype][$odds['bookmaker_id']]['active_spread'] = $odds['total'];
}
} elseif ($odds['difference'] < Nuh::$collector[$bettype][Nuh::$bookmaker_id]['difference']) {
Nuh::$collector[$bettype][Nuh::$bookmaker_id]['difference'] = $odds['difference'];
} elseif ($odds['difference'] < self::$collector[$bettype][$odds['bookmaker_id']]['difference']) {
self::$collector[$bettype][$odds['bookmaker_id']]['difference'] = $odds['difference'];
if (isset($odds['handicap'])) {
Nuh::$collector[$bettype][Nuh::$bookmaker_id]['active_spread'] = $odds['handicap'];
self::$collector[$bettype][$odds['bookmaker_id']]['active_spread'] = $odds['handicap'];
} else {
Nuh::$collector[$bettype][Nuh::$bookmaker_id]['active_spread'] = $odds['total'];
self::$collector[$bettype][$odds['bookmaker_id']]['active_spread'] = $odds['total'];
}
}
}
public static function set()
{
foreach (Nuh::$collector as $table => $value) {
DB::table($table)->where('event_id', Nuh::$id)->where('provider_id', Nuh::$options['provider_id'])->update(['active_spread' => 0]);
foreach (self::$collector as $table => $value) {
DB::table($table)->where('event_id', self::$event_id)->where('provider_id', self::$provider_id)->update(['active_spread' => 0]);
}
foreach (Nuh::$collector as $table => $bookmaker) {
foreach (self::$collector as $table => $bookmaker) {
foreach ($bookmaker as $bookmaker_id => $values) {
if (in_array($table, ['odds_points', 'odds_points_ht', 'odds_points_q1'])) {
DB::table($table)
->where('event_id', Nuh::$id)
->where('event_id', self::$event_id)
->where('bookmaker_id', $bookmaker_id)
->where('handicap', $values['active_spread'])
->update(['active_spread' => 1]);
} else {
DB::table($table)
->where('event_id', Nuh::$id)
->where('event_id', self::$event_id)
->where('bookmaker_id', $bookmaker_id)
->where('total', $values['active_spread'])
->update(['active_spread' => 1]);
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Models\Odds2way;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _2Way
{
@@ -14,14 +14,20 @@ class _2Way
$odds['a2w'] = (float) $value->o3;
}
$odds['margin'] = (float) Margin::calculate([$odds['h2w'], $odds['a2w']], 1);
$odds['updated_at'] = now();
DB::table('odds_2ways')->upsert(
$odds,
['event_id', 'bookmaker_id'],
$res = Odds2way::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first();
['h2w', 'a2w', 'margin', 'flags', 'updated_at']
);
if (! $res) {
Odds2way::create($odds);
} else {
$res->h2w = $odds['h2w'];
$res->a2w = $odds['a2w'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
}
}
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Models\Odds2wayS1;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _2WayS1
{
@@ -14,14 +14,20 @@ class _2WayS1
$odds['a2w'] = (float) $value->o3;
}
$odds['margin'] = (float) Margin::calculate([$odds['h2w'], $odds['a2w']], 1);
$odds['updated_at'] = now();
DB::table('odds_2ways_s1')->upsert(
$odds,
['event_id', 'bookmaker_id'],
$res = Odds2wayS1::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first();
['h2w', 'a2w', 'margin', 'flags', 'updated_at']
);
if (! $res) {
Odds2wayS1::create($odds);
} else {
$res->h2w = $odds['h2w'];
$res->a2w = $odds['a2w'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
}
}
@@ -13,18 +13,23 @@ class _3Way
$odds['h3w'] = (float) $value->o1;
$odds['d3w'] = (float) $value->o2;
$odds['a3w'] = (float) $value->o3;
$odds['a3w'] = (float) 1.1;
}
$odds['margin'] = (float) Margin::calculate([$odds['h3w'], $odds['d3w'], $odds['a3w']], 1);
$res = Odds3way::updateOrCreate(
['event_id' => $odds['event_id'], 'bookmaker_id' => $odds['bookmaker_id']],
$odds,
);
if ($res->wasChanged('h3w', 'd3w', 'h3w')) {
$res = Odds3way::updateOrCreate(
['event_id' => $odds['event_id'], 'bookmaker_id' => $odds['bookmaker_id']],
['oddchange_at' => now()],
);
$res = Odds3way::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first();
if (! $res) {
Odds3way::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->a3w = $odds['d3w'];
$res->d3w = $odds['a3w'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
}
}
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Models\Odds3wayHt;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _3WayHt
{
@@ -15,14 +15,21 @@ class _3WayHt
$odds['a3w'] = (float) $value->o3;
}
$odds['margin'] = (float) Margin::calculate([$odds['h3w'], $odds['d3w'], $odds['a3w']], 1);
$odds['updated_at'] = now();
DB::table('odds_3ways_ht')->upsert(
$odds,
['event_id', 'bookmaker_id'],
$res = Odds3wayHt::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first();
['h3w', 'd3w', 'a3w', 'margin', 'flags', 'updated_at']
);
if (! $res) {
Odds3wayHt::create($odds);
} else {
$res->h3w = $odds['h3w'];
$res->d3w = $odds['d3w'];
$res->d3w = $odds['a3w'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
}
}
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Models\OddsDc;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _Dc
{
@@ -15,14 +15,21 @@ class _Dc
$odds['dcx2'] = (float) $value->o3;
}
$odds['margin'] = (float) Margin::calculate([$odds['dc1x'], $odds['dc12'], $odds['dcx2']], 1);
$odds['updated_at'] = now();
DB::table('odds_dc')->upsert(
$odds,
['event_id', 'bookmaker_id'],
$res = OddsDc::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first();
['dc1x', 'dc12', 'dcx2', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsDc::create($odds);
} else {
$res->dc1x = $odds['dc1x'];
$res->dc12 = $odds['dc12'];
$res->dcx2 = $odds['dcx2'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
}
}
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Models\OddsDnb;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _Dnb
{
@@ -14,14 +14,20 @@ class _Dnb
$odds['dnb2'] = (float) $value->o3;
}
$odds['margin'] = (float) Margin::calculate([$odds['dnb1'], $odds['dnb2']], 1);
$odds['updated_at'] = now();
DB::table('odds_dnb')->upsert(
$odds,
['event_id', 'bookmaker_id'],
$res = OddsDnb::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first();
['dnb1', 'dnb2', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsDnb::create($odds);
} else {
$res->dnb1 = $odds['dnb1'];
$res->dnb2 = $odds['dnb2'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
}
}
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Models\OddsGgng;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _Ggng
{
@@ -14,14 +14,20 @@ class _Ggng
$odds['ng'] = (float) $value->o3;
}
$odds['margin'] = (float) Margin::calculate([$odds['gg'], $odds['ng']], 1);
$odds['updated_at'] = now();
DB::table('odds_ggng')->upsert(
$odds,
['event_id', 'bookmaker_id'],
$res = OddsGgng::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first();
['gg', 'ng', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsGgng::create($odds);
} else {
$res->gg = $odds['gg'];
$res->ng = $odds['ng'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
}
}
@@ -3,8 +3,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread;
use App\Models\OddsPoint;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _Points
{
@@ -20,18 +20,27 @@ class _Points
return;
}
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1);
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds['updated_at'] = now();
DB::table('odds_points')->upsert(
$odds,
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1);
['event_id', 'bookmaker_id', 'handicap'],
$res = OddsPoint::where('event_id', $odds['event_id'])
->where('bookmaker_id', $odds['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
['home', 'away', 'difference', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsPoint::create($odds);
} else {
$res->home = $odds['home'];
$res->away = $odds['away'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
ActiveSpread::collect($odds, 'odds_points');
}
@@ -3,8 +3,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread;
use App\Models\OddsPointHt;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _PointsHt
{
@@ -20,18 +20,27 @@ class _PointsHt
return;
}
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1);
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds['updated_at'] = now();
DB::table('odds_points_ht')->upsert(
$odds,
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1);
['event_id', 'bookmaker_id', 'handicap'],
$res = OddsPointHt::where('event_id', $odds['event_id'])
->where('bookmaker_id', $odds['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
['home', 'away', 'difference', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsPointHt::create($odds);
} else {
$res->home = $odds['home'];
$res->away = $odds['away'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
ActiveSpread::collect($odds, 'odds_points_ht');
}
@@ -3,8 +3,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread;
use App\Models\OddsPointQ1;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _PointsQ1
{
@@ -20,18 +20,27 @@ class _PointsQ1
return;
}
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1);
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds['updated_at'] = now();
DB::table('odds_points_q1')->upsert(
$odds,
$odds['margin'] = (float) Margin::calculate([$odds['home'], $odds['away']], 1);
['event_id', 'bookmaker_id', 'handicap'],
$res = OddsPointQ1::where('event_id', $odds['event_id'])
->where('bookmaker_id', $odds['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
['home', 'away', 'difference', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsPointQ1::create($odds);
} else {
$res->home = $odds['home'];
$res->away = $odds['away'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
ActiveSpread::collect($odds, 'odds_points_q1');
}
@@ -3,8 +3,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread;
use App\Models\OddsTotal;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _Totals
{
@@ -26,18 +26,27 @@ class _Totals
}
}
$odds['margin'] = (float) Margin::calculate([$odds['over'], $odds['under']], 1);
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds['updated_at'] = now();
DB::table('odds_totals')->upsert(
$odds,
$odds['margin'] = (float) Margin::calculate([$odds['over'], $odds['under']], 1);
['event_id', 'bookmaker_id', 'total'],
$res = OddsTotal::where('event_id', $odds['event_id'])
->where('bookmaker_id', $odds['bookmaker_id'])
->where('total', $odds['total'])
->first();
['over', 'under', 'difference', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsTotal::create($odds);
} else {
$res->over = $odds['over'];
$res->under = $odds['under'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
ActiveSpread::collect($odds, 'odds_totals');
}
@@ -3,8 +3,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread;
use App\Models\OddsTotalHt;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _TotalsHt
{
@@ -26,18 +26,27 @@ class _TotalsHt
}
}
$odds['margin'] = (float) Margin::calculate([$odds['over'], $odds['under']], 1);
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds['updated_at'] = now();
DB::table('odds_totals_ht')->upsert(
$odds,
$odds['margin'] = (float) Margin::calculate([$odds['over'], $odds['under']], 1);
['event_id', 'bookmaker_id', 'total'],
$res = OddsTotalHt::where('event_id', $odds['event_id'])
->where('bookmaker_id', $odds['bookmaker_id'])
->where('total', $odds['total'])
->first();
['over', 'under', 'difference', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsTotalHt::create($odds);
} else {
$res->over = $odds['over'];
$res->under = $odds['under'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
ActiveSpread::collect($odds, 'odds_totals_ht');
}
@@ -3,8 +3,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread;
use App\Models\OddsTotalQ1;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _TotalsQ1
{
@@ -26,18 +26,27 @@ class _TotalsQ1
}
}
$odds['margin'] = (float) Margin::calculate([$odds['over'], $odds['under']], 1);
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds['updated_at'] = now();
DB::table('odds_totals_q1')->upsert(
$odds,
$odds['margin'] = (float) Margin::calculate([$odds['over'], $odds['under']], 1);
['event_id', 'bookmaker_id', 'total'],
$res = OddsTotalQ1::where('event_id', $odds['event_id'])
->where('bookmaker_id', $odds['bookmaker_id'])
->where('total', $odds['total'])
->first();
['over', 'under', 'difference', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsTotalQ1::create($odds);
} else {
$res->over = $odds['over'];
$res->under = $odds['under'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
ActiveSpread::collect($odds, 'odds_totals_q1');
}
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Grapper\TxOdds\Odds;
use App\Models\OddsTq;
use App\Utilities\Margin;
use Illuminate\Support\Facades\DB;
class _Tq
{
@@ -14,14 +14,20 @@ class _Tq
$odds['atq'] = (float) $value->o3;
}
$odds['margin'] = (float) Margin::calculate([$odds['htq'], $odds['atq']], 1);
$odds['updated_at'] = now();
DB::table('odds_tq')->upsert(
$odds,
['event_id', 'bookmaker_id'],
$res = OddsTq::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first();
['htq', 'atq', 'margin', 'flags', 'updated_at']
);
if (! $res) {
OddsTq::create($odds);
} else {
$res->htq = $odds['htq'];
$res->atq = $odds['atq'];
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->checked_at = $odds['checked_at'];
$res->margin = $odds['margin'];
$res->save();
}
}
}