Skip to content

Commit

Permalink
Merge pull request #399 from Zemill/develop
Browse files Browse the repository at this point in the history
Heroes Profile v0.1.2
  • Loading branch information
Zemill authored Nov 12, 2023
2 parents 0313d55 + fa8554c commit 60a1897
Show file tree
Hide file tree
Showing 69 changed files with 1,706 additions and 1,078 deletions.
22 changes: 16 additions & 6 deletions app/Http/Controllers/BattletagSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,26 @@ private function searchForBattletag($input)
$counter = 0;
$uniqueBlizzIDRegion = [];

$privateAccounts = $this->globalDataService->getPrivateAccounts();
foreach ($data as $row) {
$blizz_id = $row['blizz_id'];
$region = $row['region'];

if (array_key_exists($row['blizz_id'].'|'.$row['region'], $uniqueBlizzIDRegion)) {
if ($row['latest_game'] > $uniqueBlizzIDRegion[$row['blizz_id'].'|'.$row['region']]) {
$containsAccount = $privateAccounts->contains(function ($account) use ($blizz_id, $region) {
return $account['blizz_id'] == $blizz_id && $account['region'] == $region;
});

if (! $containsAccount) {

if (array_key_exists($row['blizz_id'].'|'.$row['region'], $uniqueBlizzIDRegion)) {
if ($row['latest_game'] > $uniqueBlizzIDRegion[$row['blizz_id'].'|'.$row['region']]) {
$returnData[$row['blizz_id'].'|'.$row['region']] = $row;
}
} else {
$uniqueBlizzIDRegion[$row['blizz_id'].'|'.$row['region']] = $row['latest_game'];
$returnData[$row['blizz_id'].'|'.$row['region']] = $row;
$counter++;
}
} else {
$uniqueBlizzIDRegion[$row['blizz_id'].'|'.$row['region']] = $row['latest_game'];
$returnData[$row['blizz_id'].'|'.$row['region']] = $row;
$counter++;
}

if ($counter == 50) {
Expand Down
21 changes: 8 additions & 13 deletions app/Http/Controllers/CompareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,48 +186,43 @@ public function getData(Request $request)

$columnStatistics = [];
foreach ($statistics as $column) {


$winCount = $result->where('winner', 1)->count();
$lossCount = $result->where('winner', 0)->count();
$averageValue = $result->avg($column);


$maxValue = $averageValue;


if ($maxValue > ($maxValues[$column] ?? 0)) {
$maxValues[$column] = round($maxValue, 2);
}

}

$columnStatistics[$column] = [
'avg_value' => round($averageValue, 2),
];
}

$returnData[$request[$player]['battletag']] = [
"battletag_short" => $request[$player]['battletag_short'],
"blizz_id" => $request[$player]['blizz_id'],
"region" => $request[$player]['region'],
"region_name" => $request[$player]['region_name'],
'battletag_short' => $request[$player]['battletag_short'],
'blizz_id' => $request[$player]['blizz_id'],
'region' => $request[$player]['region'],
'region_name' => $request[$player]['region_name'],
'wins' => $winCount,
'losses' => $lossCount,
'averages' => $columnStatistics,
];
}
}
foreach ($returnData as &$playerData) {
foreach ($playerData["averages"] as $stat => &$statData) {
foreach ($playerData['averages'] as $stat => &$statData) {
$maxValue = $maxValues[$stat] ?? 0;
$averageValue = $statData["avg_value"];
$averageValue = $statData['avg_value'];

$scaledValue = $maxValue > 0 ? ($averageValue / $maxValue) * 100 : 0;

$statData["scaled_value"] = round($scaledValue, 2);
$statData['scaled_value'] = round($scaledValue, 2);
}
}


return $returnData;
}
Expand Down
60 changes: 23 additions & 37 deletions app/Http/Controllers/Esports/EsportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,12 @@ public function getData(Request $request)
$this->esport = $request['esport'];
$this->tournament = $request['tournament'];

if($request['tournament'] == "main"){
$this->esport = "hi";
}else if($request['tournament'] == "nationscup"){
$this->esport = "hi_nc";
if ($request['tournament'] == 'main') {
$this->esport = 'hi';
} elseif ($request['tournament'] == 'nationscup') {
$this->esport = 'hi_nc';
}


$this->schema = 'heroesprofile';

$this->blizz_id = $request['blizz_id'];
Expand All @@ -672,27 +671,22 @@ public function getData(Request $request)
$this->hero = $request['hero'] ? session('heroes')->keyBy('name')[$request['hero']]->id : null;
$this->game_map = $request['game_map'] ? Map::where('name', $request['game_map'])->pluck('map_id')->toArray() : null;






if ($this->esport == 'CCL') {
$this->team = $request['team'] ? CCLTeam::where('season', $this->season)->where('team_name', $request['team'])->first()->team_id : null;
$this->team_name = $request['team'];
}else if ($this->esport == "HeroesInternational" && $this->tournament == "main") {
} elseif ($this->esport == 'HeroesInternational' && $this->tournament == 'main') {
$this->team = $request['team'] ? HeroesInternationalMainTeam::where('season', $this->season)->where('team_name', $request['team'])->first()->team_id : null;
$this->team_name = $request['team'];
}else if ($this->esport == "HeroesInternational" && $this->tournament == "nationscup") {
} elseif ($this->esport == 'HeroesInternational' && $this->tournament == 'nationscup') {
$this->team = $request['team'] ? HeroesInternationalNationsCupTeam::where('season', $this->season)->where('team_name', $request['team'])->first()->team_id : null;
$this->team_name = $request['team'];
}

if ($this->esport == 'MastersClash') {
$this->schema .= '_mcl';
}elseif ($this->esport == "HeroesInternational" && $this->tournament == "main") {
} elseif ($this->esport == 'HeroesInternational' && $this->tournament == 'main') {
$this->schema .= '_hi';
}elseif ($this->esport) {
} elseif ($this->esport) {
$this->schema .= '_'.strtolower($this->esport);
}

Expand Down Expand Up @@ -844,13 +838,12 @@ public function getData(Request $request)

$battletag = explode('#', $battletag)[0];

if($this->esport == "hi" || $this->esport == "hi_nc"){
if ($this->esport == 'hi' || $this->esport == 'hi_nc') {
$playerlink = "/Esports/HeroesInternational/Player/{$battletag}/{$blizzId}";
}else{
} else {
$playerlink = "/Esports/{$this->esport}/Player/{$battletag}/{$blizzId}";
}


if ($this->season) {
$playerlink .= "?season={$this->season}";

Expand All @@ -873,10 +866,9 @@ public function getData(Request $request)
$playerlink .= "?tournament={$this->tournament}";
}


if($this->esport == "hi" || $this->esport == "hi_nc"){
if ($this->esport == 'hi' || $this->esport == 'hi_nc') {
$herolink = "/Esports/HeroesInternational/Player/{$battletag}/{$blizzId}/Hero/{$heroData[$mostPlayedHero]['name']}";
}else{
} else {
$herolink = "/Esports/{$this->esport}/Player/{$battletag}/{$blizzId}/Hero/{$heroData[$mostPlayedHero]['name']}";
}

Expand Down Expand Up @@ -959,36 +951,31 @@ public function getData(Request $request)

$gamesPlayed = $wins + $losses;


if($this->esport == "hi" || $this->esport == "hi_nc"){
if ($this->esport == 'hi' || $this->esport == 'hi_nc') {
$link = "/Esports/HeroesInternational/Player/{$this->battletag}/{$this->blizz_id}/Hero/{$heroData[$group[0]->hero]['name']}";

}else{
} else {
$link = "/Esports/{$this->esport}/Player/{$this->battletag}/{$this->blizz_id}/Hero/{$heroData[$group[0]->hero]['name']}";
}


if ($this->season) {
$link .= "?season={$this->season}";

if ($this->division) {
$link .= "&division={$this->division}";
}
if($this->tournament){
if ($this->tournament) {
$link .= "&tournament={$this->tournament}";
}
} elseif ($this->division) {
$link .= "?division={$this->division}";
if($this->tournament){
if ($this->tournament) {
$link .= "&tournament={$this->tournament}";
}
}elseif($this->tournament){
} elseif ($this->tournament) {
$link .= "?tournament={$this->tournament}";
}




return [
'hero_id' => $group[0]->hero,
'hero' => $heroData[$group[0]->hero],
Expand Down Expand Up @@ -1030,10 +1017,9 @@ public function getData(Request $request)

$gamesPlayed = $wins + $losses;


if($this->esport == "hi" || $this->esport == "hi_nc"){
if ($this->esport == 'hi' || $this->esport == 'hi_nc') {
$link = "/Esports/HeroesInternational/Player/{$this->battletag}/{$this->blizz_id}/Map/{$maps[$group[0]->game_map]['name']}";
}else{
} else {
$link = "/Esports/{$this->esport}/Player/{$this->battletag}/{$this->blizz_id}/Map/{$maps[$group[0]->game_map]['name']}";
}

Expand Down Expand Up @@ -1343,18 +1329,18 @@ private function getTopEnemyTeams($replayIDs, $team, $teamImageMap)
} elseif ($this->esport == 'MastersClash') {
$image = '/images/MCL/'.$image;
} elseif ($this->esport == 'hi') {
$image = '/images/HI/Team/Logos/'.$image.".png";
$image = '/images/HI/Team/Logos/'.$image.'.png';
} elseif ($this->esport == 'hi_nc') {
$image = '/images/HI/Flags/'.$image.".png";
$image = '/images/HI/Flags/'.$image.'.png';
}

$returnData[$counter]['icon_url'] = $image;

$returnData[$counter]['inputhover'] = 'Lost agains team '.$enemyteam.' '.$count.' times ('.round((($count / (count($replayIDs))) * 100) * 5, 2).'% of all games lost as '.$team.')';

if($this->esport == "hi" || $this->esport == "hi_nc"){
if ($this->esport == 'hi' || $this->esport == 'hi_nc') {
$enemy_link = "/Esports/HeroesInternational/Team/{$enemyteam}";
}else{
} else {
$enemy_link = "/Esports/{$this->esport}/Team/{$enemyteam}";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
namespace App\Http\Controllers\Esports\HeroesInternational;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;

use App\Models\HeroesInternational\HeroesInternationalMainTeam;
use App\Models\HeroesInternational\HeroesInternationalNationsCupTeam;

use App\Models\Map;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

class HeroesInternationalController extends Controller
{
private $esport;


public function show(Request $request)
{
$validationRules = [
Expand All @@ -32,27 +29,27 @@ public function show(Request $request)
];
}

$tournament = $request['tournament'];

$tournament = $request["tournament"];

if($tournament == "main"){
if ($tournament == 'main') {
return view('Esports.HeroesInternational.heroesInternationalMain')
->with([
'defaultseason' => 1,
'filters' => $this->globalDataService->getFilterData(),
'talentimages' => $this->globalDataService->getPreloadTalentImageUrls(),
]);
}else if($tournament == "nationscup"){
return view('Esports.HeroesInternational.heroesInternationalNationsCup')
} elseif ($tournament == 'nationscup') {
return view('Esports.HeroesInternational.heroesInternationalNationsCup')
->with([
'defaultseason' => 1,
'filters' => $this->globalDataService->getFilterData(),
'talentimages' => $this->globalDataService->getPreloadTalentImageUrls(),
]);
}else{
} else {
return view('Esports.HeroesInternational.heroesInternationalEntry');
}
}

public function getTeamsData(Request $request)
{
//return response()->json($request->all());
Expand Down Expand Up @@ -80,7 +77,6 @@ public function getTeamsData(Request $request)
return HeroesInternationalNationsCupTeam::where('season', $request['season'])->get();
}


}

public function getRecentMatchData(Request $request)
Expand Down Expand Up @@ -108,17 +104,15 @@ public function getRecentMatchData(Request $request)
$pagination_page = $request['pagination_page'];
$perPage = 1000;

$this->schema = 'heroesprofile_' . $this->esport;
$this->schema = 'heroesprofile_'.$this->esport;

$results = DB::table($this->schema . '.replay')->select($this->schema.'.replay.replayID', 'hero', 'game_map', 'replay.team_0_id', 'replay.team_1_id', 'round', 'game', 'game_date')
$results = DB::table($this->schema.'.replay')->select($this->schema.'.replay.replayID', 'hero', 'game_map', 'replay.team_0_id', 'replay.team_1_id', 'round', 'game', 'game_date')
->join($this->schema.'.player', $this->schema.'.player.replayID', '=', $this->schema.'.replay.replayID')
->join($this->schema.'.teams', $this->schema.'.teams.team_id', '=', $this->schema.'.player.team_id')
->orderBy('game_date', 'DESC')
->where('replay.season', $season)
->paginate($perPage, ['*'], 'page', $pagination_page);



$heroData = $this->globalDataService->getHeroes();
$heroData = $heroData->keyBy('id');

Expand All @@ -135,12 +129,10 @@ public function getRecentMatchData(Request $request)
$groupedResults = $results->groupBy('replayID')->map(function ($group) use ($heroData, $maps) {
$heroes = [];


for ($i = 0; $i < 10; $i++) {
$heroes[$i] = isset($group[$i]) && isset($group[$i]->hero) ? $heroData[$group[$i]->hero] : null;
}


return [
'replayID' => $group[0]->replayID,
'game_date' => $group[0]->game_date,
Expand Down
10 changes: 4 additions & 6 deletions app/Http/Controllers/Global/GlobalHeroMatchupStatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\GlobalHeromatchupsAlly;
use App\Models\GlobalHeromatchupsEnemy;
use App\Models\Hero;
use App\Rules\HeroInputValidation;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
Expand Down Expand Up @@ -106,7 +105,7 @@ public function getHeroMatchupData(Request $request)
->orderBy('ally')
//->toSql();
->get();
$allyData = $this->combineData($allyData, 'ally');
$allyData = $this->combineData($allyData, 'ally', $hero);

$enemyData = GlobalHeromatchupsEnemy::query()
->select('enemy', 'win_loss')
Expand All @@ -125,7 +124,7 @@ public function getHeroMatchupData(Request $request)
->groupBy('win_loss')
//->toSql();
->get();
$enemyData = $this->combineData($enemyData, 'enemy');
$enemyData = $this->combineData($enemyData, 'enemy', $hero);

$allyDataKeyed = collect($allyData)->keyBy(function ($item) {
return $item['hero']['name'];
Expand Down Expand Up @@ -157,7 +156,7 @@ public function getHeroMatchupData(Request $request)
return $data;
}

private function combineData($data, $type)
private function combineData($data, $type, $heroID)
{

$heroData = $this->globalDataService->getHeroes();
Expand Down Expand Up @@ -194,13 +193,12 @@ private function combineData($data, $type)
}
}

if (! $found) {
if (! $found && $heroID != $hero->id) {
$notFound[] = $hero;
}
}

foreach ($notFound as $hero) {
// Add the missing hero as a separate array to $combinedData
$combinedData[] = [
'hero' => $hero,
'wins' => 0,
Expand Down
Loading

0 comments on commit 60a1897

Please sign in to comment.