Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-03-23 19:44:28 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-03-23 19:44:28 +0300
commit81d603e2c1be5b45a623eec4f5ea9a70abcc676c (patch)
treee1f0269f55b58c6610fda7c94b4700f82561e105 /lib
parent78fe7270ab13b8d12d2de46488a37993a11029f6 (diff)
parente24da35984c13132e204ff923e4b75600ebed56e (diff)
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/commits_calendar.rb41
-rw-r--r--lib/gitlab/contributions_calendar.rb56
2 files changed, 56 insertions, 41 deletions
diff --git a/lib/gitlab/commits_calendar.rb b/lib/gitlab/commits_calendar.rb
deleted file mode 100644
index 8963d346b6f..00000000000
--- a/lib/gitlab/commits_calendar.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-module Gitlab
- class CommitsCalendar
- attr_reader :timestamps
-
- def initialize(projects, user)
- @timestamps = {}
- date_timestamps = []
-
- projects.reject(&:forked?).each do |project|
- date_timestamps << ProjectContributions.new(project, user).commits_log
- end
-
- # Sumarrize commits from all projects per days
- date_timestamps = date_timestamps.inject do |collection, date|
- collection.merge(date) { |k, old_v, new_v| old_v + new_v }
- end
-
- date_timestamps ||= []
- date_timestamps.each do |date, commits|
- timestamp = Date.parse(date).to_time.to_i.to_s rescue nil
- @timestamps[timestamp] = commits if timestamp
- end
- end
-
- def self.get_commits_for_date(projects, user, date)
- user_commits = {}
- projects.reject(&:forked?).each do |project|
- user_commits[project] = ProjectContributions.new(project, user).user_commits_on_date(date)
- end
- user_commits
- end
-
- def starting_year
- (Time.now - 1.year).strftime("%Y")
- end
-
- def starting_month
- Date.today.strftime("%m").to_i
- end
- end
-end
diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb
new file mode 100644
index 00000000000..3fd0823df06
--- /dev/null
+++ b/lib/gitlab/contributions_calendar.rb
@@ -0,0 +1,56 @@
+module Gitlab
+ class ContributionsCalendar
+ attr_reader :timestamps, :projects, :user
+
+ def initialize(projects, user)
+ @projects = projects
+ @user = user
+ end
+
+ def timestamps
+ return @timestamps if @timestamps.present?
+
+ @timestamps = {}
+ date_from = 1.year.ago
+ date_to = Date.today
+
+ events = Event.reorder(nil).contributions.where(author_id: user.id).
+ where("created_at > ?", date_from).where(project_id: projects).
+ group('date(created_at)').
+ select('date(created_at), count(id) as total_amount').
+ map(&:attributes)
+
+ dates = (1.year.ago.to_date..(Date.today + 1.day)).to_a
+
+ dates.each do |date|
+ date_id = date.to_time.to_i.to_s
+ @timestamps[date_id] = 0
+ day_events = events.find { |day_events| day_events["date"] == date }
+
+ if day_events
+ @timestamps[date_id] = day_events["total_amount"]
+ end
+ end
+
+ @timestamps
+ end
+
+ def events_by_date(date)
+ events = Event.contributions.where(author_id: user.id).
+ where("created_at > ? AND created_at < ?", date.beginning_of_day, date.end_of_day).
+ where(project_id: projects)
+
+ events.select do |event|
+ event.push? || event.issue? || event.merge_request?
+ end
+ end
+
+ def starting_year
+ (Time.now - 1.year).strftime("%Y")
+ end
+
+ def starting_month
+ Date.today.strftime("%m").to_i
+ end
+ end
+end