docbrown/app/controllers/internal/dogfood_controller.rb
rhymes e588fa7ece Code cleanups (#659)
* Initial automatic cleanup with rubocop

* Fix syntax error introduced by rubocop

* Cleanup seeds file

* Cleanup lib folder

* Exclude bin folder because it contains auto generated files

* Make Rubocop a little bit more chatty

* Block length should not include comments in the count

* Cleanup config folder

* Cleanup specs

* Updated Rubocop version and generated a todo file

* Fix broken ArticlesApi spec

* Fix tests

* Restored rubocop pre-commit hook
2018-08-07 11:00:13 -04:00

25 lines
996 B
Ruby

class Internal::DogfoodController < Internal::ApplicationController
layout "internal"
def index
usernames = if Rails.env.production?
["ben", "jess", "peter", "maestromac", "andy", "lianafelt"]
else
["thepracticaldev", "bendhalpern"]
end
@team_members = User.where(username: usernames)
@comments_this_week = Comment.where(user_id: @team_members.pluck(:id)).where("created_at > ?", Date.today.beginning_of_week).pluck(:user_id)
@comment_totals_this_week = frequency(@comments_this_week)
@comments_24_hours = Comment.where(user_id: @team_members.pluck(:id)).where("created_at > ?", 24.hours.ago).pluck(:user_id)
@comment_totals_24_hours = frequency(@comments_24_hours)
end
def frequency(a)
a.group_by do |e|
e
end.map do |key, values|
{ number_of_comments: values.size, username: User.find(key).username }
end.sort_by { |hsh| hsh[:number_of_comments] }.reverse!
end
end