summaryrefslogtreecommitdiff
path: root/lib/gitlab/cycle_analytics/base_stage.rb
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2017-01-18 22:23:53 -0600
committerMike Greiling <mike@pixelcog.com>2017-01-18 22:23:53 -0600
commit0d2ae3e7c15254aa366665cd0323ba9b7845da70 (patch)
tree0e970c96ec83bb3df0ba9059bddd4a0ea881c615 /lib/gitlab/cycle_analytics/base_stage.rb
parentc0ba747c586ff7f5f42097a0e49eace30c57ebdf (diff)
parent270dc22658424ee7f279db99e56c6fc69acd3eb7 (diff)
downloadgitlab-ce-0d2ae3e7c15254aa366665cd0323ba9b7845da70.tar.gz
Merge branch 'master' into go-go-gadget-webpack
* master: (67 commits) Add some API endpoints for time tracking. use destructuring syntax instead add changelog yml file correct User_agent placement in robots.txt Fixing typo Fix Project#update_repository_size to convert MB to Bytes properly Remove repository trait from factories that don't need it in features Add the `:repository` trait to `:project` factories in Cucumber steps Add a `:repository` trait to the `:empty_project` factory Update clipboard_button text: Copy commit SHA to clipboard Fix search bar filter dropdown scrollbars get rid of log fix UI behaviour - only make new calls when button is clicked and dropdown is not displayed better UI fix - simple solution Disable all cops in .rubocop_todo.yml fix spec refactored a bunch of stuff based on feedback fix serializer fix bug retrieving medians fix specs ...
Diffstat (limited to 'lib/gitlab/cycle_analytics/base_stage.rb')
-rw-r--r--lib/gitlab/cycle_analytics/base_stage.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/gitlab/cycle_analytics/base_stage.rb b/lib/gitlab/cycle_analytics/base_stage.rb
new file mode 100644
index 00000000000..74bbcdcb3dd
--- /dev/null
+++ b/lib/gitlab/cycle_analytics/base_stage.rb
@@ -0,0 +1,54 @@
+module Gitlab
+ module CycleAnalytics
+ class BaseStage
+ include BaseQuery
+
+ def initialize(project:, options:)
+ @project = project
+ @options = options
+ end
+
+ def events
+ event_fetcher.fetch
+ end
+
+ def as_json
+ AnalyticsStageSerializer.new.represent(self).as_json
+ end
+
+ def title
+ name.to_s.capitalize
+ end
+
+ def median
+ cte_table = Arel::Table.new("cte_table_for_#{name}")
+
+ # Build a `SELECT` query. We find the first of the `end_time_attrs` that isn't `NULL` (call this end_time).
+ # Next, we find the first of the start_time_attrs that isn't `NULL` (call this start_time).
+ # We compute the (end_time - start_time) interval, and give it an alias based on the current
+ # cycle analytics stage.
+ interval_query = Arel::Nodes::As.new(
+ cte_table,
+ subtract_datetimes(base_query.dup, start_time_attrs, end_time_attrs, name.to_s))
+
+ median_datetime(cte_table, interval_query, name)
+ end
+
+ def name
+ raise NotImplementedError.new("Expected #{self.name} to implement name")
+ end
+
+ private
+
+ def event_fetcher
+ @event_fetcher ||= Gitlab::CycleAnalytics::EventFetcher[name].new(project: @project,
+ stage: name,
+ options: event_options)
+ end
+
+ def event_options
+ @options.merge(start_time_attrs: start_time_attrs, end_time_attrs: end_time_attrs)
+ end
+ end
+ end
+end