<?php

require __DIR__ . '/common.php';
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\K131970f0a776522b1a53ba419cd5e32c;
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e;
$tmp = \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::getInstance()->select(['count(id) as `count`', '`reseller_id`'])->from('users')->where(['UNIX_TIMESTAMP(keep_alive)>' => \time() - \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\K131970f0a776522b1a53ba419cd5e32c::get('watchdog_timeout') * 2])->groupby('reseller_id')->get()->all();
$users_online = [0 => 0];
foreach ($tmp as $row) {
    if (!\array_key_exists((int) $row['reseller_id'], $users_online)) {
        $users_online[(int) $row['reseller_id']] = 0;
    }
    $users_online[(int) $row['reseller_id']] += $row['count'];
}
$users_online['total'] = \array_sum($users_online);
\Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::getInstance()->insert('users_activity', ['users_online' => \json_encode($users_online)]);
