renewd grapper wip

This commit is contained in:
salam committed 2026-01-19 18:36:07 +01:00
1 parent 8f1aeafe46
commit 4afe60a957
55 files changed
+1389 -823

No files matched your search

@@ -0,0 +1,35 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
class ActiveHandicap
{
public static function set(&$_spreads)
{
$tmp = 10000;
$hcap = false;
foreach ($_spreads as $key => $value) {
$x = 0;
foreach ($value as $k => $v) {
if ($x == 0) {
$x = $v;
} else {
$x -= $v;
}
}
$x = abs($x);
if ($x < $tmp) {
$hcap = $key;
$tmp = $x;
}
}
foreach ($_spreads as $key => $value) {
if ($key == $hcap) {
$_spreads[$key]['active_spread'] = 1;
} else {
$_spreads[$key]['active_spread'] = 0;
}
}
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
class FilterHandicap
{
public static function filter(&$_spreads, $filter, $data, $oddnames)
{
foreach ($data as $key => $value) {
$key = str_replace($filter, '', $key);
if (strpos($key, '_O') !== false) {
$hcap = str_replace('_O', '', $key);
$_spreads[$hcap]['ele1'] = $value;
} elseif (strpos($key, '_1H') !== false) {
$hcap = str_replace('_1H', '', $key);
$_spreads[$hcap]['ele1'] = $value;
} elseif (strpos($key, '_1') !== false) {
$hcap = str_replace('_1', '', $key);
$_spreads[$hcap]['ele1'] = $value;
} elseif (strpos($key, '_U') !== false) {
$hcap = str_replace('_U', '', $key);
$_spreads[$hcap]['ele2'] = $value;
} elseif (strpos($key, '_2H') !== false) {
$hcap = str_replace('_2H', '', $key);
$_spreads[$hcap]['ele2'] = $value;
} elseif (strpos($key, '_2') !== false) {
$hcap = str_replace('_2', '', $key);
$_spreads[$hcap]['ele2'] = $value;
}
}
}
}
@@ -8,9 +8,25 @@ use App\Utilities\Notice;
class LogifutureData
{
public static $testfiles = '/Console/Commands/TestFiles/';
public static function load($logifuture_sport_id)
{
$debug = Nuh::$options['d'] ?? 0;
$save = Nuh::$options['s'] ?? 0;
$read = Nuh::$options['r'] ?? 0;
$filename = app_path().self::$testfiles.str_replace(' ', '_', strtolower(Nuh::$options['sport'].'_'.Nuh::$options['provider'])).'.json';
if ($read) {
if ($debug) {
Notice::note('data read localy', 'g');
}
$file = file_get_contents($filename);
return json_decode($file, true);
}
$url = Nuh::$options['base_url'].'/v1/matches?sportId='.$logifuture_sport_id;
@@ -59,6 +75,13 @@ class LogifutureData
$file = curl_exec($ch);
if ($save) {
file_put_contents($filename, $file);
Notice::note('file saved localy', 'g');
}
if (curl_errno($ch)) {
echo curl_error($ch);
}
@@ -9,7 +9,6 @@ class MapEvent
{
public static function filter($sport_id, $match)
{
$event = [];
$event['event_id'] = (int) $match['id'];
$event['bookmaker_id'] = Nuh::$options['bookmaker_id'];
@@ -1,58 +0,0 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Tools;
class PrinzipalHandicap
{
public static function filter(&$_spreads, $filter, $data, $oddnames)
{
$_tmp = [];
foreach ($data as $key => $value) {
$key = str_replace($filter, '', $key);
if (strpos($key, '_O') !== false) {
$hcap = str_replace('_O', '', $key);
$_tmp[$hcap]['ele1'] = $value;
} elseif (strpos($key, '_1H') !== false) {
$hcap = str_replace('_1H', '', $key);
$_tmp[$hcap]['ele1'] = $value;
} elseif (strpos($key, '_1') !== false) {
$hcap = str_replace('_1', '', $key);
$_tmp[$hcap]['ele1'] = $value;
} elseif (strpos($key, '_U') !== false) {
$hcap = str_replace('_U', '', $key);
$_tmp[$hcap]['ele2'] = $value;
} elseif (strpos($key, '_2H') !== false) {
$hcap = str_replace('_2H', '', $key);
$_tmp[$hcap]['ele2'] = $value;
} elseif (strpos($key, '_2') !== false) {
$hcap = str_replace('_2', '', $key);
$_tmp[$hcap]['ele2'] = $value;
}
}
$tmp = 10000;
$hcap = false;
foreach ($_tmp as $key => $value) {
$x = 0;
foreach ($value as $k => $v) {
if ($x == 0) {
$x = $v;
} else {
$x -= $v;
}
}
$x = abs($x);
if ($x < $tmp) {
$hcap = $key;
$tmp = $x;
}
}
if ($hcap) {
$_spreads[$oddnames[0]] = $_tmp[$hcap]['ele1'];
$_spreads[$oddnames[1]] = $_tmp[$hcap]['ele2'];
$_spreads[$oddnames[2]] = $hcap;
}
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Odds;
use App\Console\Commands\Grapper\Logifuture\Tools\ActiveHandicap;
use App\Models\OddsPoint;
use App\Utilities\Margin;
class StorePoints
{
public static function store(&$_spreads, $base)
{
ActiveHandicap::set($_spreads);
foreach ($_spreads as $handicap => $value) {
// code...
$odds = [];
$odds['home'] = $value['ele1'];
$odds['away'] = $value['ele2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['handicap'] = $handicap;
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds = array_merge($odds, $base);
$res = OddsPoint::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPoint::create($odds);
} else {
$res->home = number_format($odds['home'], 2);
$res->away = number_format($odds['away'], 2);
$res->handicap = number_format($odds['handicap'], 2);
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Odds;
use App\Console\Commands\Grapper\Logifuture\Tools\ActiveHandicap;
use App\Models\OddsPointQ1;
use App\Utilities\Margin;
class StorePointsQ1
{
public static function store(&$_spreads, $base)
{
ActiveHandicap::set($_spreads);
foreach ($_spreads as $handicap => $value) {
// code...
$odds = [];
$odds['home'] = $value['ele1'];
$odds['away'] = $value['ele2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['handicap'] = $handicap;
$odds['difference'] = abs(1 / $odds['home'] - 1 / $odds['away']);
$odds = array_merge($odds, $base);
$res = OddsPointQ1::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('handicap', $odds['handicap'])
->first();
if (! $res) {
OddsPointQ1::create($odds);
} else {
$res->home = number_format($odds['home'], 2);
$res->away = number_format($odds['away'], 2);
$res->handicap = number_format($odds['handicap'], 2);
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Odds;
use App\Console\Commands\Grapper\Logifuture\Tools\ActiveHandicap;
use App\Models\OddsTotal;
use App\Utilities\Margin;
class StoreTotals
{
public static function store(&$_spreads, $base)
{
ActiveHandicap::set($_spreads);
foreach ($_spreads as $total => $value) {
// code...
$odds = [];
$odds['over'] = $value['ele1'];
$odds['under'] = $value['ele2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['total'] = $total;
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds = array_merge($odds, $base);
$res = OddsTotal::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotal::create($odds);
} else {
$res->over = number_format($odds['over'], 2);
$res->under = number_format($odds['under'], 2);
$res->total = number_format($odds['total'], 2);
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands\Grapper\Logifuture\Odds;
use App\Console\Commands\Grapper\Logifuture\Tools\ActiveHandicap;
use App\Models\OddsTotalQ1;
use App\Utilities\Margin;
class StoreTotalsQ1
{
public static function store(&$_spreads, $base)
{
ActiveHandicap::set($_spreads);
foreach ($_spreads as $total => $value) {
// code...
$odds = [];
$odds['over'] = $value['ele1'];
$odds['under'] = $value['ele2'];
$odds['margin'] = (float) Margin::calculate($odds, 1);
$odds['active_spread'] = $value['active_spread'];
$odds['total'] = $total;
$odds['difference'] = abs(1 / $odds['over'] - 1 / $odds['under']);
$odds = array_merge($odds, $base);
$res = OddsTotalQ1::where('event_id', $base['event_id'])
->where('bookmaker_id', $base['bookmaker_id'])
->where('total', $odds['total'])
->first();
if (! $res) {
OddsTotalQ1::create($odds);
} else {
$res->over = number_format($odds['over'], 2);
$res->under = number_format($odds['under'], 2);
$res->total = number_format($odds['total'], 2);
if ($res->isDirty()) {
$res->oddchange_at = now();
}
$res->active_spread = $odds['active_spread'];
$res->difference = $odds['difference'];
$res->checked_at = now();
$res->margin = $odds['margin'];
$res->save();
}
}
}
}