Skip to content

Commit

Permalink
Merge pull request #267 from Zemill/develop
Browse files Browse the repository at this point in the history
Heroes Profile v0.0.2
  • Loading branch information
Zemill authored Sep 18, 2023
2 parents 1036293 + d4824a3 commit 940b41e
Show file tree
Hide file tree
Showing 47 changed files with 2,507 additions and 793 deletions.
531 changes: 0 additions & 531 deletions app/Http/Controllers/Player/PlayerHeroesController.php

Large diffs are not rendered by default.

650 changes: 650 additions & 0 deletions app/Http/Controllers/Player/PlayerHeroesMapsRolesController.php

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions app/Http/Controllers/Player/PlayerMapsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace App\Http\Controllers\Player;
use App\Services\GlobalDataService;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use App\Rules\SingleGameMapInputValidation;

class PlayerMapsController extends Controller
{
protected $globalDataService;

public function __construct(GlobalDataService $globalDataService)
{
$this->globalDataService = $globalDataService;
}

public function showAll(Request $request, $battletag, $blizz_id, $region)
{
$validator = \Validator::make(compact('battletag', 'blizz_id', 'region'), [
'battletag' => 'required|string',
'blizz_id' => 'required|integer',
'region' => 'required|integer'
]);

if ($validator->fails()) {
return redirect('/');
}


return view('Player.Maps.allMapData')->with([
'battletag' => $battletag,
'blizz_id' => $blizz_id,
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
]);
}

public function showSingle(Request $request, $battletag, $blizz_id, $region, $role){
$validator = \Validator::make(compact('battletag', 'blizz_id', 'region'), [
'battletag' => 'required|string',
'blizz_id' => 'required|integer',
'region' => 'required|integer'
]);

if ($validator->fails()) {
return redirect('/');
}
$map = (new SingleGameMapInputValidation())->passes('map', $request["map"]);


return view('Player.Maps.singleMapData')->with([
'battletag' => $battletag,
'blizz_id' => $blizz_id,
'region' => $region,
'map' => $map,
'filters' => $this->globalDataService->getFilterData(),
'regions' => $this->globalDataService->getRegionIDtoString(),
]);
}
}
135 changes: 135 additions & 0 deletions app/Http/Controllers/Player/PlayerMatchupsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

namespace App\Http\Controllers\Player;
use App\Services\GlobalDataService;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

use App\Rules\SeasonInputValidation;
use App\Rules\GameMapInputValidation;
use App\Rules\GameTypeInputValidation;
use App\Rules\HeroInputByIDValidation;


class PlayerMatchupsController extends Controller
{
protected $globalDataService;

public function __construct(GlobalDataService $globalDataService)
{
$this->globalDataService = $globalDataService;
}

public function show(Request $request, $battletag, $blizz_id, $region)
{
$validator = \Validator::make(compact('battletag', 'blizz_id', 'region'), [
'battletag' => 'required|string',
'blizz_id' => 'required|integer',
'region' => 'required|integer'
]);

if ($validator->fails()) {
return redirect('/');
}


return view('Player.matchupData')->with([
'battletag' => $battletag,
'blizz_id' => $blizz_id,
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
]);
}

public function getMatchupData(Request $request){
//return response()->json($request->all());

$validator = \Validator::make($request->only(['blizz_id', 'region']), [
'blizz_id' => 'required|integer',
'region' => 'required|integer',
]);

$blizz_id = $request['blizz_id'];
$region = $request['region'];

$gameType = (new GameTypeInputValidation())->passes('game_type', $request["game_type"]);
$gameMap = (new GameMapInputValidation())->passes('map', $request["map"]);
$hero = (new HeroInputByIDValidation())->passes('statfilter', $request["hero"]);
$season = (new SeasonInputValidation())->passes('season', $request["season"]);

$returnData = [];

$heroData = $this->globalDataService->getHeroes();

foreach ($heroData as $hero) {
$returnData[$hero->id]['ally_wins'] = 0;
$returnData[$hero->id]['ally_losses'] = 0;
$returnData[$hero->id]['enemy_wins'] = 0;
$returnData[$hero->id]['enemy_losses'] = 0;
}
$heroData = $heroData->keyBy('id');

for($i = 0; $i <= 1; $i++){
$subquery = DB::table('player')
->join('replay', 'replay.replayID', '=', 'player.replayID')
->where('blizz_id', $blizz_id)
->where('region', $region)
->where('team', $i)
->where('replay.game_type', '<>', 0)
->select('player.replayID');

$result = DB::table('player')
->whereIn('replayID', $subquery)
->where('blizz_id', '<>', $blizz_id)
->groupBy('hero', 'team', 'winner')
->select('hero', 'team', 'winner', DB::raw('COUNT(*) AS total'))
->get();

foreach($result as $hero => $value)
{
$returnData[$value->hero]["hero"] = $heroData[$value->hero];
$returnData[$value->hero]["name"] = $heroData[$value->hero]["name"];
if($value->team == $i){
if($value->winner == 0){
$returnData[$value->hero]["ally_losses"] += $value->total;
}else{
$returnData[$value->hero]["ally_wins"] += $value->total;
}
$returnData[$value->hero]["ally_games_played"] = $returnData[$value->hero]["ally_wins"] + $returnData[$value->hero]["ally_losses"];
$returnData[$value->hero]["ally_win_rate"] = $returnData[$value->hero]["ally_games_played"] ? round(($returnData[$value->hero]["ally_wins"] / $returnData[$value->hero]["ally_games_played"]) * 100, 2): 0;
}else{
if($value->winner == 0){
$returnData[$value->hero]["enemy_losses"] += $value->total;
}else{
$returnData[$value->hero]["enemy_wins"] += $value->total;
}
$returnData[$value->hero]["enemy_games_played"] = $returnData[$value->hero]["enemy_wins"] + $returnData[$value->hero]["enemy_losses"];
$returnData[$value->hero]["enemy_win_rate"] = $returnData[$value->hero]["enemy_games_played"] ? round(100 - ($returnData[$value->hero]["enemy_wins"] / $returnData[$value->hero]["enemy_games_played"]) * 100, 2): 0;
}
}
}
$topFiveAllyHeroes = collect($returnData)
->filter(function($value, $key) {
return $value['ally_games_played'] >= 5;
})
->sortByDesc('ally_win_rate')
->take(5)->values();

$topFiveEnemyHeroes = collect($returnData)
->filter(function($value, $key) {
return $value['enemy_games_played'] >= 5;
})
->sortBy('enemy_win_rate')
->take(5)->values();

$returnData = array_values($returnData);

usort($returnData, function ($a, $b) {
return strcmp($a['name'], $b['name']);
});

return ["tabledata" => $returnData, "top_five_heroes" => $topFiveAllyHeroes , "top_five_enemies" => $topFiveEnemyHeroes];
}

}
64 changes: 64 additions & 0 deletions app/Http/Controllers/Player/PlayerRolesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Http\Controllers\Player;
use App\Services\GlobalDataService;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use App\Rules\RoleInputValidation;


