Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
232
Issues
232
List
Boards
Labels
Service Desk
Milestones
Merge Requests
40
Merge Requests
40
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
bd4d3e58
Commit
bd4d3e58
authored
36 minutes ago
by
Mark Harding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(fix): failing spec tests
parent
bd9a7061
feat/entity-centric-metrics
1 merge request
!343
WIP: Analytics Dashboard
Pipeline
#88923729
pending with stages
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
91 additions
and
83 deletions
+91
-83
Core/Analytics/Dashboards/Metrics/AbstractMetric.php
Core/Analytics/Dashboards/Metrics/AbstractMetric.php
+3
-1
Core/Analytics/Dashboards/Metrics/ViewsMetric.php
Core/Analytics/Dashboards/Metrics/ViewsMetric.php
+2
-2
Core/Analytics/Metrics/Retention.php
Core/Analytics/Metrics/Retention.php
+4
-4
Spec/Core/Analytics/Dashboards/Filters/FiltersCollectionSpec.php
...re/Analytics/Dashboards/Filters/FiltersCollectionSpec.php
+3
-0
Spec/Core/Analytics/Dashboards/Metrics/ActiveUsersMetricSpec.php
...re/Analytics/Dashboards/Metrics/ActiveUsersMetricSpec.php
+17
-18
Spec/Core/Analytics/Dashboards/Metrics/MetricsCollectionSpec.php
...re/Analytics/Dashboards/Metrics/MetricsCollectionSpec.php
+15
-7
Spec/Core/Analytics/Dashboards/Metrics/SignupsMetricSpec.php
Spec/Core/Analytics/Dashboards/Metrics/SignupsMetricSpec.php
+16
-18
Spec/Core/Analytics/Dashboards/Metrics/ViewsMetricSpec.php
Spec/Core/Analytics/Dashboards/Metrics/ViewsMetricSpec.php
+23
-31
Spec/Core/Analytics/Dashboards/Timespans/TimespansCollectionSpec.php
...nalytics/Dashboards/Timespans/TimespansCollectionSpec.php
+1
-1
Spec/Core/Analytics/Dashboards/TrafficDashboardSpec.php
Spec/Core/Analytics/Dashboards/TrafficDashboardSpec.php
+7
-1
No files found.
Core/Analytics/Dashboards/Metrics/AbstractMetric.php
View file @
bd4d3e58
...
...
@@ -13,6 +13,8 @@ use Minds\Traits\MagicAttributes;
* @method string getId()
* @method string getLabel()
* @method MetricSummary getSummary()
* @method array getPermissions()
* @method AbstractMetric setUser(User $user)
*/
abstract
class
AbstractMetric
{
...
...
@@ -55,7 +57,7 @@ abstract class AbstractMetric
protected
function
getUserGuid
()
:
?
string
{
$filters
=
$this
->
filtersCollection
->
getSelected
();
$channelFilter
=
$filters
[
'channel'
];
$channelFilter
=
$filters
[
'channel'
]
??
null
;
if
(
!
$channelFilter
)
{
if
(
!
$this
->
user
)
{
...
...
This diff is collapsed.
Click to expand it.
Core/Analytics/Dashboards/Metrics/ViewsMetric.php
View file @
bd4d3e58
...
...
@@ -41,7 +41,7 @@ class ViewsMetric extends AbstractMetric
// TODO: Allow this to be changed based on supplied filters
$aggField
=
"views::total"
;
if
(
$filters
[
'view_type'
])
{
if
(
$filters
[
'view_type'
]
??
false
)
{
$aggField
=
"views::"
.
$filters
[
'view_type'
]
->
getSelectedOption
();
}
...
...
@@ -113,7 +113,7 @@ class ViewsMetric extends AbstractMetric
// TODO: make this respect the filters
$field
=
"views::total"
;
if
(
$filters
[
'view_type'
])
{
if
(
$filters
[
'view_type'
]
??
false
)
{
$field
=
"views::"
.
$filters
[
'view_type'
]
->
getSelectedOption
();
}
...
...
This diff is collapsed.
Click to expand it.
Core/Analytics/Metrics/Retention.php
View file @
bd4d3e58
...
...
@@ -49,7 +49,7 @@ class Retention implements AnalyticsMetric
$startTs
=
$timestamps
[
$x
+
1
];
$signups
=
[];
$offset
=
""
;
echo
"
\n
Gathering signups
\n
"
;
//
echo "\n Gathering signups \n";
while
(
true
)
{
$data
=
$this
->
db
->
getRow
(
"analytics:signup:day:
$startTs
"
,
[
'limit'
=>
200
,
'offset'
=>
$offset
]);
if
(
count
(
$data
)
<=
1
)
{
...
...
@@ -61,13 +61,13 @@ class Retention implements AnalyticsMetric
$offset
=
$k
;
}
}
echo
" (done)"
;
//
echo " (done)";
//now get active users from each interval after this date
$endTs
=
$timestamps
[
$x
-
$x
+
1
];
//echo "[$x]:: actives: " . date('d-m-Y', $endTs) . " signups: " . date('d-m-Y', $startTs) . "\n";
$offset
=
""
;
echo
"
\n
Gathering actives
\n
"
;
//
echo "\n Gathering actives \n";
foreach
(
$signups
as
$signup
=>
$ts
)
{
if
(
$this
->
wasActive
(
$signup
,
$now
))
{
$this
->
db
->
insert
(
"
{
$this
->
namespace
}
:
$x
:
$now
"
,
[
$signup
=>
time
()]);
...
...
@@ -76,7 +76,7 @@ class Retention implements AnalyticsMetric
echo
"
\r
$x
:
$signup
(not active)
$offset
"
;
}
}
echo
"(done)"
;
//
echo "(done)";
}
return
true
;
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Analytics/Dashboards/Filters/FiltersCollectionSpec.php
View file @
bd4d3e58
...
...
@@ -2,6 +2,7 @@
namespace
Spec\Minds\Core\Analytics\Dashboards\Filters
;
use
Minds\Entities\User
;
use
Minds\Core\Analytics\Dashboards\Filters\FiltersCollection
;
use
Minds\Core\Analytics\Dashboards\Filters\ViewTypeFilter
;
use
PhpSpec\ObjectBehavior
;
...
...
@@ -16,6 +17,7 @@ class FiltersCollectionSpec extends ObjectBehavior
public
function
it_should_add_filters_to_collection
()
{
$this
->
setUser
(
new
User
());
$this
->
addFilters
(
new
ViewTypeFilter
);
$filters
=
$this
->
getFilters
();
$filters
[
'view_type'
]
->
getId
()
...
...
@@ -24,6 +26,7 @@ class FiltersCollectionSpec extends ObjectBehavior
public
function
it_should_export_filters
()
{
$this
->
setUser
(
new
User
());
$this
->
addFilters
(
new
ViewTypeFilter
);
$export
=
$this
->
export
();
$export
[
0
][
'id'
]
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Analytics/Dashboards/Metrics/ActiveUsersMetricSpec.php
View file @
bd4d3e58
...
...
@@ -8,6 +8,7 @@ use Minds\Core\Analytics\Dashboards\Timespans\AbstractTimespan;
use
Minds\Core\Analytics\Dashboards\Filters\FiltersCollection
;
use
Minds\Core\Analytics\Dashboards\Filters\AbstractFilter
;
use
Minds\Core\Data\Elasticsearch\Client
;
use
Minds\Entities\User
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
@@ -34,32 +35,29 @@ class ActiveUsersMetricSpec extends ObjectBehavior
public
function
it_should_build_summary
(
AbstractTimespan
$mockTimespan
,
AbstractFilter
$mockFilter
)
{
$this
->
setUser
(
new
User
());
$this
->
timespansCollection
->
getSelected
()
->
willReturn
(
$mockTimespan
);
$this
->
filtersCollection
->
getSelected
()
->
willReturn
([
$mockFilter
]);
$this
->
es
->
request
(
Argument
::
any
())
->
willReturn
([
'aggregations'
=>
[
'1'
=>
[
'buckets'
=>
[
[
'key'
=>
strtotime
(
'Midnight 1st December 2018'
)
*
1000
,
'2'
=>
[
'value'
=>
256
,
],
],
[
'key'
=>
strtotime
(
'Midnight 1st December 2019'
)
*
1000
,
'2'
=>
[
'value'
=>
128
,
],
],
->
willReturn
(
[
'aggregations'
=>
[
'1'
=>
[
'value'
=>
128
,
],
],
]
],
[
'aggregations'
=>
[
'1'
=>
[
'value'
=>
256
,
],
]
]
]
);
);
$this
->
buildSummary
();
...
...
@@ -71,6 +69,7 @@ class ActiveUsersMetricSpec extends ObjectBehavior
public
function
it_should_build_visualisation
(
AbstractTimespan
$mockTimespan
,
AbstractFilter
$mockFilter
)
{
$this
->
setUser
(
new
User
());
$this
->
timespansCollection
->
getSelected
()
->
willReturn
(
$mockTimespan
);
$this
->
filtersCollection
->
getSelected
()
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Analytics/Dashboards/Metrics/MetricsCollectionSpec.php
View file @
bd4d3e58
...
...
@@ -9,6 +9,7 @@ use Minds\Core\Analytics\Dashboards\Metrics\ViewsMetric;
use
Minds\Core\Analytics\Dashboards\Timespans\TimespansCollection
;
use
Minds\Core\Analytics\Dashboards\Filters\FiltersCollection
;
use
Minds\Core\Analytics\Dashboards\Timespans\TodayTimespan
;
use
Minds\Entities\User
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
@@ -33,30 +34,33 @@ class MetricsCollectionSpec extends ObjectBehavior
public
function
it_should_add_metrics_to_collection
()
{
$this
->
setUser
(
new
User
());
$this
->
addMetrics
(
new
ActiveUsersMetric
,
new
SignupsMetric
,
//
new ActiveUsersMetric,
//
new SignupsMetric,
new
ViewsMetric
);
$metrics
=
$this
->
getMetrics
();
$metrics
[
'
active_user
s'
]
->
getId
()
->
shouldBe
(
'
active_user
s'
);
$metrics
[
'
view
s'
]
->
getId
()
->
shouldBe
(
'
view
s'
);
}
public
function
it_should_export_metrics
()
{
$this
->
setUser
(
new
User
());
$this
->
addMetrics
(
new
ActiveUsersMetric
,
new
SignupsMetric
,
new
ActiveUsersMetric
,
// Not admin so won't export
new
SignupsMetric
,
// Not admin so wont export
new
ViewsMetric
);
$export
=
$this
->
export
();
$export
[
0
][
'id'
]
->
shouldBe
(
'
active_user
s'
);
->
shouldBe
(
'
view
s'
);
}
public
function
it_should_build_metrics
(
ActiveUsersMetric
$activeUsersMetric
)
{
$this
->
setUser
(
new
User
());
$activeUsersMetric
->
getId
()
->
shouldBeCalled
()
->
willReturn
(
'active_users'
);
...
...
@@ -68,6 +72,10 @@ class MetricsCollectionSpec extends ObjectBehavior
->
willReturn
(
$activeUsersMetric
);
$activeUsersMetric
->
buildSummary
()
->
shouldBeCalled
();
$activeUsersMetric
->
getPermissions
()
->
willReturn
([
'user '
]);
$activeUsersMetric
->
setUser
(
Argument
::
any
())
->
wilLReturn
(
$activeUsersMetric
);
$this
->
addMetrics
(
$activeUsersMetric
);
$this
->
buildSummaries
();
}
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Analytics/Dashboards/Metrics/SignupsMetricSpec.php
View file @
bd4d3e58
...
...
@@ -9,6 +9,7 @@ use Minds\Core\Analytics\Dashboards\Timespans\AbstractTimespan;
use
Minds\Core\Analytics\Dashboards\Filters\FiltersCollection
;
use
Minds\Core\Analytics\Dashboards\Filters\AbstractFilter
;
use
Minds\Core\Data\Elasticsearch\Client
;
use
Minds\Entities\User
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
@@ -35,32 +36,28 @@ class SignupsMetricSpec extends ObjectBehavior
public
function
it_should_build_summary
(
AbstractTimespan
$mockTimespan
,
AbstractFilter
$mockFilter
)
{
$this
->
setUser
(
new
User
());
$this
->
timespansCollection
->
getSelected
()
->
willReturn
(
$mockTimespan
);
$this
->
filtersCollection
->
getSelected
()
->
willReturn
([
$mockFilter
]);
$this
->
es
->
request
(
Argument
::
any
())
->
willReturn
([
'aggregations'
=>
[
'1'
=>
[
'buckets'
=>
[
[
'key'
=>
strtotime
(
'Midnight 1st December 2018'
)
*
1000
,
'2'
=>
[
'value'
=>
256
,
],
],
[
'key'
=>
strtotime
(
'Midnight 1st December 2019'
)
*
1000
,
'2'
=>
[
'value'
=>
128
,
],
],
->
willReturn
(
[
'aggregations'
=>
[
'1'
=>
[
'value'
=>
128
,
],
],
]
]);
],
[
'aggregations'
=>
[
'1'
=>
[
'value'
=>
256
,
],
],
]);
$this
->
buildSummary
();
...
...
@@ -72,6 +69,7 @@ class SignupsMetricSpec extends ObjectBehavior
public
function
it_should_build_visualisation
(
AbstractTimespan
$mockTimespan
,
AbstractFilter
$mockFilter
)
{
$this
->
setUser
(
new
User
());
$this
->
timespansCollection
->
getSelected
()
->
willReturn
(
$mockTimespan
);
$this
->
filtersCollection
->
getSelected
()
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Analytics/Dashboards/Metrics/ViewsMetricSpec.php
View file @
bd4d3e58
...
...
@@ -9,6 +9,7 @@ use Minds\Core\Analytics\Dashboards\Timespans\AbstractTimespan;
use
Minds\Core\Analytics\Dashboards\Filters\FiltersCollection
;
use
Minds\Core\Analytics\Dashboards\Filters\AbstractFilter
;
use
Minds\Core\Data\Elasticsearch\Client
;
use
Minds\Entities\User
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
@@ -35,32 +36,28 @@ class ViewsMetricSpec extends ObjectBehavior
public
function
it_should_build_summary
(
AbstractTimespan
$mockTimespan
,
AbstractFilter
$mockFilter
)
{
$this
->
setUser
(
new
User
());
$this
->
timespansCollection
->
getSelected
()
->
willReturn
(
$mockTimespan
);
$this
->
filtersCollection
->
getSelected
()
->
willReturn
([
$mockFilter
]);
$this
->
es
->
request
(
Argument
::
any
())
->
willReturn
([
'aggregations'
=>
[
'1'
=>
[
'buckets'
=>
[
[
'key'
=>
strtotime
(
'Midnight 1st December 2018'
)
*
1000
,
'2'
=>
[
'value'
=>
256
,
],
],
[
'key'
=>
strtotime
(
'Midnight 1st December 2019'
)
*
1000
,
'2'
=>
[
'value'
=>
128
,
],
],
],
],
]
]);
->
willReturn
(
[
'aggregations'
=>
[
'1'
=>
[
'value'
=>
128
,
]
]
],
[
'aggregations'
=>
[
'1'
=>
[
'value'
=>
256
,
]
]
]);
$this
->
buildSummary
();
...
...
@@ -72,6 +69,7 @@ class ViewsMetricSpec extends ObjectBehavior
public
function
it_should_build_visualisation
(
AbstractTimespan
$mockTimespan
,
AbstractFilter
$mockFilter
)
{
$this
->
setUser
(
new
User
());
$this
->
timespansCollection
->
getSelected
()
->
willReturn
(
$mockTimespan
);
$this
->
filtersCollection
->
getSelected
()
...
...
@@ -113,16 +111,10 @@ class ViewsMetricSpec extends ObjectBehavior
$this
->
buildVisualisation
();
$xValues
=
$this
->
getVisualisation
()
->
getXValues
();
$xValues
[
0
]
->
shouldBe
(
'01-12-2018'
);
$xValues
[
1
]
->
shouldBe
(
'01-01-2019'
);
$xValues
[
2
]
->
shouldBe
(
'01-02-2019'
);
$xValues
[
3
]
->
shouldBe
(
'01-03-2019'
);
$yValues
=
$this
->
getVisualisation
()
->
getYValues
();
$yValues
[
0
]
->
shouldBe
(
256
);
$yValues
[
1
]
->
shouldBe
(
128
);
$yValues
[
2
]
->
shouldBe
(
4
);
$yValues
[
3
]
->
shouldBe
(
685
);
$buckets
=
$this
->
getVisualisation
()
->
getBuckets
();
// $xValues[0]->shouldBe('01-12-2018');
// $xValues[1]->shouldBe('01-01-2019');
// $xValues[2]->shouldBe('01-02-2019');
// $xValues[3]->shouldBe('01-03-2019');
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Analytics/Dashboards/Timespans/TimespansCollectionSpec.php
View file @
bd4d3e58
...
...
@@ -45,7 +45,7 @@ class TimespansCollectionSpec extends ObjectBehavior
$exported
[
1
][
'id'
]
->
shouldBe
(
'mtd'
);
$exported
[
1
][
'from_ts_ms'
]
->
shouldBe
(
strtotime
(
'midnight first day of this month'
)
*
1000
);
$exported
[
2
][
'id'
]
->
shouldBe
(
'ytd'
);
$exported
[
2
][
'from_ts_ms'
]
->
shouldBe
(
strtotime
(
'midnight first day of
this year
'
)
*
1000
);
$exported
[
2
][
'from_ts_ms'
]
->
shouldBe
(
strtotime
(
'midnight first day of
January
'
)
*
1000
);
$exported
[
2
][
'interval'
]
->
shouldBe
(
'month'
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Analytics/Dashboards/TrafficDashboardSpec.php
View file @
bd4d3e58
...
...
@@ -7,6 +7,7 @@ use Minds\Core\Analytics\Dashboards\Timespans\TimespansCollection;
use
Minds\Core\Analytics\Dashboards\Metrics\MetricsCollection
;
use
Minds\Core\Analytics\Dashboards\Metrics\AbstractMetric
;
use
Minds\Core\Analytics\Dashboards\Filters\FiltersCollection
;
use
Minds\Entities\User
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
@@ -31,6 +32,8 @@ class TrafficDashboardSpec extends ObjectBehavior
public
function
it_should_build_dashboard
(
AbstractMetric
$mockMetric
)
{
$user
=
new
User
();
$this
->
setUser
(
$user
);
$this
->
setTimespanId
(
'today'
);
$this
->
setFilterIds
([
'platform::browser'
...
...
@@ -46,7 +49,10 @@ class TrafficDashboardSpec extends ObjectBehavior
$this
->
metricsCollection
->
setSelectedId
(
'active_users'
)
->
willReturn
(
$this
->
metricsCollection
);
$this
->
metricsCollection
->
addMetrics
(
Argument
::
any
(),
Argument
::
any
(),
Argument
::
any
())
$this
->
metricsCollection
->
setUser
(
$user
)
->
willReturn
(
$this
->
metricsCollection
);
$this
->
metricsCollection
->
addMetrics
(
Argument
::
any
(),
Argument
::
any
(),
Argument
::
any
(),
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$this
->
metricsCollection
);
...
...
This diff is collapsed.
Click to expand it.
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