diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index 0c3089db..a59a6575 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -1,5 +1,5 @@ module HomeHelper - + def featured_groups @featured_groups = Group.where(is_featured: true) end @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index 51c422e3..822beede 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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