1
|
|
|
<?php namespace GolfLeague\Statistics\Player; |
2
|
|
|
|
3
|
|
|
use Carbon\Carbon; |
4
|
|
|
use \Round; |
5
|
|
|
use \Player; |
6
|
|
|
use \Skin; |
7
|
|
|
use \Netwinner; |
8
|
|
|
use \Holescore; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class PlayerStatisticsEloquent implements PlayerStatistics |
12
|
|
|
{ |
13
|
|
|
private $date1 = '-01-01'; |
|
|
|
|
14
|
|
|
private $date2 = '-12-31'; |
|
|
|
|
15
|
|
|
|
16
|
|
|
public function matchesHandicap($playerId){} |
17
|
|
View Code Duplication |
public function scoringAverage($playerId) |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$today = Carbon::today()->toDateString(); |
20
|
|
|
$rounds = Round::where('player_id', '=', $playerId) |
21
|
|
|
->where('date', '<', $today) |
22
|
|
|
->get(); |
23
|
|
|
$scores = $rounds->map(function($round) |
24
|
|
|
{ |
25
|
|
|
return $round->score; |
26
|
|
|
}); |
27
|
|
|
if($rounds->count() > 0) { |
28
|
|
|
return round(array_sum($scores->toArray())/($rounds->count()), 2); |
29
|
|
|
} else { |
30
|
|
|
return $rounds; |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
public function scoringAverageByYear($playerId, $year) |
34
|
|
|
{ |
35
|
|
|
$date1 = $year . '-01-01'; |
36
|
|
|
$date2 = $year . '-12-31'; |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
$rounds = Round::where('player_id', '=', $playerId) |
40
|
|
|
->where('date', '>=', $date1) |
41
|
|
|
->where('date', '<=', $date2) |
42
|
|
|
->get(); |
43
|
|
|
$scores = $rounds->map(function($round) |
44
|
|
|
{ |
45
|
|
|
return $round->score; |
46
|
|
|
}); |
47
|
|
|
if($rounds->count() > 0) { |
48
|
|
|
return round(array_sum($scores->toArray())/($rounds->count()), 2); |
49
|
|
|
} else { |
50
|
|
|
return $rounds; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
public function scoringAverageMatchesByYear($year){} |
56
|
|
|
public function handicapRounds($playerId){} |
57
|
|
|
|
58
|
|
|
public function scoringAverageCourse($course){} |
59
|
|
|
public function scoringAverageCourseByYear($course, $year){} |
60
|
|
|
public function scoringAverageCourseMatchesByYear($course, $year){} |
61
|
|
|
|
62
|
|
|
public function totalEagles(){} |
63
|
|
|
public function eaglesByYear($year){} |
64
|
|
|
public function eaglesMatchesByYear($year){} |
65
|
|
|
|
66
|
|
|
public function totalBirdies($playerId){} |
67
|
|
|
public function birdiesByYear($playerId, $year) |
68
|
|
|
{ |
69
|
|
|
$year = $year . '-01-01'; |
70
|
|
|
$holescores = Holescore::with('round.player','hole') |
71
|
|
|
->where('created_at', '>', $year) |
72
|
|
|
->get(); |
73
|
|
|
$allBirdies = array(); |
74
|
|
|
foreach($holescores as $key => $holescore) { |
75
|
|
|
if($holescore['round']['match_id'] != null){ |
76
|
|
|
if( ($holescore['hole']['par'] - $holescore['score']) === 1) { |
77
|
|
|
$allBirdies[]= $holescore['round']['player']['id']; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
return count(array_keys($allBirdies, $playerId)); |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
public function birdiesMatchesByYear($year){} |
85
|
|
|
|
86
|
|
|
public function totalPars(){} |
87
|
|
|
public function parsByYear($year){} |
88
|
|
|
public function parsMatchesByYear($year){} |
89
|
|
|
|
90
|
|
|
public function totalbogeys(){} |
91
|
|
|
public function bogeysByYear($year){} |
92
|
|
|
public function bogeysMatchesByYear($year){} |
93
|
|
|
|
94
|
|
|
public function totalDoubles(){} |
95
|
|
|
public function doublesByYear($year){} |
96
|
|
|
public function doublesMatchesByYear($year){} |
97
|
|
|
|
98
|
|
|
public function totalOthers(){} |
99
|
|
|
public function othersByYear($year){} |
100
|
|
|
public function othersMatchesByYear($year){} |
101
|
|
|
|
102
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.