Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,46 @@ def fetch_engagement_stats
stats
end

def create_raffle_tickets
tickets = []

attendee_github_stats.each do |email, stats|
contributions = stats ? stats[:pull_requests] + stats[:issues] : 0
contributions.times { tickets << email }
end

tickets
end

def select_raffle_winner(tickets = create_raffle_tickets)
winner = User.find_by_email(tickets.sample)
{ email: winner.email, name: winner.profile.name } if winner
end

def print_raffle_winners(winners)
winner_text = ""
winners.compact!

winners.each_with_index do |winner, i|
winner_text += "#{i+1}. #{winner[:name]} - #{winner[:email]}\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surrounding space missing for operator '+'.

end

winner_text = "This event had no contributions." if winner_text.blank?
Rails.logger.info(winner_text)
end

def raffle(num_winners = 2)
winners = []
tickets = create_raffle_tickets

if tickets.present?
num_winners.times { winners << select_raffle_winner(tickets) }
end

print_raffle_winners(winners)
tickets
end

def upcoming?
true if end_date >= Time.now
end
Expand Down