-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserController.php
100 lines (85 loc) · 2.93 KB
/
UserController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace App\Http\Controllers;
use App\Riot\LOL;
class UserController extends Controller
{
private $user;
private $totalGames = 3;
private $api;
/**
* UserController constructor.
* @throws \RiotAPI\Exceptions\SettingsException
*/
public function __construct()
{
$this->api = new LOL();
}
/**
* @param $user
* @throws \RiotAPI\Exceptions\RequestException
* @throws \RiotAPI\Exceptions\ServerException
* @throws \RiotAPI\Exceptions\ServerLimitException
*/
public function index($user){
$gamers = ['Signífer', 'AngelKurten'];
foreach ($gamers as $gamer){
$this->user = $this->api->getSummonerByName($gamer);
$games = $this->api->getRanked($this->user->accountId, $this->totalGames);
$result = $this->getDataGames($games);
$show[$this->user->accountId]['name'] = $this->user->name;
$show[$this->user->accountId] += $this->generateAverage($result);
}
dd($show);
}
/**
* @param $games
* @return array
*/
private function getDataGames($games): array
{
$result = [
'duration' => 0,
'totalCs' => 0,
'csPerMinTotal' => 0,
'deltas' => [],
'gold' => 0,
'wardsPlaced' => 0,
];
foreach ($games as $game) {
$pid = $this->api->getParticipantId($game->participantIdentities, $this->user);
$data = $this->api->getDataUserGame($game, $pid);
$result['duration'] += $game->gameDuration / 60;
$result['totalCs'] += $data->stats->totalMinionsKilled + $data->stats->neutralMinionsKilledTeamJungle;
$result['csPerMinTotal'] += number_format($result['totalCs'] / $result['duration'], 2);
$result['deltas'] += $data->timeline->creepsPerMinDeltas;
foreach ($data->timeline->creepsPerMinDeltas as $key => $delta) {
if (array_key_exists($key, $result['deltas'])) {
$result['deltas'][$key] += $data->timeline->creepsPerMinDeltas[$key];
} else {
$result['deltas'][$key] = $data->timeline->creepsPerMinDeltas[$key];
}
}
$result['gold'] += $data->stats->goldEarned;
$result['wardsPlaced'] += $data->stats->wardsPlaced;
}
return $result;
}
/**
* @param $result
* @return array
*/
private function generateAverage($result): array
{
$parse = [];
foreach ($result as $key => $value) {
if ($key == 'deltas') {
foreach ($value as $time => $delta) {
$parse['deltas'][$time] = number_format($delta / $this->totalGames, 2);
}
} else {
$parse[$key] = number_format($value / $this->totalGames, 2);
}
}
return $parse;
}
}