Skip to content

Commit

Permalink
Merge pull request #448 from Zemill/develop
Browse files Browse the repository at this point in the history
Heroes Profile v0.1.4
  • Loading branch information
Zemill authored Nov 17, 2023
2 parents a7d89f6 + f15d5ba commit e34a182
Show file tree
Hide file tree
Showing 19 changed files with 330 additions and 261 deletions.
87 changes: 44 additions & 43 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME=Laravel
APP_NAME=HeroesProfile
APP_ENV=local
APP_KEY=
APP_DEBUG=true
Expand All @@ -8,53 +8,54 @@ LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=


HEROESPROFILE_DB_CONNECTION=heroesprofile
HEROESPROFILE_DB_CACHE=heroesprofile_cache

HEROESPROFILE_DB_HOST_LOCAL=
HEROESPROFILE_DB_PORT=
HEROESPROFILE_DB_DATABASE=heroesprofile
HEROESPROFILE_DB_DATABASE_NGS=heroesprofile_ngs
HEROESPROFILE_DB_DATABASE_CCL=heroesprofile_ccl
HEROESPROFILE_DB_DATABASE_MCL=heroesprofile_mcl
HEROESPROFILE_DB_DATABASE_HI=heroesprofile_hi
HEROESPROFILE_DB_DATABASE_HI_NC=heroesprofile_hi_nc

HEROESPROFILE_DB_CACHE_DATABASE=heroesprofile_cache
HEROESPROFILE_DB_USERNAME=
HEROESPROFILE_DB_PASSWORD=
HEROESPROFILE_DB_CACHE_TABLE=laravel_cache


BATTLENET_KEY=
BATTLENET_SECRET=
BATTLENET_REDIRECT_URI=

PATREON_CLIENT_ID=
PATREON_CLIENT_SECRET=
PATREON_REDIRECT_URI=
PATREON_CAMPAIGN_ID=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
CACHE_DRIVER=database
CACHE_PREFIX=

FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync

SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1
SESSION_LIFETIME=250

VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
#ASSET_URL=http://localhost
ASSET_URL=/


MAIL_DRIVER=
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Laravel - https://laravel.com/

PHP - PHP can be installed in different ways. If you do not currently have PHP installed, use google to find the best method for you.

- Increase your local PHP memory_limit var. We use 1g. memory_limit = 1G

MySQL - MySQL can be installed in different ways. If you do not currently have MySQL installed, use google to find the best method for you.

Optional - A visual tool for looking at the database and data is suggested. MySql Workbench is our preference - https://www.mysql.com/products/workbench/
Expand All @@ -27,8 +25,8 @@ For windows users, Wampserver64 is a useful tool as it installs the MySql server

## Database setup (TBD)

- Create the following schemas in your MySql database. `heroesprofile`, `heroesprofile_cache`
- Increase your local mysql max_allowed_packet var. We use 64M.
- Create the following schemas in your MySql database. `heroesprofile`, `heroesprofile_cache`, `heroesprofile_hi`, `heroesprofile_hi_nc`, `heroesprofile_mcl`, `heroesprofile_ml`, `heroesprofile_ngs`, `heroesprofile_nutcup`
- Table structure and table data will be provided on an as-needed basis. If you are wanting to make a change and need to know this information, please log a ticket or contact us directly explaining what you are doing and what data you need.

## Project Setup

Expand All @@ -52,5 +50,3 @@ For windows users, Wampserver64 is a useful tool as it installs the MySql server
All contributions are welcome. The owners of Heroes Profile reserve the right to include or deny any merge requests from the community. Also, please try and only create pull requests that contain updates to the specific update you want to make. Including environment or auto-generated updates to framework code that are not required for your change only complicates making updates.

If a contribution requires changes to the database, or how the data is grabbed from replays, please log an issue report detailing your need.

- If backend code from the production site is needed, it can be found in the live_side_code folder of this repository. If there is code you need that is missing, please create a PR to have that added.
8 changes: 7 additions & 1 deletion app/Http/Controllers/CompareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ public function getData(Request $request)

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

$gamesPlayed = $winCount + $lossCount;

$winRate = $gamesPlayed > 0 ? ($winCount / $gamesPlayed) * 100: 0;

$averageValue = $result->avg($column);

$maxValue = $averageValue;
Expand All @@ -201,14 +206,15 @@ public function getData(Request $request)
'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'],
'wins' => $winCount,
'losses' => $lossCount,
'games_played' => $gamesPlayed,
'win_rate' => $winRate,
'averages' => $columnStatistics,
];
}
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/Esports/EsportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ public function getDataSinglePlayerMatchHistory(Request $request){
'blizz_id' => 'nullable|string',
'division' => 'nullable|string',
'season' => 'nullable|numeric',
'hero' => ['sometimes', 'nullable', new HeroInputValidation()],
'game_map' => ['sometimes', 'nullable', new GameMapInputValidation()],
'pagination_page' => 'required:integer',
'tournament' => 'nullable|in:main,nationscup',
];
Expand Down
68 changes: 42 additions & 26 deletions app/Http/Controllers/Player/PlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,47 @@ public function getPlayerData(Request $request)
->first();

