This commit is contained in:
salam committed 2026-01-26 18:26:02 +01:00
1 parent 9ca5657827
commit 6f3d608704
47 files changed
+1005 -145

No files matched your search

@@ -0,0 +1,30 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use App\Console\Commands\Nuh;
use App\Models\ComparingBookmaker;
class AlarmBookmakerFilter
{
public static function get($client_bookmaker_id)
{
$res = ComparingBookmaker::where('sport_id', Nuh::$options['sport_id'])
->where('client_bookmaker_id', $client_bookmaker_id)
->where('is_active', 1)
->orderBy('sorting', 'asc')
->select('bookmaker_id', 'time_lastcheck', 'margin_threshold', 'sorting')
->get();
$arr = [];
foreach ($res as $value) {
$arr[$value->bookmaker_id] = [
'sorting' => $value->sorting,
'time_lastcheck' => $value->time_lastcheck,
'margin_threshold' => $value->margin_threshold,
];
}
return $arr;
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
class AlarmFilterClient
{
public static function get($odds, $client_bookmaker_id)
{
if (isset($odds[$client_bookmaker_id])) {
return $odds[$client_bookmaker_id];
}
return [];
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
class AlarmFilterCompare
{
public static function get($odds, $filter)
{
foreach ($filter as $bookmaker_id => $value) {
if (isset($odds[$bookmaker_id])) {
$data = $odds[$bookmaker_id];
if ($data['margin'] <= $value['margin_threshold']) {
$data['bookmaker_id'] = $bookmaker_id;
return $data;
}
}
}
return [];
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use Illuminate\Support\Facades\DB;
class AlarmLoadOdds
{
public static function get($event_id, $table, $oddnames)
{
$res = DB::table($table)->where('flags', 1)->where('event_id', $event_id)->get();
$odds = explode(',', $oddnames);
$arr = [];
foreach ($res as $value) {
if ($table == 'odds_dc') {
$arr[(int) $value->bookmaker_id]['margin'] = (float) $value->margin * 2;
} else {
$arr[(int) $value->bookmaker_id]['margin'] = (float) $value->margin;
}
foreach ($odds as $odd) {
$arr[(int) $value->bookmaker_id][$odd] = (float) $value->$odd;
}
}
return $arr;
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
class AlarmMap
{
public static function get($table)
{
$map = [
'odds_2ways' => ['alarm_2w_h2w' => 'h3w', 'alarm_2w_a2w' => 'a2w'],
'odds_2ways_s1' => ['alarm_2ws1_h2w' => 'h3w', 'alarm_2ws1_a2w' => 'a2w'],
'odds_3ways' => ['alarm_3w_h3w' => 'h3w', 'alarm_3w_d3w' => 'd3w', 'alarm_3w_a3w' => 'a3w'],
'odds_3ways_ht' => ['alarm_3wht_h3w' => 'h3w', 'alarm_3wht_d3w' => 'd3w', 'alarm_3wht_a3w' => 'a3w'],
'odds_dc' => ['alarm_dc_dc1x' => 'dc1x', 'alarm_dc_dc12' => 'dc12', 'alarm_dc_dcx2' => 'dcx2'],
'odds_dnb' => ['alarm_dbn_dnb1' => 'dnb1', 'alarm_dbn_dnb2' => 'dnb2'],
'odds_ggng' => ['alarm_ggng_gg' => 'gg', 'alarm_ggng_ng' => 'ng'],
'odds_points' => ['alarm_po_home' => 'home', 'alarm_po_away' => 'away'],
'odds_points_ht' => ['alarm_poht_home' => 'home', 'alarm_poht_away' => 'away'],
'odds_points_q1' => ['alarm_poq1_home' => 'home', 'alarm_poq1_away' => 'away'],
'odds_totals' => ['alarm_to_over' => 'over', 'alarm_to_under' => 'under'],
'odds_totals_ht' => ['alarm_toht_over' => 'over', 'alarm_toht_under' => 'under'],
'odds_totals_q1' => ['alarm_toq1_over' => 'over', 'alarm_toq1_under' => 'under'],
'odds_tq' => ['alarm_tq_htq' => 'htq', 'alarm_tq_atq' => 'atq'],
];
return $map[$table];
}
}
@@ -0,0 +1,24 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use App\Console\Commands\Nuh;
use App\Models\MultilineSetting;
class AlarmMultilineSetting
{
public static function get()
{
$res = MultilineSetting::where('sport_id', Nuh::$options['sport_id'])->get();
$arr = [];
foreach ($res as $value) {
$arr[$value->id] = [
'table' => $value->table,
'oddnames' => $value->oddnames,
];
}
return $arr;
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use App\Console\Commands\Nuh;
use App\Models\AlarmSetting;
class AlarmSettings
{
public static function get($client_bookmaker_id)
{
$res = AlarmSetting::where('sport_id', Nuh::$options['sport_id'])
->where('client_bookmaker_id', $client_bookmaker_id)
->where('disabled', 0)
->select('multiline_setting_id', 'level_id', 'alarm_threshold')
->get();
$arr = [];
foreach ($res as $value) {
$arr[$value->multiline_setting_id][$value->level_id] = $value->alarm_threshold;
}
return $arr;
}
}
@@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands\Services\Tasks\Alarm;
use App\Models\EventBookmaker;
class AlarmStore
{
public static function get($event_id, $table, $client_bookmaker_id, $alarm_threshold, $compare_odds, $client_odds)
{
$oddnames = AlarmMap::get($table);
if (! $compare_odds) {
return;
}
if (! $client_odds) {
return;
}
$update_array = [];
foreach ($oddnames as $fieldname => $oddname) {
$threshold = $client_odds[$oddname] - $compare_odds[$oddname];
if ($threshold > $alarm_threshold[3]) {
// ROT
$update_array[$fieldname] = 3;
} elseif ($threshold > $alarm_threshold[2]) {
// ORANGE
$update_array[$fieldname] = 2;
} elseif ($threshold > $alarm_threshold[1]) {
// GRÜNE
$update_array[$fieldname] = 1;
} else {
// Rset Alarm
$update_array[$fieldname] = 0;
}
}
EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $client_bookmaker_id)->update($update_array);
}
}
@@ -0,0 +1,57 @@
<?php
namespace App\Console\Commands\Services\Tasks;
use App\Console\Commands\Nuh;
use App\Console\Commands\Services\Tasks\Alarm\AlarmBookmakerFilter;
use App\Console\Commands\Services\Tasks\Alarm\AlarmFilterClient;
use App\Console\Commands\Services\Tasks\Alarm\AlarmFilterCompare;
use App\Console\Commands\Services\Tasks\Alarm\AlarmLoadOdds;
use App\Console\Commands\Services\Tasks\Alarm\AlarmMultilineSetting;
use App\Console\Commands\Services\Tasks\Alarm\AlarmSettings;
use App\Console\Commands\Services\Tasks\Alarm\AlarmStore;
use App\Models\Client;
use App\Models\EventBookmaker;
use App\Utilities\Notice;
class AlarmGenerator
{
public static function run()
{
$debug = Nuh::$options['d'] ?? 0;
if ($debug) {
Notice::note('ALARM GENERATOR', 'b');
}
$clients = Client::get();
$multilines = AlarmMultilineSetting::get();
foreach ($clients as $client) {
foreach ($client->bookmaker as $client_bookmaker_id) {
$alarm_threshold = AlarmSettings::get($client_bookmaker_id);
$filter = AlarmBookmakerFilter::get($client_bookmaker_id);
$res = EventBookmaker::where('bookmaker_id', $client_bookmaker_id)->where('sport_id', Nuh::$options['sport_id'])->get();
foreach ($res as $event) {
foreach ($multilines as $multiline_id => $multiline) {
$odds = AlarmLoadOdds::get($event->event_id, $multiline['table'], $multiline['oddnames']);
$compare_odds = AlarmFilterCompare::get($odds, $filter);
$client_odds = AlarmFilterClient::get($odds, $client_bookmaker_id);
AlarmStore::get($event->event_id, $multiline['table'], $client_bookmaker_id, $alarm_threshold[$multiline_id], $compare_odds, $client_odds);
}
}
}
}
}
}
@@ -3,6 +3,7 @@
namespace App\Console\Commands\Services\Tasks;
use App\Console\Commands\Nuh;
use App\Models\AlarmSetting;
use App\Models\BettypeUser;
use App\Models\Bookmaker;
use App\Models\Client;
@@ -24,11 +25,45 @@ class GenerateDefaultSetting
}
/**************************************************
* MULTILINE SLOTS
* 1) ALARM BOOKMAKER
**************************************************/
if ($debug) {
Notice::note('1) MULTILINE SLOTS', 'p');
Notice::note('1) ALARM BOOKMAKER', 'p');
}
$alarm_thresholds = [1 => 0.01, 2 => 0.2, 3 => 0.3];
$clients = Client::get();
foreach ($clients as $client) {
foreach ($client->sport as $sport_id) {
foreach ($client->bookmaker as $client_bookmaker_id) {
$multilines = MultilineSetting::where('sport_id', $sport_id)->get()->pluck('id');
foreach ($multilines as $multiline_id) {
foreach ($alarm_thresholds as $level_id => $alarm_threshold) {
AlarmSetting::firstOrCreate(
['client_bookmaker_id' => $client_bookmaker_id, 'sport_id' => $sport_id, 'multiline_setting_id' => $multiline_id, 'level_id' => $level_id],
['name' => "LEVEL $level_id", 'alarm_threshold' => $alarm_threshold]
);
}
}
}
}
}
/**************************************************
* 2) MULTILINE SLOTS
**************************************************/
if ($debug) {
Notice::note('2) MULTILINE SLOTS', 'p');
}
$bookmaker_slots = [1 => 6, 2 => 30, 3 => 649, 4 => 126];
@@ -58,11 +93,11 @@ class GenerateDefaultSetting
}
/**************************************************
* BETTYPES for USER in MONITOR
* 3) BETTYPES for USER in MONITOR
**************************************************/
if ($debug) {
Notice::note('2) GENERATOR BETTYPES IM COMPARATORE FOR USERS', 'p');
Notice::note('3) GENERATOR BETTYPES IM COMPARATORE FOR USERS', 'p');
}
$users = User::get();
@@ -83,11 +118,11 @@ class GenerateDefaultSetting
}
/**************************************************
* COMPARING BOOKMAKER
* 4) COMPARING BOOKMAKER
**************************************************/
if ($debug) {
Notice::note('3) COMPARING BOOKMAKER', 'p');
Notice::note('4) COMPARING BOOKMAKER', 'p');
}
$res = Client::get();
@@ -104,13 +139,12 @@ class GenerateDefaultSetting
$i = 1;
foreach ($bookmakers_soccer as $bookmaker_id) {
$margin_threshold = $bookmaker_id == 110 ? 103 : 115;
ComparingBookmaker::updateOrCreate(
['method_id' => 1, 'sport_id' => 1, 'client_bookmaker_id' => $client_bookmaker_id, 'bookmaker_id' => $bookmaker_id],
['is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => 110, 'sorting' => $i]
['is_active' => 1, 'time_lastcheck' => 600, 'margin_threshold' => $margin_threshold, 'sorting' => $i]
);
$i++;
}
}
}