diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 5d57457..416f901 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -170,6 +170,44 @@ def confirm_rsvps @rsvps = @event.rsvps.joins(:user).where("users.id in (?)", users).sort_by { |rsvp| rsvp.user.full_name } end + def leaderboard + @semester = params[:semester] ? MemberSemester.find_by_id(params[:semester]) : MemberSemester.current + @users = Role.members.semester_filter(@semester).all_users + @users_array = [] + #moar_people = [ 'eunjian' ].collect{|u|Person.find_by_username(u)} # TODO remove when we have leaderboard opt-in + @users.each do |user| + # Makeshift data structure + events = user.rsvps.where(confirmed: 't').joins(:event).where("events.start_time > ? AND events.start_time < ?", @semester.start_time, @semester.end_time) + @users_array << { + :user => user, + :total => events.count, + :events => events + } + end + + @users_array.each do |entry| + entry[:big_fun] = entry[:events].where("events.event_type = ? ", "Big Fun").count + entry[:fun] = entry[:events].where("events.event_type = ? ", "Fun").count + entry[:service] = entry[:events].where("events.event_type = ? ", "Service").count + entry[:score] = 2*entry[:big_fun] + entry[:fun] + 3*entry[:service] + end + + @users_array.sort!{|a,b| a[:score] <=> b[:score]} + @users_array.reverse! + rank = 0 + last_num = -1 + incr = 1 + @users_array.each do |entry| + if last_num != entry[:score] + rank += incr + last_num = entry[:score] + incr = 0 + end + entry[:rank] = rank + incr += 1 + end + end + private def event_authorize @event_auth = comm_authorize diff --git a/app/controllers/rsvps_controller.rb b/app/controllers/rsvps_controller.rb index 8f6078c..b414315 100644 --- a/app/controllers/rsvps_controller.rb +++ b/app/controllers/rsvps_controller.rb @@ -92,10 +92,10 @@ def destroy def confirm - role = params[:role] || :candidate + role = params[:role] || :candidates respond_to do |format| - if @rsvp.update_attribute :confirmed, Rsvp::Confirmed + if @rsvp.update_attributes(confirmed: Rsvp::Confirmed, confirmed_by: current_user.id, confirmed_at: Time.now) format.html { redirect_to(confirm_rsvps_path(@rsvp.event_id, :role => role), :notice => 'Rsvp was confirmed.') } format.xml { render :xml => @rsvp } else @@ -106,7 +106,7 @@ def confirm end def unconfirm - @rsvp.update_attribute :confirmed, Rsvp::Unconfirmed + @rsvp.update_attributes(confirmed: Rsvp::Unconfirmed, confirmed_by: current_user.id, confirmed_at: Time.now) role = params[:role] || "candidates" respond_to do |format| @@ -116,7 +116,7 @@ def unconfirm end def reject - @rsvp.update_attribute :confirmed, Rsvp::Rejected + @rsvp.update_attributes(confirmed: Rsvp::Rejected, confirmed_by: current_user.id, confirmed_at: Time.now) role = params[:role] || "candidates" respond_to do |format| diff --git a/app/models/member_semester.rb b/app/models/member_semester.rb index e01e9ed..23871d6 100644 --- a/app/models/member_semester.rb +++ b/app/models/member_semester.rb @@ -57,4 +57,20 @@ def prev MemberSemester.find_by_year_and_season(year, "Spring") end end + + def start_time + if season == "Spring" + Date.civil(year) + else + Date.civil(year, 8) + end + end + + def end_time + if season == "Spring" + Date.civil(year, 6) + else + Date.civil(year, 12, 30) + end + end end diff --git a/app/views/events/leaderboard.html.erb b/app/views/events/leaderboard.html.erb new file mode 100644 index 0000000..09b5e62 --- /dev/null +++ b/app/views/events/leaderboard.html.erb @@ -0,0 +1,29 @@ +
Scoring system: Big fun = 2 pts; Fun = 1 pt; Service = 3 pts +
+ + + +Rank + | Name | +Score | +Big Fun | +Fun | +Service | +
---|---|---|---|---|---|
<%= entry[:rank] %> | +<%= entry[:user].full_name %> | +<%= entry[:score] %> | +<%= entry[:big_fun] %> | +<%= entry[:fun] %> | +<%= entry[:service] %> | +