Skip to content

Commit

Permalink
Updated seeds.rb & home_helper to ease setup in dev env
Browse files Browse the repository at this point in the history
  • Loading branch information
prasadsurase committed Sep 14, 2016
1 parent c96ef9f commit 8838940
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module HomeHelper

def featured_groups
@featured_groups = Group.where(is_featured: true)
end
Expand All @@ -19,20 +19,23 @@ def widget_class
end

def multi_line_chart

users = Subscription.collection.aggregate( [ { "$group" => { _id: "$round_id", total: { "$sum" => 1 } } } ] ).sort {|x, y| Date.parse(Round.find(y["_id"]).name) <=> Date.parse(Round.find(x["_id"]).name) }.collect { |r| [ Round.find(r["_id"]).name, r["total"] ] }[1..6].reverse

contributions = Subscription.collection.aggregate( [ {"$match" => { "created_at" => { "$gt" => Date.parse("march 2016") } } }, { "$group" => { _id: "$round_id", total: { "$sum" => "$points" } } } ]).sort {|x, y| Date.parse(Round.find(y["_id"]).name) <=> Date.parse(Round.find(x["_id"]).name) }.collect { |r| [ Round.find(r["_id"]).name, r["total"] ] }[1..6].reverse
users = Subscription.collection.aggregate( [ { "$group" => { _id: "$round_id", total: { "$sum" => 1 } } } ] ).sort {|x, y| Date.parse(Round.find(y["_id"]).name) <=> Date.parse(Round.find(x["_id"]).name) }.collect { |r| [ Round.find(r["_id"]).name, r["total"] ] }
users = users[1..6].reverse if users.any?


contributions = Subscription.collection.aggregate( [ {"$match" => { "created_at" => { "$gt" => Date.parse("march 2016") } } }, { "$group" => { _id: "$round_id", total: { "$sum" => "$points" } } } ]).sort {|x, y| Date.parse(Round.find(y["_id"]).name) <=> Date.parse(Round.find(x["_id"]).name) }.collect { |r| [ Round.find(r["_id"]).name, r["total"] ] }
contributions = contributions[1..6].reverse if contributions.any?

@user_trend = []
@contribution_trend = []
@user_xAxis = []
@xAxis = []

users.map{ |user| @user_trend << user[1]; @user_xAxis << user[0]}

contributions.map{ |contribution| @contribution_trend << contribution[1]; @xAxis << contribution[0]}


end

Expand Down
5 changes: 5 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@

#Roles
Role.find_or_create_by(name: 'Admin')

if Rails.env.development?
Goal.setup if Goal.count.zero?
Round.create(name: 'first', from_date: Date.today.beginning_of_month, end_date: Date.today.end_of_month, status: :open) if Round.find_by(status: :open).nil?
end

0 comments on commit 8838940

Please sign in to comment.