@@ -3,38 +3,38 @@ |
||
| 3 | 3 | |
| 4 | 4 | interface PlayerStatistics { |
| 5 | 5 | |
| 6 | - public function matchesHandicap($playerId); |
|
| 7 | - public function scoringAverage($playerId); |
|
| 8 | - public function scoringAverageByYear($playerId, $year); |
|
| 9 | - public function scoringAverageMatchesByYear($year); |
|
| 10 | - public function handicapRounds($playerId); |
|
| 11 | - |
|
| 12 | - public function scoringAverageCourse($course); |
|
| 13 | - public function scoringAverageCourseByYear($course, $year); |
|
| 14 | - public function scoringAverageCourseMatchesByYear($course, $year); |
|
| 15 | - |
|
| 16 | - public function totalEagles(); |
|
| 17 | - public function eaglesByYear($year); |
|
| 18 | - public function eaglesMatchesByYear($year); |
|
| 19 | - |
|
| 20 | - public function totalBirdies($playerId); |
|
| 21 | - public function birdiesByYear($playerId, $year); |
|
| 22 | - public function birdiesMatchesByYear($year); |
|
| 23 | - |
|
| 24 | - public function totalPars(); |
|
| 25 | - public function parsByYear($year); |
|
| 26 | - public function parsMatchesByYear($year); |
|
| 27 | - |
|
| 28 | - public function totalbogeys(); |
|
| 29 | - public function bogeysByYear($year); |
|
| 30 | - public function bogeysMatchesByYear($year); |
|
| 31 | - |
|
| 32 | - public function totalDoubles(); |
|
| 33 | - public function doublesByYear($year); |
|
| 34 | - public function doublesMatchesByYear($year); |
|
| 35 | - |
|
| 36 | - public function totalOthers(); |
|
| 37 | - public function othersByYear($year); |
|
| 38 | - public function othersMatchesByYear($year); |
|
| 6 | + public function matchesHandicap($playerId); |
|
| 7 | + public function scoringAverage($playerId); |
|
| 8 | + public function scoringAverageByYear($playerId, $year); |
|
| 9 | + public function scoringAverageMatchesByYear($year); |
|
| 10 | + public function handicapRounds($playerId); |
|
| 11 | + |
|
| 12 | + public function scoringAverageCourse($course); |
|
| 13 | + public function scoringAverageCourseByYear($course, $year); |
|
| 14 | + public function scoringAverageCourseMatchesByYear($course, $year); |
|
| 15 | + |
|
| 16 | + public function totalEagles(); |
|
| 17 | + public function eaglesByYear($year); |
|
| 18 | + public function eaglesMatchesByYear($year); |
|
| 19 | + |
|
| 20 | + public function totalBirdies($playerId); |
|
| 21 | + public function birdiesByYear($playerId, $year); |
|
| 22 | + public function birdiesMatchesByYear($year); |
|
| 23 | + |
|
| 24 | + public function totalPars(); |
|
| 25 | + public function parsByYear($year); |
|
| 26 | + public function parsMatchesByYear($year); |
|
| 27 | + |
|
| 28 | + public function totalbogeys(); |
|
| 29 | + public function bogeysByYear($year); |
|
| 30 | + public function bogeysMatchesByYear($year); |
|
| 31 | + |
|
| 32 | + public function totalDoubles(); |
|
| 33 | + public function doublesByYear($year); |
|
| 34 | + public function doublesMatchesByYear($year); |
|
| 35 | + |
|
| 36 | + public function totalOthers(); |
|
| 37 | + public function othersByYear($year); |
|
| 38 | + public function othersMatchesByYear($year); |
|
| 39 | 39 | |
| 40 | 40 | } |
| 41 | 41 | \ No newline at end of file |
@@ -9,86 +9,86 @@ |
||
| 9 | 9 | |
| 10 | 10 | class PlayerStatisticsEloquent implements PlayerStatistics |
| 11 | 11 | { |
| 12 | - private $date1 = '-01-01'; |
|
| 13 | - private $date2 = '-12-31'; |
|
| 14 | - |
|
| 15 | - public function matchesHandicap($playerId){} |
|
| 16 | - public function scoringAverage($playerId) |
|
| 17 | - { |
|
| 18 | - $rounds = Round::where('match_id', '>', '0') |
|
| 19 | - ->where('player_id', '=', $playerId) |
|
| 20 | - ->get(); |
|
| 21 | - |
|
| 22 | - $scores = $rounds->map(function($round) |
|
| 23 | - { |
|
| 24 | - return $round->score; |
|
| 25 | - }); |
|
| 26 | - return round(array_sum($scores->toArray())/($rounds->count()), 2); |
|
| 27 | - } |
|
| 28 | - public function scoringAverageByYear($playerId, $year) |
|
| 29 | - { |
|
| 30 | - $rounds = Round::where('match_id', '>', '0') |
|
| 31 | - ->where('player_id', '=', $playerId) |
|
| 32 | - ->where('date', '>=', $year . $this->date1) |
|
| 33 | - ->where('date', '<=', $year . $this->date2) |
|
| 34 | - ->get(); |
|
| 35 | - $scores = $rounds->map(function($round) |
|
| 36 | - { |
|
| 37 | - return $round->score; |
|
| 38 | - }); |
|
| 39 | - if($rounds->count() > 0) { |
|
| 40 | - return round(array_sum($scores->toArray())/($rounds->count()), 2); |
|
| 41 | - } else { |
|
| 42 | - return $rounds; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - } |
|
| 47 | - public function scoringAverageMatchesByYear($year){} |
|
| 48 | - public function handicapRounds($playerId){} |
|
| 49 | - |
|
| 50 | - public function scoringAverageCourse($course){} |
|
| 51 | - public function scoringAverageCourseByYear($course, $year){} |
|
| 52 | - public function scoringAverageCourseMatchesByYear($course, $year){} |
|
| 53 | - |
|
| 54 | - public function totalEagles(){} |
|
| 55 | - public function eaglesByYear($year){} |
|
| 56 | - public function eaglesMatchesByYear($year){} |
|
| 57 | - |
|
| 58 | - public function totalBirdies($playerId){} |
|
| 59 | - public function birdiesByYear($playerId, $year) |
|
| 60 | - { |
|
| 61 | - $year = $year . '-01-01'; |
|
| 62 | - $holescores = Holescore::with('round.player','hole') |
|
| 63 | - ->where('created_at', '>', $year) |
|
| 64 | - ->get(); |
|
| 65 | - $allBirdies = array(); |
|
| 66 | - foreach($holescores as $key => $holescore) { |
|
| 67 | - if($holescore['round']['match_id'] != null){ |
|
| 68 | - if( ($holescore['hole']['par'] - $holescore['score']) === 1) { |
|
| 69 | - $allBirdies[]= $holescore['round']['player']['id']; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - return count(array_keys($allBirdies, $playerId)); |
|
| 74 | - |
|
| 75 | - } |
|
| 76 | - public function birdiesMatchesByYear($year){} |
|
| 77 | - |
|
| 78 | - public function totalPars(){} |
|
| 79 | - public function parsByYear($year){} |
|
| 80 | - public function parsMatchesByYear($year){} |
|
| 81 | - |
|
| 82 | - public function totalbogeys(){} |
|
| 83 | - public function bogeysByYear($year){} |
|
| 84 | - public function bogeysMatchesByYear($year){} |
|
| 85 | - |
|
| 86 | - public function totalDoubles(){} |
|
| 87 | - public function doublesByYear($year){} |
|
| 88 | - public function doublesMatchesByYear($year){} |
|
| 89 | - |
|
| 90 | - public function totalOthers(){} |
|
| 91 | - public function othersByYear($year){} |
|
| 92 | - public function othersMatchesByYear($year){} |
|
| 12 | + private $date1 = '-01-01'; |
|
| 13 | + private $date2 = '-12-31'; |
|
| 14 | + |
|
| 15 | + public function matchesHandicap($playerId){} |
|
| 16 | + public function scoringAverage($playerId) |
|
| 17 | + { |
|
| 18 | + $rounds = Round::where('match_id', '>', '0') |
|
| 19 | + ->where('player_id', '=', $playerId) |
|
| 20 | + ->get(); |
|
| 21 | + |
|
| 22 | + $scores = $rounds->map(function($round) |
|
| 23 | + { |
|
| 24 | + return $round->score; |
|
| 25 | + }); |
|
| 26 | + return round(array_sum($scores->toArray())/($rounds->count()), 2); |
|
| 27 | + } |
|
| 28 | + public function scoringAverageByYear($playerId, $year) |
|
| 29 | + { |
|
| 30 | + $rounds = Round::where('match_id', '>', '0') |
|
| 31 | + ->where('player_id', '=', $playerId) |
|
| 32 | + ->where('date', '>=', $year . $this->date1) |
|
| 33 | + ->where('date', '<=', $year . $this->date2) |
|
| 34 | + ->get(); |
|
| 35 | + $scores = $rounds->map(function($round) |
|
| 36 | + { |
|
| 37 | + return $round->score; |
|
| 38 | + }); |
|
| 39 | + if($rounds->count() > 0) { |
|
| 40 | + return round(array_sum($scores->toArray())/($rounds->count()), 2); |
|
| 41 | + } else { |
|
| 42 | + return $rounds; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + public function scoringAverageMatchesByYear($year){} |
|
| 48 | + public function handicapRounds($playerId){} |
|
| 49 | + |
|
| 50 | + public function scoringAverageCourse($course){} |
|
| 51 | + public function scoringAverageCourseByYear($course, $year){} |
|
| 52 | + public function scoringAverageCourseMatchesByYear($course, $year){} |
|
| 53 | + |
|
| 54 | + public function totalEagles(){} |
|
| 55 | + public function eaglesByYear($year){} |
|
| 56 | + public function eaglesMatchesByYear($year){} |
|
| 57 | + |
|
| 58 | + public function totalBirdies($playerId){} |
|
| 59 | + public function birdiesByYear($playerId, $year) |
|
| 60 | + { |
|
| 61 | + $year = $year . '-01-01'; |
|
| 62 | + $holescores = Holescore::with('round.player','hole') |
|
| 63 | + ->where('created_at', '>', $year) |
|
| 64 | + ->get(); |
|
| 65 | + $allBirdies = array(); |
|
| 66 | + foreach($holescores as $key => $holescore) { |
|
| 67 | + if($holescore['round']['match_id'] != null){ |
|
| 68 | + if( ($holescore['hole']['par'] - $holescore['score']) === 1) { |
|
| 69 | + $allBirdies[]= $holescore['round']['player']['id']; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + return count(array_keys($allBirdies, $playerId)); |
|
| 74 | + |
|
| 75 | + } |
|
| 76 | + public function birdiesMatchesByYear($year){} |
|
| 77 | + |
|
| 78 | + public function totalPars(){} |
|
| 79 | + public function parsByYear($year){} |
|
| 80 | + public function parsMatchesByYear($year){} |
|
| 81 | + |
|
| 82 | + public function totalbogeys(){} |
|
| 83 | + public function bogeysByYear($year){} |
|
| 84 | + public function bogeysMatchesByYear($year){} |
|
| 85 | + |
|
| 86 | + public function totalDoubles(){} |
|
| 87 | + public function doublesByYear($year){} |
|
| 88 | + public function doublesMatchesByYear($year){} |
|
| 89 | + |
|
| 90 | + public function totalOthers(){} |
|
| 91 | + public function othersByYear($year){} |
|
| 92 | + public function othersMatchesByYear($year){} |
|
| 93 | 93 | |
| 94 | 94 | } |
| 95 | 95 | \ No newline at end of file |
@@ -8,55 +8,55 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class LeagueStatisticsEloquent implements LeagueStatistics |
| 10 | 10 | { |
| 11 | - public function topFiveLowestScores() |
|
| 12 | - { |
|
| 13 | - return Round::with('player','course')->orderBy('score')->take(5)->get(); |
|
| 14 | - } |
|
| 15 | - public function topFiveLowestScoresByYear($year) |
|
| 16 | - { |
|
| 17 | - $date1 = $year . '-01-01'; |
|
| 18 | - $date2 = $year . '-12-31'; |
|
| 19 | - return Round::with('player', 'course') |
|
| 20 | - ->where('match_id', '>', '0') |
|
| 21 | - ->where('date', '>=', $date1) |
|
| 22 | - ->where('date', '<=', $date2) |
|
| 23 | - ->orderBy('score') |
|
| 24 | - ->take(5) |
|
| 25 | - ->get(); |
|
| 26 | - } |
|
| 27 | - public function topFiveScoringAverageByYear($year) |
|
| 28 | - { |
|
| 29 | - //Get players |
|
| 30 | - //For each player where match > 0 select scores and average them |
|
| 31 | - //Store in players array |
|
| 32 | - $date1 = $year . '-01-01'; |
|
| 33 | - $date2 = $year . '-12-31'; |
|
| 34 | - $players = Player::all(); |
|
| 35 | - $average = array(); |
|
| 36 | - $i = 0; |
|
| 37 | - foreach($players as $key => $player) { |
|
| 38 | - $rounds = Round::where('match_id', '>', '0') |
|
| 39 | - ->where('player_id', '=', $player->id) |
|
| 40 | - ->where('date', '>=', $date1) |
|
| 41 | - ->where('date', '<=', $date2) |
|
| 42 | - ->get(); |
|
| 43 | - $scores = array(); |
|
| 11 | + public function topFiveLowestScores() |
|
| 12 | + { |
|
| 13 | + return Round::with('player','course')->orderBy('score')->take(5)->get(); |
|
| 14 | + } |
|
| 15 | + public function topFiveLowestScoresByYear($year) |
|
| 16 | + { |
|
| 17 | + $date1 = $year . '-01-01'; |
|
| 18 | + $date2 = $year . '-12-31'; |
|
| 19 | + return Round::with('player', 'course') |
|
| 20 | + ->where('match_id', '>', '0') |
|
| 21 | + ->where('date', '>=', $date1) |
|
| 22 | + ->where('date', '<=', $date2) |
|
| 23 | + ->orderBy('score') |
|
| 24 | + ->take(5) |
|
| 25 | + ->get(); |
|
| 26 | + } |
|
| 27 | + public function topFiveScoringAverageByYear($year) |
|
| 28 | + { |
|
| 29 | + //Get players |
|
| 30 | + //For each player where match > 0 select scores and average them |
|
| 31 | + //Store in players array |
|
| 32 | + $date1 = $year . '-01-01'; |
|
| 33 | + $date2 = $year . '-12-31'; |
|
| 34 | + $players = Player::all(); |
|
| 35 | + $average = array(); |
|
| 36 | + $i = 0; |
|
| 37 | + foreach($players as $key => $player) { |
|
| 38 | + $rounds = Round::where('match_id', '>', '0') |
|
| 39 | + ->where('player_id', '=', $player->id) |
|
| 40 | + ->where('date', '>=', $date1) |
|
| 41 | + ->where('date', '<=', $date2) |
|
| 42 | + ->get(); |
|
| 43 | + $scores = array(); |
|
| 44 | 44 | foreach($rounds as $round) { |
| 45 | 45 | $scores[] = $round->score; |
| 46 | 46 | } |
| 47 | - if(count($scores) > 0) { |
|
| 48 | - $average[$i]['average'] = round((array_sum($scores) / count($scores)) ,2); |
|
| 49 | - $average[$i]['player_id'] = $player->id; |
|
| 50 | - $average[$i]['name'] = $player->name; |
|
| 51 | - $average[$i]['rounds'] = count($scores); |
|
| 52 | - $i++; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - array_multisort($average); |
|
| 56 | - return $average; |
|
| 57 | - } |
|
| 58 | - public function topFiveNetScoresByYear($year) |
|
| 59 | - { |
|
| 47 | + if(count($scores) > 0) { |
|
| 48 | + $average[$i]['average'] = round((array_sum($scores) / count($scores)) ,2); |
|
| 49 | + $average[$i]['player_id'] = $player->id; |
|
| 50 | + $average[$i]['name'] = $player->name; |
|
| 51 | + $average[$i]['rounds'] = count($scores); |
|
| 52 | + $i++; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + array_multisort($average); |
|
| 56 | + return $average; |
|
| 57 | + } |
|
| 58 | + public function topFiveNetScoresByYear($year) |
|
| 59 | + { |
|
| 60 | 60 | $date1 = $year . '-01-01'; |
| 61 | 61 | $date2 = $year . '-12-31'; |
| 62 | 62 | |
@@ -64,29 +64,29 @@ discard block |
||
| 64 | 64 | ->where('created_at', '>=', $date1) |
| 65 | 65 | ->where('created_at', '<=', $date2) |
| 66 | 66 | ->orderBy('score')->take(5)->get(); |
| 67 | - } |
|
| 68 | - public function mostSkinsByYear($year) |
|
| 69 | - { |
|
| 70 | - $year = $year . '-01-01'; |
|
| 71 | - $players = Player::all(); |
|
| 72 | - $i = 0; |
|
| 73 | - $skinsCount = array(); |
|
| 74 | - foreach($players as $key => $player) { |
|
| 75 | - $skins = Skin::with('player','level') |
|
| 76 | - ->where('player_id', '=', $player->id) |
|
| 77 | - ->where('created_at', '>', $year) |
|
| 78 | - ->get(); |
|
| 79 | - if(count($skins) > 0) { |
|
| 80 | - $skinsCount[$i]['skins'] = $skins->count(); |
|
| 81 | - $skinsCount[$i]['name'] = $player->name; |
|
| 82 | - $i++; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - array_multisort($skinsCount, SORT_DESC); |
|
| 86 | - return $skinsCount; |
|
| 87 | - } |
|
| 88 | - public function totalEagles($year){} |
|
| 89 | - public function totalBirdies($year) |
|
| 67 | + } |
|
| 68 | + public function mostSkinsByYear($year) |
|
| 69 | + { |
|
| 70 | + $year = $year . '-01-01'; |
|
| 71 | + $players = Player::all(); |
|
| 72 | + $i = 0; |
|
| 73 | + $skinsCount = array(); |
|
| 74 | + foreach($players as $key => $player) { |
|
| 75 | + $skins = Skin::with('player','level') |
|
| 76 | + ->where('player_id', '=', $player->id) |
|
| 77 | + ->where('created_at', '>', $year) |
|
| 78 | + ->get(); |
|
| 79 | + if(count($skins) > 0) { |
|
| 80 | + $skinsCount[$i]['skins'] = $skins->count(); |
|
| 81 | + $skinsCount[$i]['name'] = $player->name; |
|
| 82 | + $i++; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + array_multisort($skinsCount, SORT_DESC); |
|
| 86 | + return $skinsCount; |
|
| 87 | + } |
|
| 88 | + public function totalEagles($year){} |
|
| 89 | + public function totalBirdies($year) |
|
| 90 | 90 | { |
| 91 | 91 | $year = $year . '-01-01'; |
| 92 | 92 | $holescores = Holescore::with('round.player','hole') |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | return $birds; |
| 112 | 112 | } |
| 113 | - public function totalPars($year) |
|
| 113 | + public function totalPars($year) |
|
| 114 | 114 | { |
| 115 | 115 | $year = $year . '-01-01'; |
| 116 | 116 | $holescores = Holescore::with('round.player','hole') |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | return $pars; |
| 136 | 136 | } |
| 137 | - public function totalBogeys($year) |
|
| 137 | + public function totalBogeys($year) |
|
| 138 | 138 | { |
| 139 | 139 | $year = $year . '-01-01'; |
| 140 | 140 | $holescores = Holescore::with('round.player','hole') |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | return $bogeys; |
| 160 | 160 | } |
| 161 | - public function totalDoubles($year) |
|
| 161 | + public function totalDoubles($year) |
|
| 162 | 162 | { |
| 163 | 163 | $year = $year . '-01-01'; |
| 164 | 164 | $holescores = Holescore::with('round.player','hole') |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | return $doubles; |
| 184 | 184 | } |
| 185 | - public function totalOthers($year) |
|
| 185 | + public function totalOthers($year) |
|
| 186 | 186 | { |
| 187 | 187 | $year = $year . '-01-01'; |
| 188 | 188 | $holescores = Holescore::with('round.player','hole') |