@@ -9,48 +9,48 @@ |
||
9 | 9 | */ |
10 | 10 | class Responder |
11 | 11 | { |
12 | - /** |
|
13 | - * @param $content |
|
14 | - * @param $response |
|
15 | - * @param array $headers |
|
16 | - * @return mixed |
|
17 | - */ |
|
18 | - public static function getJsonResponse($content, $response, $headers = []) |
|
19 | - { |
|
20 | - $headers['Content-Type'] = 'application/json'; |
|
21 | - return self::getResponse( |
|
22 | - $headers, |
|
23 | - $content, |
|
24 | - $response |
|
25 | - ); |
|
26 | - } |
|
12 | + /** |
|
13 | + * @param $content |
|
14 | + * @param $response |
|
15 | + * @param array $headers |
|
16 | + * @return mixed |
|
17 | + */ |
|
18 | + public static function getJsonResponse($content, $response, $headers = []) |
|
19 | + { |
|
20 | + $headers['Content-Type'] = 'application/json'; |
|
21 | + return self::getResponse( |
|
22 | + $headers, |
|
23 | + $content, |
|
24 | + $response |
|
25 | + ); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param array $headers |
|
30 | - * @param $content |
|
31 | - * @param $response |
|
32 | - * @return mixed |
|
33 | - */ |
|
34 | - public static function getResponse($headers = [], $content, $response) |
|
35 | - { |
|
36 | - $body = $response->getBody(); |
|
37 | - $body->write($content); |
|
38 | - $i = 0; |
|
39 | - foreach ($headers as $header => $value) { |
|
40 | - if ($i === 0) { |
|
41 | - $response = $response->withHeader( |
|
42 | - $header, |
|
43 | - $value |
|
44 | - ); |
|
45 | - } else { |
|
46 | - $response = $response->withAddedHeader( |
|
47 | - $header, |
|
48 | - $value |
|
49 | - ); |
|
50 | - } |
|
51 | - $i++; |
|
52 | - } |
|
53 | - return $response->withBody($body); |
|
54 | - } |
|
28 | + /** |
|
29 | + * @param array $headers |
|
30 | + * @param $content |
|
31 | + * @param $response |
|
32 | + * @return mixed |
|
33 | + */ |
|
34 | + public static function getResponse($headers = [], $content, $response) |
|
35 | + { |
|
36 | + $body = $response->getBody(); |
|
37 | + $body->write($content); |
|
38 | + $i = 0; |
|
39 | + foreach ($headers as $header => $value) { |
|
40 | + if ($i === 0) { |
|
41 | + $response = $response->withHeader( |
|
42 | + $header, |
|
43 | + $value |
|
44 | + ); |
|
45 | + } else { |
|
46 | + $response = $response->withAddedHeader( |
|
47 | + $header, |
|
48 | + $value |
|
49 | + ); |
|
50 | + } |
|
51 | + $i++; |
|
52 | + } |
|
53 | + return $response->withBody($body); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -8,122 +8,122 @@ |
||
8 | 8 | { |
9 | 9 | |
10 | 10 | |
11 | - /** |
|
12 | - * @group OrmModels |
|
13 | - * @group PlayerOrm |
|
14 | - */ |
|
15 | - public function testPlayerOrmGetSet() |
|
16 | - { |
|
17 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
18 | - $playerM = $rndFiller->getPlayer(); |
|
19 | - $arrayPl = $playerM->toArray(); |
|
20 | - $playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl); |
|
21 | - $this->assertNotEmpty($playerO); |
|
11 | + /** |
|
12 | + * @group OrmModels |
|
13 | + * @group PlayerOrm |
|
14 | + */ |
|
15 | + public function testPlayerOrmGetSet() |
|
16 | + { |
|
17 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
18 | + $playerM = $rndFiller->getPlayer(); |
|
19 | + $arrayPl = $playerM->toArray(); |
|
20 | + $playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl); |
|
21 | + $this->assertNotEmpty($playerO); |
|
22 | 22 | |
23 | - $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray()); |
|
24 | - $this->assertNotEmpty($newPlayer); |
|
25 | - } |
|
23 | + $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray()); |
|
24 | + $this->assertNotEmpty($newPlayer); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @group OrmModels |
|
29 | - * @group CoachOrm |
|
30 | - */ |
|
31 | - public function testCoachOrmGetSet() |
|
32 | - { |
|
33 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
34 | - $coach = $rndFiller->getCoach(); |
|
35 | - $arrayPl = $coach->toArray(); |
|
36 | - $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl); |
|
37 | - $this->assertNotEmpty($coachO); |
|
27 | + /** |
|
28 | + * @group OrmModels |
|
29 | + * @group CoachOrm |
|
30 | + */ |
|
31 | + public function testCoachOrmGetSet() |
|
32 | + { |
|
33 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
34 | + $coach = $rndFiller->getCoach(); |
|
35 | + $arrayPl = $coach->toArray(); |
|
36 | + $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl); |
|
37 | + $this->assertNotEmpty($coachO); |
|
38 | 38 | |
39 | - $newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray()); |
|
40 | - $this->assertNotEmpty($newCoach); |
|
41 | - } |
|
39 | + $newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray()); |
|
40 | + $this->assertNotEmpty($newCoach); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @group OrmModels |
|
45 | - * @group TeamOrm |
|
46 | - */ |
|
47 | - public function testTeamOrm() |
|
48 | - { |
|
49 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
50 | - $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
51 | - $teamArray = $team->toArray(); |
|
52 | - $this->assertNotEmpty($team); |
|
53 | - $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
54 | - $this->assertNotEmpty($teamArray); |
|
55 | - $this->assertNotEmpty($teamArray['roster']); |
|
56 | - foreach ($teamArray['roster'] as $player) { |
|
57 | - $player['team_id'] = $teamO->id; |
|
58 | - $playerO = \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
59 | - $this->assertNotEmpty($playerO); |
|
60 | - } |
|
61 | - $teamArray['coach']['team_id'] = $teamO->id; |
|
62 | - $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
63 | - $this->assertNotEmpty($coachO); |
|
43 | + /** |
|
44 | + * @group OrmModels |
|
45 | + * @group TeamOrm |
|
46 | + */ |
|
47 | + public function testTeamOrm() |
|
48 | + { |
|
49 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
50 | + $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
51 | + $teamArray = $team->toArray(); |
|
52 | + $this->assertNotEmpty($team); |
|
53 | + $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
54 | + $this->assertNotEmpty($teamArray); |
|
55 | + $this->assertNotEmpty($teamArray['roster']); |
|
56 | + foreach ($teamArray['roster'] as $player) { |
|
57 | + $player['team_id'] = $teamO->id; |
|
58 | + $playerO = \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
59 | + $this->assertNotEmpty($playerO); |
|
60 | + } |
|
61 | + $teamArray['coach']['team_id'] = $teamO->id; |
|
62 | + $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
63 | + $this->assertNotEmpty($coachO); |
|
64 | 64 | |
65 | - $this->assertNotEmpty( |
|
66 | - \App\Lib\DsManager\Models\Orm\Team::with( |
|
67 | - 'roster' |
|
68 | - )->with( |
|
69 | - 'coach' |
|
70 | - )->where( |
|
71 | - [ |
|
72 | - 'id' => $teamO->id |
|
73 | - ] |
|
74 | - )->get()->toArray() |
|
75 | - ); |
|
76 | - } |
|
65 | + $this->assertNotEmpty( |
|
66 | + \App\Lib\DsManager\Models\Orm\Team::with( |
|
67 | + 'roster' |
|
68 | + )->with( |
|
69 | + 'coach' |
|
70 | + )->where( |
|
71 | + [ |
|
72 | + 'id' => $teamO->id |
|
73 | + ] |
|
74 | + )->get()->toArray() |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @group Match |
|
80 | - * @group createnewmatch |
|
81 | - */ |
|
82 | - public function testCreateNewMatch() |
|
83 | - { |
|
84 | - $teams = \App\Lib\DsManager\Models\Orm\Team::with( |
|
85 | - 'roster', |
|
86 | - 'coach' |
|
87 | - )->get(); |
|
88 | - $this->assertNotNull($teams); |
|
89 | - $teams = $teams->toArray(); |
|
90 | - $homeIndex = array_rand($teams); |
|
91 | - $teamHome = $teams[$homeIndex]; |
|
92 | - unset($teams[$homeIndex]); |
|
93 | - $teamAway = $teams[array_rand($teams)]; |
|
94 | - $this->assertNotNull($teamHome); |
|
95 | - $this->assertNotNull($teamAway); |
|
96 | - $matchO = \App\Lib\DsManager\Models\Orm\Match::create( |
|
97 | - [ |
|
98 | - 'home_team_id' => $teamHome['id'], |
|
99 | - 'away_team_id' => $teamAway['id'] |
|
100 | - ] |
|
101 | - ); |
|
102 | - $this->assertNotNull($matchO); |
|
103 | - $matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first(); |
|
104 | - $this->assertNotNull($matchNew); |
|
105 | - $match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray()); |
|
106 | - $this->assertNotNull($match); |
|
107 | - } |
|
78 | + /** |
|
79 | + * @group Match |
|
80 | + * @group createnewmatch |
|
81 | + */ |
|
82 | + public function testCreateNewMatch() |
|
83 | + { |
|
84 | + $teams = \App\Lib\DsManager\Models\Orm\Team::with( |
|
85 | + 'roster', |
|
86 | + 'coach' |
|
87 | + )->get(); |
|
88 | + $this->assertNotNull($teams); |
|
89 | + $teams = $teams->toArray(); |
|
90 | + $homeIndex = array_rand($teams); |
|
91 | + $teamHome = $teams[$homeIndex]; |
|
92 | + unset($teams[$homeIndex]); |
|
93 | + $teamAway = $teams[array_rand($teams)]; |
|
94 | + $this->assertNotNull($teamHome); |
|
95 | + $this->assertNotNull($teamAway); |
|
96 | + $matchO = \App\Lib\DsManager\Models\Orm\Match::create( |
|
97 | + [ |
|
98 | + 'home_team_id' => $teamHome['id'], |
|
99 | + 'away_team_id' => $teamAway['id'] |
|
100 | + ] |
|
101 | + ); |
|
102 | + $this->assertNotNull($matchO); |
|
103 | + $matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first(); |
|
104 | + $this->assertNotNull($matchNew); |
|
105 | + $match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray()); |
|
106 | + $this->assertNotNull($match); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @group Stats |
|
111 | - */ |
|
112 | - public function testGetStats() |
|
113 | - { |
|
114 | - $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
115 | - [ |
|
116 | - 'simulated' => false |
|
117 | - ] |
|
118 | - )->whereNotNull( |
|
119 | - 'league_round_id' |
|
120 | - )->get()->random(1); |
|
121 | - $this->assertNotEmpty($match); |
|
122 | - $result = \App\Lib\DsManager\Helpers\MatchSimulator::simulateRound($match->league_round_id); |
|
123 | - $this->assertNotEmpty($result); |
|
124 | - $players = \App\Lib\DsManager\Models\Orm\Player::getBest(); |
|
125 | - $this->assertNotEmpty($players); |
|
126 | - $teams = \App\Lib\DsManager\Models\Orm\Team::getBest(); |
|
127 | - $this->assertNotEmpty($teams); |
|
128 | - } |
|
109 | + /** |
|
110 | + * @group Stats |
|
111 | + */ |
|
112 | + public function testGetStats() |
|
113 | + { |
|
114 | + $match = \App\Lib\DsManager\Models\Orm\Match::where( |
|
115 | + [ |
|
116 | + 'simulated' => false |
|
117 | + ] |
|
118 | + )->whereNotNull( |
|
119 | + 'league_round_id' |
|
120 | + )->get()->random(1); |
|
121 | + $this->assertNotEmpty($match); |
|
122 | + $result = \App\Lib\DsManager\Helpers\MatchSimulator::simulateRound($match->league_round_id); |
|
123 | + $this->assertNotEmpty($result); |
|
124 | + $players = \App\Lib\DsManager\Models\Orm\Player::getBest(); |
|
125 | + $this->assertNotEmpty($players); |
|
126 | + $teams = \App\Lib\DsManager\Models\Orm\Team::getBest(); |
|
127 | + $this->assertNotEmpty($teams); |
|
128 | + } |
|
129 | 129 | } |
@@ -8,109 +8,109 @@ |
||
8 | 8 | */ |
9 | 9 | class Player extends DsManagerOrm |
10 | 10 | { |
11 | - /** |
|
12 | - * |
|
13 | - */ |
|
14 | - const PLAYER_STATS_LIMIT = 5; |
|
11 | + /** |
|
12 | + * |
|
13 | + */ |
|
14 | + const PLAYER_STATS_LIMIT = 5; |
|
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $table = 'players'; |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $table = 'players'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $fillable = [ |
|
26 | - 'name', |
|
27 | - 'surname', |
|
28 | - 'age', |
|
29 | - 'nationality', |
|
30 | - 'skillAvg', |
|
31 | - 'wageReq', |
|
32 | - 'val', |
|
33 | - 'role', |
|
34 | - 'team_id' |
|
35 | - ]; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $fillable = [ |
|
26 | + 'name', |
|
27 | + 'surname', |
|
28 | + 'age', |
|
29 | + 'nationality', |
|
30 | + 'skillAvg', |
|
31 | + 'wageReq', |
|
32 | + 'val', |
|
33 | + 'role', |
|
34 | + 'team_id' |
|
35 | + ]; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
39 | - */ |
|
40 | - public function team() |
|
41 | - { |
|
42 | - return $this->belongsTo(Team::class); |
|
43 | - } |
|
37 | + /** |
|
38 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
39 | + */ |
|
40 | + public function team() |
|
41 | + { |
|
42 | + return $this->belongsTo(Team::class); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return mixed |
|
47 | - */ |
|
48 | - public function lastMatches() |
|
49 | - { |
|
50 | - return $this->hasMany(MatchPlayer::class) |
|
51 | - ->orderBy('updated_at', 'DESC') |
|
52 | - ->limit(5); |
|
53 | - } |
|
45 | + /** |
|
46 | + * @return mixed |
|
47 | + */ |
|
48 | + public function lastMatches() |
|
49 | + { |
|
50 | + return $this->hasMany(MatchPlayer::class) |
|
51 | + ->orderBy('updated_at', 'DESC') |
|
52 | + ->limit(5); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return mixed |
|
57 | - */ |
|
58 | - public function goals() |
|
59 | - { |
|
60 | - return $this->hasOne(MatchPlayer::class) |
|
61 | - ->selectRaw('player_id, sum(goals) as count') |
|
62 | - ->groupBy('player_id'); |
|
63 | - } |
|
55 | + /** |
|
56 | + * @return mixed |
|
57 | + */ |
|
58 | + public function goals() |
|
59 | + { |
|
60 | + return $this->hasOne(MatchPlayer::class) |
|
61 | + ->selectRaw('player_id, sum(goals) as count') |
|
62 | + ->groupBy('player_id'); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return mixed |
|
67 | - */ |
|
68 | - public function appearances() |
|
69 | - { |
|
70 | - return $this->hasOne(MatchPlayer::class) |
|
71 | - ->selectRaw('player_id, count(match_id) as count') |
|
72 | - ->groupBy('player_id'); |
|
73 | - } |
|
65 | + /** |
|
66 | + * @return mixed |
|
67 | + */ |
|
68 | + public function appearances() |
|
69 | + { |
|
70 | + return $this->hasOne(MatchPlayer::class) |
|
71 | + ->selectRaw('player_id, count(match_id) as count') |
|
72 | + ->groupBy('player_id'); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return mixed |
|
77 | - */ |
|
78 | - public function avg() |
|
79 | - { |
|
80 | - return $this->hasOne(MatchPlayer::class) |
|
81 | - ->selectRaw('player_id, round(avg(vote),2) as avg') |
|
82 | - ->groupBy('player_id'); |
|
83 | - } |
|
75 | + /** |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | + public function avg() |
|
79 | + { |
|
80 | + return $this->hasOne(MatchPlayer::class) |
|
81 | + ->selectRaw('player_id, round(avg(vote),2) as avg') |
|
82 | + ->groupBy('player_id'); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param $query |
|
87 | - * @return mixed |
|
88 | - */ |
|
89 | - public function scopeStatistics($query) |
|
90 | - { |
|
91 | - return $query->with( |
|
92 | - 'goals', |
|
93 | - 'appearances', |
|
94 | - 'avg', |
|
95 | - 'lastMatches', |
|
96 | - 'team' |
|
97 | - ); |
|
98 | - } |
|
85 | + /** |
|
86 | + * @param $query |
|
87 | + * @return mixed |
|
88 | + */ |
|
89 | + public function scopeStatistics($query) |
|
90 | + { |
|
91 | + return $query->with( |
|
92 | + 'goals', |
|
93 | + 'appearances', |
|
94 | + 'avg', |
|
95 | + 'lastMatches', |
|
96 | + 'team' |
|
97 | + ); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public static function getBest() |
|
104 | - { |
|
105 | - $result = MatchPlayer::selectRaw( |
|
106 | - 'player_id, COUNT(*) as appearances , AVG(vote) avg, SUM(goals) goals' |
|
107 | - )->where('goals', '>', 0) |
|
108 | - ->orderByRaw('SUM(goals) DESC,COUNT(*) DESC') |
|
109 | - ->groupBy('player_id')->take(self::PLAYER_STATS_LIMIT)->get()->keyBy('player_id')->toArray(); |
|
110 | - $players = Player::with('team')->whereIn('id', array_keys($result))->get()->toArray(); |
|
111 | - $result = array_map(function ($player) use ($result) { |
|
112 | - return array_merge($player,$result[$player['id']]); |
|
113 | - }, $players); |
|
114 | - return $result; |
|
115 | - } |
|
100 | + /** |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public static function getBest() |
|
104 | + { |
|
105 | + $result = MatchPlayer::selectRaw( |
|
106 | + 'player_id, COUNT(*) as appearances , AVG(vote) avg, SUM(goals) goals' |
|
107 | + )->where('goals', '>', 0) |
|
108 | + ->orderByRaw('SUM(goals) DESC,COUNT(*) DESC') |
|
109 | + ->groupBy('player_id')->take(self::PLAYER_STATS_LIMIT)->get()->keyBy('player_id')->toArray(); |
|
110 | + $players = Player::with('team')->whereIn('id', array_keys($result))->get()->toArray(); |
|
111 | + $result = array_map(function ($player) use ($result) { |
|
112 | + return array_merge($player,$result[$player['id']]); |
|
113 | + }, $players); |
|
114 | + return $result; |
|
115 | + } |
|
116 | 116 | } |
117 | 117 | \ No newline at end of file |
@@ -108,8 +108,8 @@ |
||
108 | 108 | ->orderByRaw('SUM(goals) DESC,COUNT(*) DESC') |
109 | 109 | ->groupBy('player_id')->take(self::PLAYER_STATS_LIMIT)->get()->keyBy('player_id')->toArray(); |
110 | 110 | $players = Player::with('team')->whereIn('id', array_keys($result))->get()->toArray(); |
111 | - $result = array_map(function ($player) use ($result) { |
|
112 | - return array_merge($player,$result[$player['id']]); |
|
111 | + $result = array_map(function($player) use ($result) { |
|
112 | + return array_merge($player, $result[$player['id']]); |
|
113 | 113 | }, $players); |
114 | 114 | return $result; |
115 | 115 | } |