Skip to content

Commit

Permalink
Merge pull request #118 from prasadsurase/ease-dev-setup
Browse files Browse the repository at this point in the history
Updated seeds.rb & home_helper to ease setup in dev env.
  • Loading branch information
gautamrege authored Sep 15, 2016
2 parents aebe1ec + 8838940 commit 3c56a18
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 3c56a18

Please sign in to comment.