/** * Get all stats by user * @param int $user_id * @return mixed|bool */ static function GetByUser($user_id) { $stats = new Stats(); $stats->total_bets_placed = 0; $stats->total_bets_won = 0; $stats->total_bets_lost = 0; $stats->total_points_won = 0; $stats->total_points_lost = 0; $stats->avg_bet_value = 0; $bets = Bet::GetAll(); $totals = []; foreach ($bets as $bet) { if ($user_id == $bet->user_id) { $stats->total_bets_placed++; if ($bet->result == 1) { $stats->total_bets_won++; $stats->total_points_won += $bet->points_total; } if ($bet->result == 0) { $stats->total_bets_lost++; $stats->total_points_lost += $bet->points_total; } $totals[] = $bet->points_total; } } $stats->avg_bet_value = mmmr($totals, 'median'); $stats->wealth_gap = wealthGap(); return $stats; }