Telegram bot users statistics in /stats response.

This commit is contained in:
Alexey Skobkin 2017-01-07 21:53:31 +03:00
parent 88be9e99ae
commit 1372b7e6d1
3 changed files with 75 additions and 1 deletions

View File

@ -2,10 +2,73 @@
namespace Skobkin\Bundle\PointToolsBundle\Repository\Telegram;
use Doctrine\ORM\EntityRepository;
class AccountRepository extends EntityRepository
{
/**
* @todo remove if not used
*
* @param array $criteria
* @param array|null $orderBy
* @param int|null $limit
* @param int|null $offset
*
* @return array
*/
public function findLinkedAccountsBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
{
$qb = $this->createQueryBuilder('a');
$i = 0;
foreach ($criteria as $property => $value) {
$qb
->andWhere('a.'.$property.' = :criteria_'.$i)
->setParameter('criteria_'.$i, $value)
;
}
if (null !== $orderBy) {
foreach ($orderBy as $property => $order) {
$qb->addOrderBy($property, $order);
}
}
if (null !== $limit) {
$qb->setMaxResults($limit);
}
if (null !== $offset) {
$qb->setFirstResult($offset);
}
return $qb->getQuery()->getResult();
}
/**
* Returns total number of accounts
*
* @return int
*/
public function getAccountsCount(): int
{
return $this->createQueryBuilder('a')
->select('COUNT(a)')
->getQuery()->getSingleScalarResult()
;
}
/**
* Returns number of accounts with linked Point.im profile
*
* @return int
*/
public function getLinkedAccountsCount(): int
{
return $this->createQueryBuilder('a')
->select('COUNT(a)')
->where('a.user IS NOT NULL')
->getQuery()->getSingleScalarResult()
;
}
}

View File

@ -2,6 +2,8 @@
Total users: {{ total_users }}
Active users: {{ active_users }}
Telegram users: {{ telegram_accounts }}
Telegram linked users: {{ telegram_linked_accounts }}
24 hours events: {{ today_events }}
Visit [Point Tools](https://point.skobk.in/) for more info.

View File

@ -8,6 +8,7 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Skobkin\Bundle\PointToolsBundle\Exception\Telegram\CommandProcessingException;
use Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository;
use Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionRepository;
use Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository;
use Skobkin\Bundle\PointToolsBundle\Repository\UserRepository;
use Skobkin\Bundle\PointToolsBundle\Service\Factory\Telegram\AccountFactory;
use Skobkin\Bundle\PointToolsBundle\Service\UserApi;
@ -45,6 +46,11 @@ class PrivateMessageProcessor
*/
private $userRepo;
/**
* @var AccountRepository
*/
private $accountRepo;
/**
* @var SubscriptionRepository
*/
@ -70,6 +76,7 @@ class PrivateMessageProcessor
$this->pointUserId = $pointUserId;
$this->userRepo = $em->getRepository('SkobkinPointToolsBundle:User');
$this->accountRepo = $em->getRepository('SkobkinPointToolsBundle:Telegram\Account');
$this->subscriptionRepo = $em->getRepository('SkobkinPointToolsBundle:Subscription');
$this->subscriptionEventRepo = $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent');
}
@ -336,6 +343,8 @@ class PrivateMessageProcessor
[
'total_users' => $this->userRepo->getUsersCount(),
'active_users' => $this->subscriptionRepo->getUserSubscribersCountById($this->pointUserId),
'telegram_accounts' => $this->accountRepo->getAccountsCount(),
'telegram_linked_accounts' => $this->accountRepo->getLinkedAccountsCount(),
'today_events' => $this->subscriptionEventRepo->getLastDayEventsCount(),
]
);