filter playeer played

This commit is contained in:
salam committed 2026-06-27 18:49:29 +02:00
1 parent 74e9285bac
commit 5081ec9e32
30 files changed
+4114 -1420

No files matched your search

+1 -1
View File
@@ -56,7 +56,7 @@ class Sofascore
}
if ($debug) {
Notice::note(Nuh::$options['sport'].' '.Nuh::$options['name'], 'bb');
Notice::note(Nuh::$options['sport'] ?? 'All'.' '.Nuh::$options['name'], 'bb');
}
switch (Nuh::$options['name']) {
@@ -92,14 +92,14 @@ class EventsDatabase
$data = CurlSofa::load($url);
$data['id'] = $event_id;
File::put($folder.'/statistics.json', json_encode($data));
/*********************************
* EVENT lineups
*********************************/
$event_id = $event['id'];
$url = Nuh::$options['base_url']."api/v1/event/$event_id/lineups";
$rand = rand(500000, 1000000);
@@ -110,14 +110,14 @@ class EventsDatabase
$data = CurlSofa::load($url);
$data['id'] = $event_id;
File::put($folder.'/lineups.json', json_encode($data));
/*********************************
* EVENT lineups
*********************************/
$event_id = $event['id'];
$url = Nuh::$options['base_url']."api/v1/event/$event_id/odds/1/all";
$rand = rand(500000, 1000000);
@@ -128,6 +128,8 @@ class EventsDatabase
$data = CurlSofa::load($url);
$data['id'] = $event_id;
File::put($folder.'/odds.json', json_encode($data));
}
}
@@ -2,129 +2,31 @@
namespace App\Console\Commands\Grapper\Sofascore;
use App\Console\Commands\Grapper\Sofascore\Specials\CountPlayerPerSeason;
use App\Console\Commands\Nuh;
use App\Utilities\Notice;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\File;
ini_set('magic_quotes_runtime', false);
class Special
{
public static $max_days = 30;
public static Carbon $days_back;
public static $storage_path = '/Console/Commands/Grapper/Sofascore/worldcup-teams/';
public static function load()
{
$debug = Nuh::$options['d'] ?? 0;
$url = Nuh::$options['base_url'].'/api/v1/world-cup/meet-the-team';
$special = Nuh::$options['special'];
$rand = rand(500000, 1000000);
if ($debug) {
Notice::note("Sleep $rand msec", 'y');
}
usleep($rand);
$data = CurlSofa::load($url);
$teams = [];
foreach ($data['groups'] as $groups) {
foreach ($groups['teams'] as $team) {
$teams[] = [
'id' => $team['team']['id'],
'slug' => $team['team']['slug'],
'name' => $team['team']['name'],
];
}
}
foreach ($teams as $team) {
Nuh::$options['s'] = 0;
Nuh::$options['r'] = 0;
$url = 'https://www.sofascore.com/api/v1/team/'.$team['id'].'/events/last/0';
$data = CurlSofa::load($url);
foreach ($data['events'] as $event) {
// "id" => 12749524
// "slug" => "mexico-usa"
// "startTimestamp" => 1729045800
$event_id = $event['id'];
/*********************************
* Folder
*********************************/
$starttime = Carbon::createFromTimestamp($event['startTimestamp'])->format('Y-m-d');
$folder = app_path().self::$storage_path.$starttime.'/'.$event['tournament']['slug'].'/'.$event['slug'];
File::makeDirectory($folder, 0775, true, true);
/*********************************
* EVENT event basic
*********************************/
File::put($folder.'/event.json', json_encode($event));
/*********************************
* EVENT statistics
*********************************/
$url = Nuh::$options['base_url']."api/v1/event/$event_id/statistics";
$rand = rand(500000, 1000000);
if ($debug) {
Notice::note("Sleep $rand msec", 'y');
switch($special){
case 1:
if($debug){
Notice::note('For speed in Statistiko'.PHP_EOL.'Count for every player how many time he has player per season and write it to DB', 'g');
}
usleep($rand);
$data = CurlSofa::load($url);
File::put($folder.'/statistics.json', json_encode($data));
/*********************************
* EVENT lineups
*********************************/
$url = Nuh::$options['base_url']."api/v1/event/$event_id/lineups";
$rand = rand(500000, 1000000);
if ($debug) {
Notice::note("Sleep $rand msec", 'y');
}
usleep($rand);
$data = CurlSofa::load($url);
File::put($folder.'/lineups.json', json_encode($data));
/*********************************
* EVENT lineups
*********************************/
$event_id = $event['id'];
$url = Nuh::$options['base_url']."api/v1/event/$event_id/odds/1/all";
$rand = rand(500000, 1000000);
if ($debug) {
Notice::note("Sleep $rand msec", 'y');
}
usleep($rand);
$data = CurlSofa::load($url);
File::put($folder.'/odds.json', json_encode($data));
}
CountPlayerPerSeason::run();
break;
default:
Notice::note('special ID not set process stopped', 'br', 1);
}
}
}
@@ -0,0 +1,60 @@
<?php
namespace App\Console\Commands\Grapper\Sofascore\Specials;
use App\Models\SofaScorePlayerPerSeason;
use App\Models\StatistikoDetail;
use App\Models\StatistikoPlayer;
class CountPlayerPerSeason
{
public static function run()
{
$res = StatistikoDetail::query()->select('tm_player_id', 'txodds_id')->get();
foreach ($res as $val) {
$collection = [];
$res2 = StatistikoPlayer::with('event')->where('tm_player_id', $val->tm_player_id)->get();
foreach ($res2 as $val2) {
if(!isset($collection[$val2->event->season])){
$collection[$val2->event->season]['events_played_home'] = 0;
$collection[$val2->event->season]['events_played_away'] = 0;
$collection[$val2->event->season]['minutes_played_home'] = 0;
$collection[$val2->event->season]['minutes_played_away'] = 0;
}
if($val2->minutes_played > 0){
if($val->txodds_id == $val2->event->home_id){
$collection[$val2->event->season]['events_played_home'] += 1;
$collection[$val2->event->season]['minutes_played_home'] += $val2->minutes_played;
}
else if($val->txodds_id == $val2->event->away_id){
$collection[$val2->event->season]['events_played_away'] += 1;
$collection[$val2->event->season]['minutes_played_away'] += $val2->minutes_played;
}
}
}
foreach ($collection as $season => $row) {
if($val->txodds_id && $val->tm_player_id){
SofaScorePlayerPerSeason::updateOrCreate(
[
'tm_player_id' => $val->tm_player_id,
'tx_team_id' => $val->txodds_id,
'season' => $season
],
[
'events_played_home' => $row['events_played_home'],
'events_played_away' => $row['events_played_away'],
'minutes_played_home' => $row['minutes_played_home'],
'minutes_played_away' => $row['minutes_played_away'],
]
);
}
}
}
}
}
+2 -1
View File
@@ -23,7 +23,7 @@ class Nuh extends Command
public static $id = 0;
protected $signature = 'nuh {process=help} {--truncate} {--groups=0} {--days=0} {--day=0} {--id=0} {--fn=} {--gid=} {--p} {--d} {--x} {--t} {--w} {--a} {--r} {--s} {--g} {--t} {--q} {--f} {--b} {--e} {--z}';
protected $signature = 'nuh {process=help} {--truncate} {--groups=0} {--days=0} {--day=0} {--id=0} {--special=0} {--fn=} {--gid=} {--p} {--d} {--x} {--t} {--w} {--a} {--r} {--s} {--g} {--t} {--q} {--f} {--b} {--e} {--z}';
public function handle()
{
@@ -51,6 +51,7 @@ class Nuh extends Command
$txt .= '--days (optional) grap days back from yesterday' . PHP_EOL;
$txt .= '--groups (optional) csv of tournament_id\'s' . PHP_EOL;
$txt .= '--p will print days and tournaments and stop' . PHP_EOL;
$txt .= '--special (generate data) [1 => count played/season]' . PHP_EOL;
$txt .= '-----------------------------------------------------------' . PHP_EOL . PHP_EOL;
$txt .= 'Options' . PHP_EOL;
$txt .= '-----------------------------------------------------------' . PHP_EOL;