if (! $cachedData) {
$cachedData = $this->calculateProfile($blizz_id, $region, $game_type, $season);
} else {
$latestReplayID = Replay::select('replay.replayID')
->join('player', 'player.replayID', '=', 'replay.replayID')
->where('blizz_id', $blizz_id)
->where('region', $region)
->when(! is_null($game_type), function ($query) use ($game_type) {
return $query->where('game_type', $game_type);
})
->when(! is_null($season), function ($query) use ($season) {
$seasonDate = SeasonDate::find($season);
if ($seasonDate) {
return $query->where('game_date', '>=', $seasonDate->start_date)
->where('game_date', '<', $seasonDate->end_date);
}

return $query;
})
->orderBy('replayID', 'DESC')
->limit(1)
->first()
->replayID ?? null;

if ($latestReplayID && $cachedData->latest_replayID < $latestReplayID) {
$cachedData = $this->calculateProfile($blizz_id, $region, $game_type, $season, $cachedData);
}
$this->calculateProfile($blizz_id, $region, $game_type, $season);

$cachedData = LaravelProfilePage::filterByBlizzID($blizz_id)
->filterByRegion($region)
->where('game_type', $game_type)
->where('season', $season)
->first();
}


$latestReplayID = Replay::select('replay.replayID')
->join('player', 'player.replayID', '=', 'replay.replayID')
->where('blizz_id', $blizz_id)
->where('region', $region)
->when(! is_null($game_type), function ($query) use ($game_type) {
return $query->where('game_type', $game_type);
})
->when(! is_null($season), function ($query) use ($season) {
$seasonDate = SeasonDate::find($season);
if ($seasonDate) {
return $query->where('game_date', '>=', $seasonDate->start_date)
->where('game_date', '<', $seasonDate->end_date);
}

return $query;
})
->orderBy('replayID', 'DESC')
->limit(1)
->first()
->replayID ?? null;

if ($latestReplayID && $cachedData->latest_replayID < $latestReplayID) {
$this->calculateProfile($blizz_id, $region, $game_type, $season, $cachedData);
$cachedData = LaravelProfilePage::filterByBlizzID($blizz_id)
->filterByRegion($region)
->where('game_type', $game_type)
->where('season', $season)
->first();
}


if ($cachedData) {
return $this->formatCache($cachedData, $blizz_id, $region, $battletag);
} else {
Expand Down Expand Up @@ -719,6 +733,8 @@ private function formatCache($data, $blizz_id, $region, $battletag)

if (is_string($data->matches)) {
$matches = json_decode($data->matches, true);
}else{
$matches = $data->matches;
}

$returnData->matchData = collect($matches)->sortByDesc('game_date')->map(function ($match) use ($maps, $heroData, $talentData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public function getData(Request $request)

if ($minimum_games && $minimum_games > 0) {
$filteredData = array_filter($returnData, function ($item) {
return $item['games_played'] > 200;
return $item['games_played'] > $minimum_games;
});

$returnData = array_values($filteredData);
Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/SetGlobalDataValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function handle(Request $request, Closure $next): Response
$globalDataService->getSeasonsData();
$globalDataService->getGameTypeIDtoString();
$globalDataService->getRegionStringToID();
$globalDataService->getHeaderAlert();
//$globalDataService->getGameTypes();

return $next($request);
Expand Down
16 changes: 16 additions & 0 deletions app/Models/HeaderAlert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class HeaderAlert extends Model
{
protected $table = 'header_alert';

protected $primaryKey = 'header_alert_id';

protected $connection = 'heroesprofile';

public $timestamps = false;
}
12 changes: 12 additions & 0 deletions app/Services/GlobalDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use App\Models\HeaderAlert;

class GlobalDataService
{
Expand All @@ -29,6 +30,17 @@ public function __construct()
$this->filtersMinimumPatch = '2.53.0.83004';
}

public function getHeaderAlert(){
if (! session()->has('headeralert')) {
$alert = HeaderAlert::select('text')->where("valid", 1)->first();

if(!empty($alert)){
session(['headeralert' => $alert->text]);
}
}
return session('headeralert');
}

public function getPrivateAccounts()
{
$privateAccounts = BattlenetAccount::select('battletag', 'blizz_id', 'region')->where('private', 1)->get();
Expand Down
12 changes: 12 additions & 0 deletions resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ body{
}
.nav-dropdown a{
text-wrap:nowrap;
display:flex;
white-space:nowrap;
}
.nav-item:not(:first-child)::before{
content: '|';
padding-right:20px;
height:100%;
font-size:1.5em;
}
.nav-item{
padding-top:10px;
padding-bottom:10px;
}


Expand Down
Loading

0 comments on commit e34a182

Please sign in to comment.