Commit 9dc49442 authored by Mark Harding's avatar Mark Harding

(feat): improved stats

1 merge request!100Epic/reporting and moderation
Pipeline #62660983 passed with stages
in 4 minutes and 14 seconds
<?php
namespace Minds\Core\Reports\Stats\Aggregates;
use Minds\Core\Di\Di;
use Minds\Core\Data\Cassandra\Prepared;
use Cassandra\Timestamp;
class TotalActionedAggregate implements ModerationStatsAggregateInterface
{
/** @var Client $cql */
private $cql;
public function __construct($cql = null)
{
$this->cql = $cql ?: Di::_()->get('Database\Cassandra\Cql');
}
/**
* @return init
*/
public function get(): int
{
$statement = "SELECT count(*) as total FROM moderation_reports_by_state
WHERE state IN ('initial_jury_decided', 'appealed')
AND timestamp > ?
AND uphold = true
ALLOW FILTERING
";
$values = [ new Timestamp(strtotime('-30 days', time())) ];
$prepared = new Prepared\Custom();
$prepared->query($statement, $values);
$result = $this->cql->request($prepared);
$initialJuryActioned = (int) $result[0]['total']->value();
$statement = "SELECT count(*) as total FROM moderation_reports_by_state
WHERE state = 'appeal_jury_decided'
AND timestamp > ?";
$values = [ new Timestamp(strtotime('-30 days', time())) ];
$prepared = new Prepared\Custom();
$prepared->query($statement, $values);
$result = $this->cql->request($prepared);
$appealJuryTotal = (int) $result[0]['total']->value();
return $initialJuryActioned + $appealJuryTotal;
}
}
......@@ -23,6 +23,9 @@ class Manager
/** @var Aggregates\TotalReportsAggregate $totalReportsAggregate */
private $totalReportsAggregate;
/** @var Aggregates\TotalActionedAggregate $totalActionedAggregate */
private $totalActionedAggregate;
/** @var Aggregates\TotalOverturnedAggregate $totalOverturnedAggregate */
private $totalOverturnedAggregate;
......@@ -31,6 +34,7 @@ class Manager
$totalPostsAggregate = null,
$totalAppealsAggregate = null,
$totalReportsAggregate = null,
$totalActionedAggregate = null,
$totalOverturnedAggregate = null
)
{
......@@ -38,6 +42,7 @@ class Manager
$this->totalPostsAggregate = $totalPostsAggregate ?: new Aggregates\TotalPostsAggregate;
$this->totalAppealsAggregate = $totalAppealsAggregate ?: new Aggregates\TotalAppealsAggregate;
$this->totalReportsAggregate = $totalReportsAggregate ?: new Aggregates\TotalReportsAggregate;
$this->totalActionedAggregate = $totalActionedAggregate ?: new Aggregates\TotalActionedAggregate;
$this->totalOverturnedAggregate = $totalOverturnedAggregate ?: new Aggregates\TotalOverturnedAggregate;
}
......@@ -48,18 +53,24 @@ class Manager
{
$postsCount = (int) $this->totalPostsAggregate->get();
$reportsCount = (int) $this->totalReportsAggregate->get();
$actionedCount = (int) $this->totalActionedAggregate->get();
$appealedCount = (int) $this->totalAppealsAggregate->get();
$overturnedCount = (int) $this->totalOverturnedAggregate->get();
$reportsPct = ($reportsCount / ($postsCount ?: 1)) * 100;
$appealedPct = ($appealedCount / ($reportsCount ?: 1)) * 100;
$actionedPct = ($actionedCount / ($reportsCount ?: 1)) * 100;
$appealedPct = ($appealedCount / ($actionedCount ?: 1)) * 100;
$upheldPct = 100 - (($overturnedCount / ($appealedCount ?: 1)) * 100);
$this->stats = [
'reportedPct' => round($reportsPct, 2),
'reported' => $reportsCount,
'actioned' => $actionedCount,
'actionedPct' => round($actionedPct, 2),
'appealedPct' => round($appealedPct, 2),
'appealed' => $appealedCount,
'upheldPct' => $upheldPct,
'overturned' => $overturnedCount,
];
return $this->stats;
}
......
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