Commit d66a1ef5 authored by Mark Harding's avatar Mark Harding

(feat): multiple changes to aid with frontend

1 merge request!343WIP: Analytics Dashboard
Pipeline #87882057 failed with stages
in 4 minutes and 21 seconds
......@@ -25,7 +25,7 @@ class dashboards implements Interfaces\Api, Interfaces\ApiIgnorePam
$dashboard->setTimespanId($_GET['timespan']);
}
if (isset($_GET['filters'])) {
if (isset($_GET['filter'])) {
$filterIds = explode(',', $_GET['filters']);
$dashboard->setFilterIds($filterIds);
}
......
......@@ -13,6 +13,9 @@ abstract class AbstractFilter
/** @var string */
protected $label;
/** @var string */
protected $description;
/** @var FilterOptions */
protected $options;
......@@ -45,6 +48,7 @@ abstract class AbstractFilter
return [
'id' => (string) $this->id,
'label' => (string) $this->label,
'description' => (string) $this->description,
'options' => (array) $this->options->export(),
];
}
......
<?php
namespace Minds\Core\Analytics\Dashboards\Filters;
class ChannelFilter extends AbstractFilter
{
/** @var string */
protected $id = "channel";
/** @var string */
protected $label = "Channel";
/** @var string */
protected $description = "Filter by channels or by the full site";
/** @var string */
protected $selectedOption = "all";
public function __construct()
{
$this->options = (new FilterOptions())
->setOptions(
(new FilterOptionsOption())
->setId("all")
->setLabel("All")
->setDescription("Global, site-wide metrics"),
(new FilterOptionsOption())
->setId("self")
->setLabel("Me")
->setDescription("Your currently logged in user"),
(new FilterOptionsOption())
->setId("custom")
->setLabel("Custom (Search)")
->setDescription("Search for a channel to view their metrics")
);
}
}
......@@ -16,6 +16,9 @@ class FilterOptionsOption
/** @var string */
private $label;
/** @var string */
private $description;
/** @var bool */
private $available = true;
......@@ -32,6 +35,7 @@ class FilterOptionsOption
return [
'id' => $this->id,
'label' => $this->label,
'description' => $this->description,
'available' => (bool) $this->available,
'selected' => (bool) $this->selected,
];
......
......@@ -9,19 +9,25 @@ class PlatformFilter extends AbstractFilter
/** @var string */
protected $label = "Platform";
/** @var string */
protected $description = "Filter by device types";
public function __construct()
{
$this->options = (new FilterOptions())
->setOptions(
(new FilterOptionsOption())
->setId("all")
->setLabel("All"),
->setLabel("All")
->setDescription("Browsers, Mobile and APIs"),
(new FilterOptionsOption())
->setId("browser")
->setLabel("Browser"),
->setLabel("Browser")
->setDescription("Browsers"),
(new FilterOptionsOption())
->setId("mobile")
->setLabel("Mobile")
->setDescription("Native mobile applications")
);
}
}
......@@ -9,22 +9,29 @@ class ViewTypeFilter extends AbstractFilter
/** @var string */
protected $label = "View types";
/** @var string */
protected $description = "Filter by the breakdown of views";
public function __construct()
{
$this->options = (new FilterOptions())
->setOptions(
(new FilterOptionsOption())
->setId("total")
->setLabel("Total"),
->setLabel("Total")
->setDescription("All views recorded on assets"),
(new FilterOptionsOption())
->setId("organic")
->setLabel("Organic"),
->setLabel("Organic")
->setDescription("Views on assets that excludes boosted impressions"),
(new FilterOptionsOption())
->setId("boosted")
->setLabel("Boosted"),
->setLabel("Boosted")
->setDescription("Views recorded on assets that were boosted"),
(new FilterOptionsOption())
->setId("single")
->setLabel("Single")
->setDecription("Views recorded on single pages, not in feeds")
);
}
}
......@@ -22,6 +22,12 @@ abstract class AbstractMetric
/** @var string */
protected $label;
/** @var string */
protected $description;
/** @var string */
protected $unit = 'number';
/** @var string[] */
protected $permissions;
......@@ -47,6 +53,8 @@ abstract class AbstractMetric
return [
'id' => (string) $this->id,
'label' => (string) $this->label,
'description' => (string) $this->description,
'unit' => (string) $this->unit,
'permissions' => (array) $this->permissions,
'summary' => $this->summary ? (array) $this->summary->export() : null,
'visualisation' => $this->visualisation ? (array) $this->visualisation->export() : null,
......
......@@ -13,7 +13,10 @@ class ActiveUsersMetric extends AbstractMetric
protected $id = 'active_users';
/** @var string */
protected $label = 'active users';
protected $label = 'Active Users';
/** @var string */
protected $description = 'Users who make at least one single request to Minds';
/** @var array */
protected $permissions = [ 'admin' ];
......
......@@ -13,7 +13,10 @@ class SignupsMetric extends AbstractMetric
protected $id = 'signups';
/** @var string */
protected $label = 'signups';
protected $label = 'Signups';
/** @var string */
protected $description = 'New accounts registered';
/** @var array */
protected $permissions = [ 'admin' ];
......
......@@ -2,6 +2,7 @@
namespace Minds\Core\Analytics\Dashboards\Metrics;
use Minds\Core\Di\Di;
use Minds\Core\Session;
use Minds\Core\Data\Elasticsearch;
class ViewsMetric extends AbstractMetric
......@@ -13,7 +14,10 @@ class ViewsMetric extends AbstractMetric
protected $id = 'views';
/** @var string */
protected $label = 'views';
protected $label = 'Views';
/** @var string */
protected $description = 'Views on channel assets';
/** @var array */
protected $permissions = [ 'admin' ];
......@@ -59,6 +63,14 @@ class ViewsMetric extends AbstractMetric
],
];
if ($userGuid = $this->getUserGuid()) {
$must[] = [
'term' => [
'owner_guid' => $userGuid,
],
];
}
$query = [
'index' => 'minds-entitycentric-*',
'size' => 0,
......@@ -128,6 +140,14 @@ class ViewsMetric extends AbstractMetric
],
];
if ($userGuid = $this->getUserGuid()) {
$must[] = [
'term' => [
'owner_guid' => $userGuid,
],
];
}
// Do the query
$query = [
'index' => 'minds-entitycentric-*',
......@@ -183,4 +203,24 @@ class ViewsMetric extends AbstractMetric
return $this;
}
private function getUserGuid(): ?string
{
$filters = $this->filtersCollection->getSelected();
$channelFilter = $filters['channel'];
if (!$channelFilter) {
return "";
}
if ($channelFilter->getSelectedOption() === 'self') {
return Session::getLoggedInUserGuid();
}
if ($channelFilter->getSelectedOption() === 'all') {
return "";
}
// TODO: check permissions first
return $channelFilter->getSelectedOption();
}
}
......@@ -36,7 +36,11 @@ class ChartVisualisation extends AbstractVisualisation
{
return [
'type' => $this->type,
'buckets' => (array) $this->buckets,
'segments' => [
[
'buckets' => (array) $this->buckets,
],
]
];
}
}
......@@ -64,7 +64,8 @@ class TrafficDashboard implements DashboardInterface
->setSelectedIds($this->filterIds)
->addFilters(
new Filters\PlatformFilter(),
new Filters\ViewTypeFilter()
new Filters\ViewTypeFilter(),
new Filters\ChannelFilter()
);
$this->metricsCollection
->setTimespansCollection($this->timespansCollection)
......@@ -92,7 +93,7 @@ class TrafficDashboard implements DashboardInterface
'category' => 'traffic',
'timespan' => $this->timespansCollection->getSelected()->getId(),
'timespans' => $this->timespansCollection->export(),
'metric' => $this->metricsCollection->getSelected()->export(),
'metric' => $this->metricsCollection->getSelected()->getId(),
'metrics' => $this->metricsCollection->export(),
'filter' => $this->filtersCollection->getSelectedIds(),
'filters' => $this->filtersCollection->export(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment