-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from Zemill/develop
Heroes Profile v0.0.2
- Loading branch information
Showing
47 changed files
with
2,507 additions
and
793 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
650 changes: 650 additions & 0 deletions
650
app/Http/Controllers/Player/PlayerHeroesMapsRolesController.php
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
135
app/Http/Controllers/Player/PlayerMatchupsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.