@@ -195,6 +195,10 @@ func Get170StatisticsForPlayer(id int) (*models.Statistics170, error) {
195195 err := models .DB .QueryRow (`
196196 SELECT
197197 p.id,
198+ COUNT(DISTINCT m.id) AS 'matches_played',
199+ COUNT(DISTINCT m2.id) AS 'matches_won',
200+ COUNT(DISTINCT l.id) AS 'legs_played',
201+ COUNT(DISTINCT l2.id) AS 'legs_won',
198202 SUM(s.points),
199203 SUM(s.ppd_score) / SUM(s.darts_thrown),
200204 SUM(s.rounds),
@@ -218,8 +222,9 @@ func Get170StatisticsForPlayer(id int) (*models.Statistics170, error) {
218222 WHERE s.player_id = ?
219223 AND l.is_finished = 1 AND m.is_abandoned = 0 AND m.is_walkover = 0
220224 AND m.match_type_id = 17
221- GROUP BY p.id` , id ).Scan (& s .LegID , & s .PlayerID , & s .Points , & s .PPD , & s .Rounds , & s .CheckoutPercentage , & s .CheckoutAttempts ,
222- & s .HighestCheckout , & s .DartsThrown , & darts9 , & darts8 , & darts7 , & darts6 , & darts5 , & darts4 , & darts3 )
225+ GROUP BY p.id` , id ).Scan (& s .PlayerID , & s .MatchesPlayed , & s .MatchesWon , & s .LegsPlayed , & s .LegsWon ,
226+ & s .Points , & s .PPD , & s .Rounds , & s .CheckoutPercentage , & s .CheckoutAttempts , & s .HighestCheckout ,
227+ & s .DartsThrown , & darts9 , & darts8 , & darts7 , & darts6 , & darts5 , & darts4 , & darts3 )
223228 if err != nil {
224229 if err == sql .ErrNoRows {
225230 return new (models.Statistics170 ), nil
@@ -285,13 +290,24 @@ func Get170HistoryForPlayer(id int, start int, limit int) ([]*models.Leg, error)
285290 legs = make ([]* models.Leg , 0 )
286291 for rows .Next () {
287292 s := new (models.Statistics170 )
288- s .CheckoutDarts = make (map [int ]int )
293+ var darts9 , darts8 , darts7 , darts6 , darts5 , darts4 , darts3 int
294+
289295 err := rows .Scan (& s .LegID , & s .PlayerID , & s .Points , & s .PPD , & s .PPDScore , & s .Rounds , & s .CheckoutPercentage ,
290- & s .CheckoutAttempts , & s .CheckoutCompleted , & s .HighestCheckout , s . CheckoutDarts [ 9 ], s . CheckoutDarts [ 8 ] ,
291- s . CheckoutDarts [ 7 ], s . CheckoutDarts [ 6 ], s . CheckoutDarts [ 5 ], s . CheckoutDarts [ 4 ], s . CheckoutDarts [ 3 ] )
296+ & s .CheckoutAttempts , & s .CheckoutCompleted , & s .HighestCheckout , & darts9 , & darts8 , & darts7 , & darts6 , & darts5 ,
297+ & darts4 , & darts3 )
292298 if err != nil {
293299 return nil , err
294300 }
301+ checkoutDarts := make (map [int ]int , 0 )
302+ checkoutDarts [9 ] = darts9
303+ checkoutDarts [8 ] = darts8
304+ checkoutDarts [7 ] = darts7
305+ checkoutDarts [6 ] = darts6
306+ checkoutDarts [5 ] = darts5
307+ checkoutDarts [4 ] = darts4
308+ checkoutDarts [3 ] = darts3
309+ s .CheckoutDarts = checkoutDarts
310+
295311 leg := m [s .LegID ]
296312 leg .Statistics = s
297313 legs = append (legs , leg )
0 commit comments