Loading Controllers/api/v2/analytics.php +10 −10 Original line number Original line Diff line number Diff line Loading @@ -18,25 +18,25 @@ class analytics implements Interfaces\Api, Interfaces\ApiIgnorePam ]); ]); } } $span = 12; $span = 13; $unit = 'month'; $unit = 'month'; switch ($_GET['timespan'] ?? null) { switch ($_GET['timespan'] ?? null) { case 'hourly': case 'hourly': $span = 24; $span = 25; $unit = 'hour'; $unit = 'hour'; break; break; case 'daily': case 'daily': $span = 7; $span = 17; $unit = 'day'; $unit = 'day'; break; break; case 'monthly': case 'monthly': $span = 12; $span = 13; $unit = 'month'; $unit = 'month'; break; break; } } /** @var Core\Analytics\Metrics\Manager $manager */ /** @var Core\Analytics\Graphs\Manager $manager */ $manager = Di::_()->get('Analytics\Graphs\Manager'); $manager = Di::_()->get('Analytics\Graphs\Manager'); try { try { Loading Core/Analytics/Graphs/Aggregates/ActiveUsers.php +60 −18 Original line number Original line Diff line number Diff line Loading @@ -3,11 +3,11 @@ namespace Minds\Core\Analytics\Graphs\Aggregates; namespace Minds\Core\Analytics\Graphs\Aggregates; use DateTime; use DateTime; use Minds\Core\Analytics\Graphs\Manager; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\ElasticSearch; use Minds\Core\Data\ElasticSearch; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\Analytics\Graphs\Manager; class ActiveUsers implements AggregateInterface class ActiveUsers implements AggregateInterface { { Loading Loading @@ -39,14 +39,36 @@ class ActiveUsers implements AggregateInterface { { $result = []; $result = []; foreach (['hour', 'day', 'month'] as $unit) { foreach (['hour', 'day', 'month'] as $unit) { switch ($unit) { case 'hour': $span = 25; break; case 'day': $span = 17; break; case 'month': $span = 13; break; } $k = Manager::buildKey([ $k = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'activeusers', 'aggregate' => $opts['aggregate'] ?? 'activeusers', 'key' => null, 'key' => null, 'unit' => $unit, 'unit' => $unit, 'span' => $span ]); ]); $result[$k] = $this->fetch([ $result[$k] = $this->fetch([ 'unit' => $unit, 'unit' => $unit, 'span' => $span, ]); ]); $avgKey = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'activeusers', 'key' => 'avg', 'unit' => $unit, 'span' => $span ]); $result[$avgKey] = Manager::calculateAverages($result[$k]); } } return $result; return $result; } } Loading @@ -54,7 +76,7 @@ class ActiveUsers implements AggregateInterface public function fetch(array $options = []) public function fetch(array $options = []) { { $options = array_merge([ $options = array_merge([ 'span' => 12, 'span' => 13, 'unit' => 'month', // day / month 'unit' => 'month', // day / month 'userGuid' => null, 'userGuid' => null, ], $options); ], $options); Loading @@ -64,21 +86,29 @@ class ActiveUsers implements AggregateInterface $from = null; $from = null; switch ($options['unit']) { switch ($options['unit']) { case "hour": case "hour": $from = (new DateTime('midnight'))->modify("-{$options['span']} hours"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} hours"); $this->dateFormat = 'y-m-d H:i'; $this->dateFormat = 'y-m-d H:i'; return $this->getHourlyPageviews($from, $to, $user_guid); return $this->getHourlyPageviews($from, $to, $user_guid); case "day": case "day": $from = (new DateTime('midnight'))->modify("-{$options['span']} days"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime('midnight')) ->modify("-{$options['span']} days"); $this->dateFormat = 'y-m-d'; $this->dateFormat = 'y-m-d'; return $this->getDailyPageviews($from, $to, $user_guid); return $this->getDailyPageviews($from, $to, $user_guid); break; break; case "month": case "month": $from = (new DateTime('midnight first day of next month'))->modify("-{$options['span']} months"); $to = new DateTime('midnight first day of next month'); $to = new DateTime('midnight first day of next month'); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} months"); $this->dateFormat = 'y-m'; $this->dateFormat = 'y-m'; return $this->getMonthlyPageviews($from, $to, $user_guid); return $this->getMonthlyPageviews($from, $to, $user_guid); Loading Loading @@ -159,12 +189,14 @@ class ActiveUsers implements AggregateInterface $response = [ $response = [ [ [ 'name' => 'HAU (Logged In)', 'key' => 'loggedInHAU', 'name' => 'Hourly Active Users', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'HAU (Unique)', 'key' => 'uniqueHAU', 'name' => 'Hourly Unique Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ] ] Loading Loading @@ -254,18 +286,19 @@ class ActiveUsers implements AggregateInterface $response = [ $response = [ [ [ 'name' => 'DAU (Logged In)', 'key' => 'loggedInDAU', 'name' => 'Daily Active Users', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'DAU (Unique)', 'key' => 'uniqueDAU', 'name' => 'Daily Unique Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ] ] ]; ]; foreach ($result['aggregations']['histogram']['buckets'] as $count) { foreach ($result['aggregations']['histogram']['buckets'] as $count) { $date = date($this->dateFormat, $count['key'] / 1000); $date = date($this->dateFormat, $count['key'] / 1000); Loading @@ -291,6 +324,13 @@ class ActiveUsers implements AggregateInterface ] ] ] ] ], ], [ "match_phrase" => [ "platform.keyword" => [ "query" => "browser" ] ] ] ]; ]; // filter by user_guid // filter by user_guid Loading Loading @@ -359,22 +399,24 @@ class ActiveUsers implements AggregateInterface $response = [ $response = [ [ [ 'name' => 'MAU', 'key' => 'loggedInMAU', 'name' => 'Monthly Active Users', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'Visitors', 'key' => 'uniqueMAU', 'name' => 'Monthly Active Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'Avg. DAU', 'name' => 'Avg. Daily Unique Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'DAU', 'name' => 'Daily Unique Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ] ] Loading Core/Analytics/Graphs/Aggregates/AvgPageviews.php +23 −36 Original line number Original line Diff line number Diff line Loading @@ -3,11 +3,11 @@ namespace Minds\Core\Analytics\Graphs\Aggregates; namespace Minds\Core\Analytics\Graphs\Aggregates; use DateTime; use DateTime; use Minds\Core\Analytics\Graphs\Manager; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\ElasticSearch; use Minds\Core\Data\ElasticSearch; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\Analytics\Graphs\Manager; class AvgPageviews implements AggregateInterface class AvgPageviews implements AggregateInterface { { Loading @@ -34,23 +34,27 @@ class AvgPageviews implements AggregateInterface { { $result = []; $result = []; foreach ([ foreach ([ 'mau_unique', 'mau_loggedin', 'dau_loggedin', 'dau_unique', 'total_pageviews', 'total_pageviews', 'hau_unique', 'hau_loggedin', ] as $key) { ] as $key) { foreach ([ 'day', 'month' ] as $unit) { foreach ([/*'day',*/ 'month'] as $unit) { switch ($unit) { case 'day': $span = 17; break; case 'month': $span = 13; break; } $k = Manager::buildKey([ $k = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'avgpageviews', 'aggregate' => $opts['aggregate'] ?? 'avgpageviews', 'key' => $key, 'key' => $key, 'unit' => $unit, 'unit' => $unit, 'span' => $span, ]); ]); $result[$k] = $this->fetch([ $result[$k] = $this->fetch([ 'key' => $key, 'key' => $key, 'unit' => $unit 'unit' => $unit, 'span' => $span, ]); ]); } } } } Loading @@ -60,7 +64,7 @@ class AvgPageviews implements AggregateInterface public function fetch(array $options = []) public function fetch(array $options = []) { { $options = array_merge([ $options = array_merge([ 'span' => 12, 'span' => 13, 'unit' => 'month', // day / month 'unit' => 'month', // day / month 'key' => null, 'key' => null, ], $options); ], $options); Loading @@ -74,14 +78,15 @@ class AvgPageviews implements AggregateInterface $from = null; $from = null; switch ($options['unit']) { switch ($options['unit']) { case "day": case "day": $from = (new DateTime('midnight'))->modify("-{$options['span']} days"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime('midnight')) $interval = '1d'; ->modify("-{$options['span']} days"); break; break; case "month": case "month": $from = (new DateTime('midnight first day of next month'))->modify("-{$options['span']} months"); $to = new DateTime('midnight first day of next month'); $to = new DateTime('midnight first day of next month'); $interval = '1M'; $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} months"); break; break; default: default: throw new \Exception("{$options['unit']} is not an accepted unit"); throw new \Exception("{$options['unit']} is not an accepted unit"); Loading @@ -89,27 +94,9 @@ class AvgPageviews implements AggregateInterface $response = null; $response = null; switch ($key) { switch ($key) { case 'mau_unique': $response = $this->getMauUnique($from, $to, $interval); break; case 'mau_loggedin': $response = $this->getMauLoggedIn($from, $to, $interval); break; case 'dau_loggedin': $response = $this->getDauLoggedIn($from, $to); break; case 'dau_unique': $response = $this->getDauUnique($from, $to); break; case 'total_pageviews': case 'total_pageviews': $response = $this->getTotalPageviews($from, $to); $response = $this->getTotalPageviews($from, $to); break; break; case 'hau_unique': $response = $this->getHauUnique($from, $to); break; case 'hau_loggedin': $response = $this->getHauLoggedIn($from, $to); break; } } return $response; return $response; Loading Core/Analytics/Graphs/Aggregates/Comments.php +42 −10 Original line number Original line Diff line number Diff line Loading @@ -7,11 +7,11 @@ namespace Minds\Core\Analytics\Graphs\Aggregates; namespace Minds\Core\Analytics\Graphs\Aggregates; use DateTime; use DateTime; use Minds\Core\Analytics\Graphs\Manager; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Prepared\Search; use Minds\Core\Data\ElasticSearch\Prepared\Search; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\Analytics\Graphs\Manager; class Comments implements AggregateInterface class Comments implements AggregateInterface { { Loading Loading @@ -43,14 +43,36 @@ class Comments implements AggregateInterface { { $result = []; $result = []; foreach (['hour', 'day', 'month'] as $unit) { foreach (['hour', 'day', 'month'] as $unit) { switch ($unit) { case 'hour': $span = 25; break; case 'day': $span = 17; break; case 'month': $span = 13; break; } $k = Manager::buildKey([ $k = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'comments', 'aggregate' => $opts['aggregate'] ?? 'comments', 'key' => null, 'key' => null, 'unit' => $unit, 'unit' => $unit, 'span' => $span, ]); ]); $result[$k] = $this->fetch([ $result[$k] = $this->fetch([ 'unit' => $unit, 'unit' => $unit, 'span' => $span, ]); $avgKey = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'comments', 'key' => 'avg', 'unit' => $unit, 'span' => $span, ]); ]); $result[$avgKey] = Manager::calculateAverages($result[$k]); } } return $result; return $result; } } Loading @@ -58,7 +80,7 @@ class Comments implements AggregateInterface public function fetch(array $options = []) public function fetch(array $options = []) { { $options = array_merge([ $options = array_merge([ 'span' => 12, 'span' => 13, 'unit' => 'month', // day / month 'unit' => 'month', // day / month 'userGuid' => null, 'userGuid' => null, ], $options); ], $options); Loading @@ -68,20 +90,28 @@ class Comments implements AggregateInterface $from = null; $from = null; switch ($options['unit']) { switch ($options['unit']) { case "hour": case "hour": $from = (new DateTime('midnight'))->modify("-{$options['span']} hours"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} hours"); $interval = '1h'; $interval = '1h'; $this->dateFormat = 'y-m-d H:i'; $this->dateFormat = 'y-m-d H:i'; break; break; case "day": case "day": $from = (new DateTime('midnight'))->modify("-{$options['span']} days"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime('midnight')) ->modify("-{$options['span']} days"); $interval = '1d'; $interval = '1d'; $this->dateFormat = 'y-m-d'; $this->dateFormat = 'y-m-d'; break; break; case "month": case "month": $from = (new DateTime('midnight first day of next month'))->modify("-{$options['span']} months"); $to = new DateTime('midnight first day of next month'); $to = new DateTime('midnight first day of next month'); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} months"); $interval = '1M'; $interval = '1M'; $this->dateFormat = 'y-m'; $this->dateFormat = 'y-m'; break; break; Loading Loading @@ -165,6 +195,7 @@ class Comments implements AggregateInterface $response = [ $response = [ [ [ 'key' => 'comments', 'name' => 'Comments', 'name' => 'Comments', 'x' => [], 'x' => [], 'y' => [] 'y' => [] Loading @@ -172,7 +203,8 @@ class Comments implements AggregateInterface ]; ]; if (!$userGuid) { if (!$userGuid) { $response[] = [ $response[] = [ 'name' => 'Number of Commenting Users', 'key' => 'commentingUsers', 'name' => 'Commenting Users', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ]; ]; Loading Core/Analytics/Graphs/Aggregates/Interactions.php +9 −4 Original line number Original line Diff line number Diff line Loading @@ -8,7 +8,6 @@ use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Prepared\Count; use Minds\Core\Data\ElasticSearch\Prepared\Count; use Minds\Core\Data\ElasticSearch\Prepared\Search; use Minds\Core\Data\ElasticSearch\Prepared\Search; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\Analytics\Graphs\Manager; class Interactions implements AggregateInterface class Interactions implements AggregateInterface { { Loading Loading @@ -55,14 +54,20 @@ class Interactions implements AggregateInterface $from = null; $from = null; switch ($options['unit']) { switch ($options['unit']) { case "day": case "day": $from = (new DateTime('midnight'))->modify("-{$options['span']} days"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} hours"); $interval = '1d'; $interval = '1d'; $this->dateFormat = 'y-m-d'; $this->dateFormat = 'y-m-d'; break; break; case "month": case "month": $from = (new DateTime('midnight first day of next month'))->modify("-{$options['span']} months"); $to = new DateTime('midnight first day of next month'); $to = new DateTime('midnight first day of next month'); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} months"); $interval = '1M'; $interval = '1M'; $this->dateFormat = 'y-m'; $this->dateFormat = 'y-m'; break; break; Loading Loading
Controllers/api/v2/analytics.php +10 −10 Original line number Original line Diff line number Diff line Loading @@ -18,25 +18,25 @@ class analytics implements Interfaces\Api, Interfaces\ApiIgnorePam ]); ]); } } $span = 12; $span = 13; $unit = 'month'; $unit = 'month'; switch ($_GET['timespan'] ?? null) { switch ($_GET['timespan'] ?? null) { case 'hourly': case 'hourly': $span = 24; $span = 25; $unit = 'hour'; $unit = 'hour'; break; break; case 'daily': case 'daily': $span = 7; $span = 17; $unit = 'day'; $unit = 'day'; break; break; case 'monthly': case 'monthly': $span = 12; $span = 13; $unit = 'month'; $unit = 'month'; break; break; } } /** @var Core\Analytics\Metrics\Manager $manager */ /** @var Core\Analytics\Graphs\Manager $manager */ $manager = Di::_()->get('Analytics\Graphs\Manager'); $manager = Di::_()->get('Analytics\Graphs\Manager'); try { try { Loading
Core/Analytics/Graphs/Aggregates/ActiveUsers.php +60 −18 Original line number Original line Diff line number Diff line Loading @@ -3,11 +3,11 @@ namespace Minds\Core\Analytics\Graphs\Aggregates; namespace Minds\Core\Analytics\Graphs\Aggregates; use DateTime; use DateTime; use Minds\Core\Analytics\Graphs\Manager; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\ElasticSearch; use Minds\Core\Data\ElasticSearch; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\Analytics\Graphs\Manager; class ActiveUsers implements AggregateInterface class ActiveUsers implements AggregateInterface { { Loading Loading @@ -39,14 +39,36 @@ class ActiveUsers implements AggregateInterface { { $result = []; $result = []; foreach (['hour', 'day', 'month'] as $unit) { foreach (['hour', 'day', 'month'] as $unit) { switch ($unit) { case 'hour': $span = 25; break; case 'day': $span = 17; break; case 'month': $span = 13; break; } $k = Manager::buildKey([ $k = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'activeusers', 'aggregate' => $opts['aggregate'] ?? 'activeusers', 'key' => null, 'key' => null, 'unit' => $unit, 'unit' => $unit, 'span' => $span ]); ]); $result[$k] = $this->fetch([ $result[$k] = $this->fetch([ 'unit' => $unit, 'unit' => $unit, 'span' => $span, ]); ]); $avgKey = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'activeusers', 'key' => 'avg', 'unit' => $unit, 'span' => $span ]); $result[$avgKey] = Manager::calculateAverages($result[$k]); } } return $result; return $result; } } Loading @@ -54,7 +76,7 @@ class ActiveUsers implements AggregateInterface public function fetch(array $options = []) public function fetch(array $options = []) { { $options = array_merge([ $options = array_merge([ 'span' => 12, 'span' => 13, 'unit' => 'month', // day / month 'unit' => 'month', // day / month 'userGuid' => null, 'userGuid' => null, ], $options); ], $options); Loading @@ -64,21 +86,29 @@ class ActiveUsers implements AggregateInterface $from = null; $from = null; switch ($options['unit']) { switch ($options['unit']) { case "hour": case "hour": $from = (new DateTime('midnight'))->modify("-{$options['span']} hours"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} hours"); $this->dateFormat = 'y-m-d H:i'; $this->dateFormat = 'y-m-d H:i'; return $this->getHourlyPageviews($from, $to, $user_guid); return $this->getHourlyPageviews($from, $to, $user_guid); case "day": case "day": $from = (new DateTime('midnight'))->modify("-{$options['span']} days"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime('midnight')) ->modify("-{$options['span']} days"); $this->dateFormat = 'y-m-d'; $this->dateFormat = 'y-m-d'; return $this->getDailyPageviews($from, $to, $user_guid); return $this->getDailyPageviews($from, $to, $user_guid); break; break; case "month": case "month": $from = (new DateTime('midnight first day of next month'))->modify("-{$options['span']} months"); $to = new DateTime('midnight first day of next month'); $to = new DateTime('midnight first day of next month'); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} months"); $this->dateFormat = 'y-m'; $this->dateFormat = 'y-m'; return $this->getMonthlyPageviews($from, $to, $user_guid); return $this->getMonthlyPageviews($from, $to, $user_guid); Loading Loading @@ -159,12 +189,14 @@ class ActiveUsers implements AggregateInterface $response = [ $response = [ [ [ 'name' => 'HAU (Logged In)', 'key' => 'loggedInHAU', 'name' => 'Hourly Active Users', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'HAU (Unique)', 'key' => 'uniqueHAU', 'name' => 'Hourly Unique Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ] ] Loading Loading @@ -254,18 +286,19 @@ class ActiveUsers implements AggregateInterface $response = [ $response = [ [ [ 'name' => 'DAU (Logged In)', 'key' => 'loggedInDAU', 'name' => 'Daily Active Users', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'DAU (Unique)', 'key' => 'uniqueDAU', 'name' => 'Daily Unique Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ] ] ]; ]; foreach ($result['aggregations']['histogram']['buckets'] as $count) { foreach ($result['aggregations']['histogram']['buckets'] as $count) { $date = date($this->dateFormat, $count['key'] / 1000); $date = date($this->dateFormat, $count['key'] / 1000); Loading @@ -291,6 +324,13 @@ class ActiveUsers implements AggregateInterface ] ] ] ] ], ], [ "match_phrase" => [ "platform.keyword" => [ "query" => "browser" ] ] ] ]; ]; // filter by user_guid // filter by user_guid Loading Loading @@ -359,22 +399,24 @@ class ActiveUsers implements AggregateInterface $response = [ $response = [ [ [ 'name' => 'MAU', 'key' => 'loggedInMAU', 'name' => 'Monthly Active Users', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'Visitors', 'key' => 'uniqueMAU', 'name' => 'Monthly Active Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'Avg. DAU', 'name' => 'Avg. Daily Unique Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ], ], [ [ 'name' => 'DAU', 'name' => 'Daily Unique Visits', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ] ] Loading
Core/Analytics/Graphs/Aggregates/AvgPageviews.php +23 −36 Original line number Original line Diff line number Diff line Loading @@ -3,11 +3,11 @@ namespace Minds\Core\Analytics\Graphs\Aggregates; namespace Minds\Core\Analytics\Graphs\Aggregates; use DateTime; use DateTime; use Minds\Core\Analytics\Graphs\Manager; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\ElasticSearch; use Minds\Core\Data\ElasticSearch; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\Analytics\Graphs\Manager; class AvgPageviews implements AggregateInterface class AvgPageviews implements AggregateInterface { { Loading @@ -34,23 +34,27 @@ class AvgPageviews implements AggregateInterface { { $result = []; $result = []; foreach ([ foreach ([ 'mau_unique', 'mau_loggedin', 'dau_loggedin', 'dau_unique', 'total_pageviews', 'total_pageviews', 'hau_unique', 'hau_loggedin', ] as $key) { ] as $key) { foreach ([ 'day', 'month' ] as $unit) { foreach ([/*'day',*/ 'month'] as $unit) { switch ($unit) { case 'day': $span = 17; break; case 'month': $span = 13; break; } $k = Manager::buildKey([ $k = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'avgpageviews', 'aggregate' => $opts['aggregate'] ?? 'avgpageviews', 'key' => $key, 'key' => $key, 'unit' => $unit, 'unit' => $unit, 'span' => $span, ]); ]); $result[$k] = $this->fetch([ $result[$k] = $this->fetch([ 'key' => $key, 'key' => $key, 'unit' => $unit 'unit' => $unit, 'span' => $span, ]); ]); } } } } Loading @@ -60,7 +64,7 @@ class AvgPageviews implements AggregateInterface public function fetch(array $options = []) public function fetch(array $options = []) { { $options = array_merge([ $options = array_merge([ 'span' => 12, 'span' => 13, 'unit' => 'month', // day / month 'unit' => 'month', // day / month 'key' => null, 'key' => null, ], $options); ], $options); Loading @@ -74,14 +78,15 @@ class AvgPageviews implements AggregateInterface $from = null; $from = null; switch ($options['unit']) { switch ($options['unit']) { case "day": case "day": $from = (new DateTime('midnight'))->modify("-{$options['span']} days"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime('midnight')) $interval = '1d'; ->modify("-{$options['span']} days"); break; break; case "month": case "month": $from = (new DateTime('midnight first day of next month'))->modify("-{$options['span']} months"); $to = new DateTime('midnight first day of next month'); $to = new DateTime('midnight first day of next month'); $interval = '1M'; $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} months"); break; break; default: default: throw new \Exception("{$options['unit']} is not an accepted unit"); throw new \Exception("{$options['unit']} is not an accepted unit"); Loading @@ -89,27 +94,9 @@ class AvgPageviews implements AggregateInterface $response = null; $response = null; switch ($key) { switch ($key) { case 'mau_unique': $response = $this->getMauUnique($from, $to, $interval); break; case 'mau_loggedin': $response = $this->getMauLoggedIn($from, $to, $interval); break; case 'dau_loggedin': $response = $this->getDauLoggedIn($from, $to); break; case 'dau_unique': $response = $this->getDauUnique($from, $to); break; case 'total_pageviews': case 'total_pageviews': $response = $this->getTotalPageviews($from, $to); $response = $this->getTotalPageviews($from, $to); break; break; case 'hau_unique': $response = $this->getHauUnique($from, $to); break; case 'hau_loggedin': $response = $this->getHauLoggedIn($from, $to); break; } } return $response; return $response; Loading
Core/Analytics/Graphs/Aggregates/Comments.php +42 −10 Original line number Original line Diff line number Diff line Loading @@ -7,11 +7,11 @@ namespace Minds\Core\Analytics\Graphs\Aggregates; namespace Minds\Core\Analytics\Graphs\Aggregates; use DateTime; use DateTime; use Minds\Core\Analytics\Graphs\Manager; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Prepared\Search; use Minds\Core\Data\ElasticSearch\Prepared\Search; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\Analytics\Graphs\Manager; class Comments implements AggregateInterface class Comments implements AggregateInterface { { Loading Loading @@ -43,14 +43,36 @@ class Comments implements AggregateInterface { { $result = []; $result = []; foreach (['hour', 'day', 'month'] as $unit) { foreach (['hour', 'day', 'month'] as $unit) { switch ($unit) { case 'hour': $span = 25; break; case 'day': $span = 17; break; case 'month': $span = 13; break; } $k = Manager::buildKey([ $k = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'comments', 'aggregate' => $opts['aggregate'] ?? 'comments', 'key' => null, 'key' => null, 'unit' => $unit, 'unit' => $unit, 'span' => $span, ]); ]); $result[$k] = $this->fetch([ $result[$k] = $this->fetch([ 'unit' => $unit, 'unit' => $unit, 'span' => $span, ]); $avgKey = Manager::buildKey([ 'aggregate' => $opts['aggregate'] ?? 'comments', 'key' => 'avg', 'unit' => $unit, 'span' => $span, ]); ]); $result[$avgKey] = Manager::calculateAverages($result[$k]); } } return $result; return $result; } } Loading @@ -58,7 +80,7 @@ class Comments implements AggregateInterface public function fetch(array $options = []) public function fetch(array $options = []) { { $options = array_merge([ $options = array_merge([ 'span' => 12, 'span' => 13, 'unit' => 'month', // day / month 'unit' => 'month', // day / month 'userGuid' => null, 'userGuid' => null, ], $options); ], $options); Loading @@ -68,20 +90,28 @@ class Comments implements AggregateInterface $from = null; $from = null; switch ($options['unit']) { switch ($options['unit']) { case "hour": case "hour": $from = (new DateTime('midnight'))->modify("-{$options['span']} hours"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} hours"); $interval = '1h'; $interval = '1h'; $this->dateFormat = 'y-m-d H:i'; $this->dateFormat = 'y-m-d H:i'; break; break; case "day": case "day": $from = (new DateTime('midnight'))->modify("-{$options['span']} days"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime('midnight')) ->modify("-{$options['span']} days"); $interval = '1d'; $interval = '1d'; $this->dateFormat = 'y-m-d'; $this->dateFormat = 'y-m-d'; break; break; case "month": case "month": $from = (new DateTime('midnight first day of next month'))->modify("-{$options['span']} months"); $to = new DateTime('midnight first day of next month'); $to = new DateTime('midnight first day of next month'); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} months"); $interval = '1M'; $interval = '1M'; $this->dateFormat = 'y-m'; $this->dateFormat = 'y-m'; break; break; Loading Loading @@ -165,6 +195,7 @@ class Comments implements AggregateInterface $response = [ $response = [ [ [ 'key' => 'comments', 'name' => 'Comments', 'name' => 'Comments', 'x' => [], 'x' => [], 'y' => [] 'y' => [] Loading @@ -172,7 +203,8 @@ class Comments implements AggregateInterface ]; ]; if (!$userGuid) { if (!$userGuid) { $response[] = [ $response[] = [ 'name' => 'Number of Commenting Users', 'key' => 'commentingUsers', 'name' => 'Commenting Users', 'x' => [], 'x' => [], 'y' => [] 'y' => [] ]; ]; Loading
Core/Analytics/Graphs/Aggregates/Interactions.php +9 −4 Original line number Original line Diff line number Diff line Loading @@ -8,7 +8,6 @@ use Minds\Core\Data\ElasticSearch\Client; use Minds\Core\Data\ElasticSearch\Prepared\Count; use Minds\Core\Data\ElasticSearch\Prepared\Count; use Minds\Core\Data\ElasticSearch\Prepared\Search; use Minds\Core\Data\ElasticSearch\Prepared\Search; use Minds\Core\Di\Di; use Minds\Core\Di\Di; use Minds\Core\Analytics\Graphs\Manager; class Interactions implements AggregateInterface class Interactions implements AggregateInterface { { Loading Loading @@ -55,14 +54,20 @@ class Interactions implements AggregateInterface $from = null; $from = null; switch ($options['unit']) { switch ($options['unit']) { case "day": case "day": $from = (new DateTime('midnight'))->modify("-{$options['span']} days"); $to = new DateTime('now'); $to = (new DateTime('midnight')); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} hours"); $interval = '1d'; $interval = '1d'; $this->dateFormat = 'y-m-d'; $this->dateFormat = 'y-m-d'; break; break; case "month": case "month": $from = (new DateTime('midnight first day of next month'))->modify("-{$options['span']} months"); $to = new DateTime('midnight first day of next month'); $to = new DateTime('midnight first day of next month'); $from = (new DateTime()) ->setTimestamp($to->getTimestamp()) ->modify("-{$options['span']} months"); $interval = '1M'; $interval = '1M'; $this->dateFormat = 'y-m'; $this->dateFormat = 'y-m'; break; break; Loading