class PlayerRolesController extends Controller
{
protected $globalDataService;

public function __construct(GlobalDataService $globalDataService)
{
$this->globalDataService = $globalDataService;
}

public function showAll(Request $request, $battletag, $blizz_id, $region)
{
$validator = \Validator::make(compact('battletag', 'blizz_id', 'region'), [
'battletag' => 'required|string',
'blizz_id' => 'required|integer',
'region' => 'required|integer'
]);

if ($validator->fails()) {
return redirect('/');
}


return view('Player.Roles.allRoleData')->with([
'battletag' => $battletag,
'blizz_id' => $blizz_id,
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
]);
}

public function showSingle(Request $request, $battletag, $blizz_id, $region, $role){
$validator = \Validator::make(compact('battletag', 'blizz_id', 'region'), [
'battletag' => 'required|string',
'blizz_id' => 'required|integer',
'region' => 'required|integer'
]);

if ($validator->fails()) {
return redirect('/');
}
$role = (new RoleInputValidation())->passes('role', $request["role"]);


return view('Player.Roles.singleRoleData')->with([
'battletag' => $battletag,
'blizz_id' => $blizz_id,
'region' => $region,
'role' => $role,
'filters' => $this->globalDataService->getFilterData(),
'regions' => $this->globalDataService->getRegionIDtoString(),
]);
}
}
30 changes: 30 additions & 0 deletions app/Rules/SingleGameMapInputValidation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;
use App\Models\Map;

class SingleGameMapInputValidation implements Rule
{
public function passes($attribute, $value)
{
$validMaps = Map::where('playable', '<>', 0)
->pluck('name')
->toArray();

if(!in_array($value, $validMaps)){
return;
}

$mapId = Map::where('name', $value)
->pluck('map_id')->first();

return $mapId;
}

public function message()
{
return 'The selected game types are invalid.';
}
}
5 changes: 2 additions & 3 deletions app/Rules/SingleGameTypeInputValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ public function passes($attribute, $value)
$validGameTypes = GameType::pluck('short_name')->toArray();
$validGameTypes = array_diff($validGameTypes, ['br', 'cu']);

if(!in_array($value, $validGameTypes)){ // corrected from $this->validGameTypes
if(!in_array($value, $validGameTypes)){
return 5;
}

// Assume $filteredGameTypes is defined elsewhere or pass it as an argument
$typeId = GameType::whereIn('short_name', $filteredGameTypes)
->pluck('type_id')->first(); // corrected from ->type_id
->pluck('type_id')->first();

return $typeId;
}
Expand Down
Loading

0 comments on commit 940b41e

Please sign in to comment.