Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6bd773a8
Commit
6bd773a8
authored
Sep 14, 2020
by
Dmytro Zaporozhets (DZ)
Committed by
James Fargher
Sep 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add activity graph to PA
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
8672da3c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
82 additions
and
3 deletions
+82
-3
app/controllers/projects/product_analytics_controller.rb
app/controllers/projects/product_analytics_controller.rb
+4
-0
app/models/product_analytics_event.rb
app/models/product_analytics_event.rb
+7
-0
app/services/product_analytics/build_activity_graph_service.rb
...ervices/product_analytics/build_activity_graph_service.rb
+13
-0
app/services/product_analytics/build_graph_service.rb
app/services/product_analytics/build_graph_service.rb
+7
-3
app/views/projects/product_analytics/graphs.html.haml
app/views/projects/product_analytics/graphs.html.haml
+4
-0
spec/models/product_analytics_event_spec.rb
spec/models/product_analytics_event_spec.rb
+14
-0
spec/services/product_analytics/build_activity_graph_service_spec.rb
...es/product_analytics/build_activity_graph_service_spec.rb
+33
-0
No files found.
app/controllers/projects/product_analytics_controller.rb
View file @
6bd773a8
...
@@ -27,6 +27,10 @@ class Projects::ProductAnalyticsController < Projects::ApplicationController
...
@@ -27,6 +27,10 @@ class Projects::ProductAnalyticsController < Projects::ApplicationController
.
new
(
project
,
{
graph:
graph
,
timerange:
@timerange
})
.
new
(
project
,
{
graph:
graph
,
timerange:
@timerange
})
.
execute
.
execute
end
end
@activity_graph
=
ProductAnalytics
::
BuildActivityGraphService
.
new
(
project
,
{
timerange:
@timerange
})
.
execute
end
end
private
private
...
...
app/models/product_analytics_event.rb
View file @
6bd773a8
...
@@ -26,6 +26,13 @@ class ProductAnalyticsEvent < ApplicationRecord
...
@@ -26,6 +26,13 @@ class ProductAnalyticsEvent < ApplicationRecord
group
(
graph
).
timerange
(
days
).
count
group
(
graph
).
timerange
(
days
).
count
end
end
def
self
.
count_collector_tstamp_by_day
(
days
)
group
(
"DATE_TRUNC('day', collector_tstamp)"
)
.
reorder
(
'date_trunc_day_collector_tstamp'
)
.
timerange
(
days
)
.
count
end
def
as_json_wo_empty
def
as_json_wo_empty
as_json
.
compact
as_json
.
compact
end
end
...
...
app/services/product_analytics/build_activity_graph_service.rb
0 → 100644
View file @
6bd773a8
# frozen_string_literal: true
module
ProductAnalytics
class
BuildActivityGraphService
<
BuildGraphService
def
execute
timerange
=
@params
[
:timerange
].
days
results
=
product_analytics_events
.
count_collector_tstamp_by_day
(
timerange
)
format_results
(
'collector_tstamp'
,
results
.
transform_keys
(
&
:to_date
))
end
end
end
app/services/product_analytics/build_graph_service.rb
View file @
6bd773a8
...
@@ -13,15 +13,19 @@ module ProductAnalytics
...
@@ -13,15 +13,19 @@ module ProductAnalytics
results
=
product_analytics_events
.
count_by_graph
(
graph
,
timerange
)
results
=
product_analytics_events
.
count_by_graph
(
graph
,
timerange
)
format_results
(
graph
,
results
)
end
private
def
format_results
(
name
,
results
)
{
{
id:
graph
,
id:
name
,
keys:
results
.
keys
,
keys:
results
.
keys
,
values:
results
.
values
values:
results
.
values
}
}
end
end
private
def
product_analytics_events
def
product_analytics_events
@project
.
product_analytics_events
@project
.
product_analytics_events
end
end
...
...
app/views/projects/product_analytics/graphs.html.haml
View file @
6bd773a8
...
@@ -5,6 +5,10 @@
...
@@ -5,6 +5,10 @@
%p
%p
=
_
(
'Showing graphs based on events of the last %{timerange} days.'
)
%
{
timerange:
@timerange
}
=
_
(
'Showing graphs based on events of the last %{timerange} days.'
)
%
{
timerange:
@timerange
}
.gl-mb-3
=
render
'graph'
,
graph:
@activity_graph
-
@graphs
.
each_slice
(
2
)
do
|
pair
|
-
@graphs
.
each_slice
(
2
)
do
|
pair
|
.row.append-bottom-10
.row.append-bottom-10
-
pair
.
each
do
|
graph
|
-
pair
.
each
do
|
graph
|
...
...
spec/models/product_analytics_event_spec.rb
View file @
6bd773a8
...
@@ -46,4 +46,18 @@ RSpec.describe ProductAnalyticsEvent, type: :model do
...
@@ -46,4 +46,18 @@ RSpec.describe ProductAnalyticsEvent, type: :model do
it
{
expect
(
described_class
.
by_category_and_action
(
'catA'
,
'actA'
)).
to
match_array
([
event
])
}
it
{
expect
(
described_class
.
by_category_and_action
(
'catA'
,
'actA'
)).
to
match_array
([
event
])
}
end
end
describe
'.count_collector_tstamp_by_day'
do
let_it_be
(
:time_now
)
{
Time
.
zone
.
now
}
let_it_be
(
:time_ago
)
{
Time
.
zone
.
now
-
5
.
days
}
let_it_be
(
:events
)
do
create_list
(
:product_analytics_event
,
3
,
collector_tstamp:
time_now
)
+
create_list
(
:product_analytics_event
,
2
,
collector_tstamp:
time_ago
)
end
subject
{
described_class
.
count_collector_tstamp_by_day
(
7
.
days
)
}
it
{
is_expected
.
to
eq
({
time_now
.
beginning_of_day
=>
3
,
time_ago
.
beginning_of_day
=>
2
})
}
end
end
end
spec/services/product_analytics/build_activity_graph_service_spec.rb
0 → 100644
View file @
6bd773a8
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
ProductAnalytics
::
BuildActivityGraphService
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:time_now
)
{
Time
.
zone
.
now
}
let_it_be
(
:time_ago
)
{
Time
.
zone
.
now
-
5
.
days
}
let_it_be
(
:events
)
do
[
create
(
:product_analytics_event
,
project:
project
,
collector_tstamp:
time_now
),
create
(
:product_analytics_event
,
project:
project
,
collector_tstamp:
time_now
),
create
(
:product_analytics_event
,
project:
project
,
collector_tstamp:
time_now
),
create
(
:product_analytics_event
,
project:
project
,
collector_tstamp:
time_ago
),
create
(
:product_analytics_event
,
project:
project
,
collector_tstamp:
time_ago
)
]
end
let
(
:params
)
{
{
timerange:
7
}
}
subject
{
described_class
.
new
(
project
,
params
).
execute
}
it
'returns a valid graph hash'
do
expected_hash
=
{
id:
'collector_tstamp'
,
keys:
[
time_ago
.
to_date
,
time_now
.
to_date
],
values:
[
2
,
3
]
}
expect
(
subject
).
to
eq
(
expected_hash
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment