Skip to content

Commit

Permalink
Merge pull request #265 from Zemill/BackendMigrationWork
Browse files Browse the repository at this point in the history
Backend migration work
  • Loading branch information
Zemill authored Sep 17, 2023
2 parents 2a99516 + 19c7e8e commit cc408ed
Show file tree
Hide file tree
Showing 17 changed files with 615 additions and 53 deletions.
35 changes: 23 additions & 12 deletions app/Http/Controllers/Player/PlayerHeroesMapsRolesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function __construct(GlobalDataService $globalDataService)
$this->globalDataService = $globalDataService;
}
public function getData(Request $request){
//return response()->json($request->all());

//return response()->json($request->all());

$validator = \Validator::make($request->only(['blizz_id', 'region', 'minimumgames', 'type']), [
'blizz_id' => 'required|integer',
Expand All @@ -51,6 +52,7 @@ public function getData(Request $request){
$type = $request["type"];
$page = $request["page"];
$role = (new RoleInputValidation())->passes('role', $request["role"]);
$map = $request["map"];

if(count($gameType) == 6){
$gameType = [];
Expand Down Expand Up @@ -78,6 +80,9 @@ public function getData(Request $request){
->when($type == "single" && $page == "role", function ($query) use ($role) {
return $query->where("new_role", $role);
})
->when($type == "single" && $page == "map", function ($query) use ($map) {
return $query->where("game_map", $map);
})
->select([
'replay.replayID',
'hero',
Expand Down Expand Up @@ -160,17 +165,17 @@ public function getData(Request $request){
$seasonData = $this->globalDataService->getSeasonsData();
$newSeasonData = null;
$latestGames = null;
$winRateFiltered = null;

$mapWinRateFiltered= null;
$heroWinRateFiltered = null;

$mapData = null;
$heroDataStats = null;


if($type == "single"){
$mapData = $result->groupBy('game_map');
$heroDataStats = $result->groupBy('hero');


$filterByType = $hero;
if($page == "role"){
$filterByType = MMRTypeID::select("mmr_type_id")->filterByName($role)->first()->mmr_type_id;
Expand Down Expand Up @@ -209,7 +214,9 @@ public function getData(Request $request){


$latestGames = $result->sortByDesc('game_date')->take(5)->values();

$latestGames = $latestGames->map(function($game) use($heroData, $maps, $talentData, $gameTypes) {
$game = clone $game;
unset(
$game['hero_level'],
$game['stack_size'],
Expand Down Expand Up @@ -279,6 +286,7 @@ public function getData(Request $request){
return $game;
});


$newSeasonData = $result->map(function ($item) use ($seasonData) {
$gameDate = $item->game_date;
$season = null;
Expand Down Expand Up @@ -406,18 +414,19 @@ public function getData(Request $request){
}

}



$groupBy = "";
if($page == "hero"){
$groupBy = 'hero';
}else if($page == "map"){

$groupBy = 'game_map';
}else if($page == "role"){
$groupBy = 'new_role';
}

$returnData = $result->groupBy($groupBy)->map(function($heroStats) use ($heroData, $qm_mmr_data, $ud_mmr_data, $hl_mmr_data, $tl_mmr_data, $sl_mmr_data, $ar_mmr_data, $newSeasonData, $mapData, $mapWinRateFiltered, $latestGames, $page, $heroWinRateFiltered, $heroDataStats){

$returnData = $result->groupBy($groupBy)->map(function($heroStats, $index) use ($heroData, $qm_mmr_data, $ud_mmr_data, $hl_mmr_data, $tl_mmr_data, $sl_mmr_data, $ar_mmr_data, $newSeasonData, $mapData, $mapWinRateFiltered, $latestGames, $page, $heroWinRateFiltered, $heroDataStats, $maps){
$deaths = $heroStats->sum('deaths');
$avg_kills = $heroStats->avg('kills');
$avg_takedowns = $heroStats->avg('takedowns');
Expand Down Expand Up @@ -449,17 +458,19 @@ public function getData(Request $request){
$stack_size_five_losses = $heroStats->where('stack_size', 5)->where('winner', 0)->count();
$stack_size_five_total = $stack_size_five_wins + $stack_size_five_losses;


if($page == "hero"){
$name = $heroData[$heroStats->pluck('hero')->first()]["name"];
//$name = $heroData[$heroStats->pluck('hero')->first()]["name"];
}else if($page == "map"){

//$name = $maps[$heroStats->pluck('game_map')->first()]["name"];
}else if($page == "role"){
$name = $heroStats->pluck('new_role')->first();
}

return [
"name" => $name,
"hero" => $heroData[$heroStats->pluck('hero')->first()],
"name" => $index,
//"hero" => $heroData[$heroStats->pluck('hero')->first()],
//"game_map" => $maps[$heroStats->pluck('game_map')->first()],
'wins' => $wins,
'losses' => $losses,
'games_played' => $games_played,
Expand Down
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(),
]);
}
}
7 changes: 0 additions & 7 deletions app/Http/Controllers/Player/PlayerRolesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use App\Rules\GameTypeInputValidation;
use App\Rules\GameMapInputValidation;
use App\Rules\HeroInputByIDValidation;
use App\Rules\HeroInputValidation;
use App\Rules\RoleInputValidation;

use App\Models\Replay;
use App\Models\Map;
use App\Models\HeroesDataTalent;

class PlayerRolesController extends Controller
{
Expand Down
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
2 changes: 2 additions & 0 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import PlayerHeroSingleStats from './components/Player/Heroes/PlayerHeroSingleSt
import PlayerMatchup from './components/Player/PlayerMatchup.vue';
import PlayerRolesAllStats from './components/Player/Roles/PlayerRolesAllStats.vue';
import PlayerRoleSingleStats from './components/Player/Roles/PlayerRoleSingleStats.vue';
import PlayerMapsAllStats from './components/Player/Maps/PlayerMapsAllStats.vue';
import PlayerMapSingleStats from './components/Player/Maps/PlayerMapSingleStats.vue';


// Automatically register Vue components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default {
}
},
getTalentPageUrl(){
return "/Player/Talents/" + this.battletag + "/" + this.blizzid + "/" + this.region + "/" + this.heroname;
return "/Player/" + this.battletag + "/" + this.blizzid + "/" + this.region + "/Talents/" + "/" + this.heroname;
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export default {
return this.gametype.includes(game_type);
},
getPlayerHeroPageUrl(hero){
return "/Player/Hero/Single/" + this.battletag + "/" + this.blizzid + "/" + this.region + "/" + hero;
return "/Player/" + this.battletag + "/" + this.blizzid + "/" + this.region + "/Hero/" + hero;
},
isDisabled(stat) {
return this.selectedStatsCount >= 15 && !stat.selected;
Expand Down
Loading

0 comments on commit cc408ed

Please sign in to comment.