Skip to content

Commit

Permalink
browse historical leaderboards
Browse files Browse the repository at this point in the history
  • Loading branch information
pjurewicz committed Oct 12, 2023
1 parent e2d4bc2 commit 5a04e58
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/leaderboards_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class LeaderboardsController < ApplicationController
def show
team = Team.find_by(slack_team_domain: params[:team_domain])
@leaderboard = Leaderboards.new(team, nil).top_for_this_year
@leaderboard = Leaderboards.new(team, nil).top_for_year(params[:year])
end
end
2 changes: 2 additions & 0 deletions app/models/daily_statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ class DailyStatistic < ActiveRecord::Base
scope :by_period, -> (starting_date, duration) { where('date >= ? and date < ?', starting_date, starting_date + duration) }
scope :for_this_week, -> (time_zone) { by_period(Time.now.in_time_zone(time_zone).beginning_of_week.to_date, 7.days) }
scope :for_this_month, -> (time_zone) { by_period(Time.now.in_time_zone(time_zone).beginning_of_month.to_date, 1.month) }
scope :for_month, -> (year, time_zone) { by_period(Time.new(year, month).in_time_zone(time_zone).beginning_of_month.to_date, 1.month) }
scope :for_this_year, -> (time_zone) { by_period(Time.now.in_time_zone(time_zone).beginning_of_year.to_date, 1.year) }
scope :for_year, -> (year, time_zone) { by_period(Time.new(year).in_time_zone(time_zone).beginning_of_year.to_date, 1.year) }
scope :of_team, -> (team_id) { where(team_id: team_id) }

def self.rebuild_read_model!(event_store = Rails.configuration.event_store)
Expand Down
8 changes: 8 additions & 0 deletions app/models/leaderboards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ def top_for_this_year
aggreated_data(@team_scope.for_this_year(@team_time_zone))
end

def top_for_month(year, month)
aggreated_data(@team_scope.for_month(year, month, @team_time_zone))
end

def top_for_year(year)
aggreated_data(@team_scope.for_year(year, @team_time_zone))
end

private

def aggreated_data(scope)
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ def matches?(request)
post "/slack/plus" => "slack#leaderboard", :constraints => LeaderboardConstraint.new
post "/slack/plus" => "slack#plus"

get "/:team_domain/leaderboards/year" => "leaderboards#show"
get "/:team_domain/leaderboards/year/:year" => "leaderboards#show"
end

0 comments on commit 5a04e58

Please sign in to comment.