feat(cloudron): add tirreno package artifacts
- Add CloudronStack/output/CloudronPackages-Artifacts/tirreno/ directory and its contents - Includes package manifest, Dockerfile, source code, documentation, and build artifacts - Add tirreno-1761840148.tar.gz as a build artifact - Add tirreno-cloudron-package-1761841304.tar.gz as the Cloudron package - Include all necessary files for the tirreno Cloudron package This adds the complete tirreno Cloudron package artifacts to the repository.
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
abstract class Base extends \Models\BaseSql {
|
||||
use \Traits\DateRange;
|
||||
|
||||
protected function concatDataLines(array $data1, string $field1, array $data2, string $field2, array $data3 = [], ?string $field3 = null): array {
|
||||
$data0 = [];
|
||||
$iters = count($data1);
|
||||
|
||||
for ($i = 0; $i < $iters; ++$i) {
|
||||
$item = $data1[$i];
|
||||
$ts = $item['ts'];
|
||||
|
||||
$data0[$ts] = [
|
||||
'ts' => $ts,
|
||||
$field1 => $item[$field1],
|
||||
$field2 => 0,
|
||||
];
|
||||
|
||||
if ($field3) {
|
||||
$data0[$ts][$field3] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$iters = count($data2);
|
||||
|
||||
for ($i = 0; $i < $iters; ++$i) {
|
||||
$item = $data2[$i];
|
||||
$ts = $item['ts'];
|
||||
|
||||
if (!array_key_exists($ts, $data0)) {
|
||||
$data0[$ts] = [
|
||||
'ts' => $ts,
|
||||
$field1 => 0,
|
||||
$field2 => 0,
|
||||
];
|
||||
|
||||
if ($field3) {
|
||||
$data0[$ts][$field3] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$data0[$ts][$field2] = $item[$field2];
|
||||
}
|
||||
|
||||
$iters = count($data3);
|
||||
|
||||
for ($i = 0; $i < $iters; ++$i) {
|
||||
$item = $data3[$i];
|
||||
$ts = $item['ts'];
|
||||
|
||||
if (!array_key_exists($ts, $data0)) {
|
||||
$data0[$ts] = [
|
||||
'ts' => $ts,
|
||||
$field1 => 0,
|
||||
$field2 => 0,
|
||||
$field3 => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$data0[$ts][$field3] = $item[$field3];
|
||||
}
|
||||
|
||||
// TODO: tmp order troubles fix
|
||||
usort($data0, function ($a, $b) {
|
||||
return $a['ts'] - $b['ts'];
|
||||
});
|
||||
|
||||
return $data0;
|
||||
}
|
||||
|
||||
protected function addEmptyDays(array $params): array {
|
||||
$cnt = count($params);
|
||||
$data = array_fill(0, $cnt, []);
|
||||
|
||||
$request = $this->f3->get('REQUEST');
|
||||
$step = \Utils\Constants::get('CHART_RESOLUTION')[$this->getResolution($request)];
|
||||
// use offset shift because $startTs/$endTs compared with shifted ['ts']
|
||||
$offset = \Utils\TimeZones::getCurrentOperatorOffset();
|
||||
$dateRange = $this->getDatesRange($request, $offset);
|
||||
|
||||
if (!$dateRange) {
|
||||
$now = time() + $offset;
|
||||
$week = 7 * 24 * 60 * 60;
|
||||
if (count($params[0]) === 0) {
|
||||
$dateRange = [
|
||||
'endDate' => date('Y-m-d H:i:s', $now),
|
||||
'startDate' => date('Y-m-d 00:00:01', $now - $week),
|
||||
];
|
||||
} else {
|
||||
$firstTs = ($now - $params[0][0] < $week) ? $now - $week : $params[0][0];
|
||||
$dateRange = [
|
||||
'endDate' => date('Y-m-d H:i:s', $now),
|
||||
'startDate' => date('Y-m-d 00:00:01', $firstTs),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$endTs = strtotime($dateRange['endDate']);
|
||||
$startTs = strtotime($dateRange['startDate']);
|
||||
|
||||
$endTs = $endTs - ($endTs % $step);
|
||||
$startTs = $startTs - ($startTs % $step);
|
||||
|
||||
$ox = $params[0];
|
||||
|
||||
while ($endTs >= $startTs) {
|
||||
$itemIdx = array_search($startTs, $ox);
|
||||
|
||||
$data[0][] = $startTs;
|
||||
|
||||
for ($i = 1; $i < $cnt; ++$i) {
|
||||
$data[$i][] = ($itemIdx !== false) ? $params[$i][$itemIdx] : 0;
|
||||
}
|
||||
|
||||
$startTs += $step;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function execute(string $query, int $apiKey): array {
|
||||
$request = $this->f3->get('REQUEST');
|
||||
|
||||
// do not use offset because :start_time/:end_time compared with UTC db timestamps
|
||||
$dateRange = $this->getDatesRange($request);
|
||||
|
||||
// Search request does not contain daterange param
|
||||
if (!$dateRange) {
|
||||
$dateRange = [
|
||||
'endDate' => date('Y-m-d H:i:s'),
|
||||
'startDate' => date('Y-m-d H:i:s', 0),
|
||||
];
|
||||
}
|
||||
|
||||
$offset = \Utils\TimeZones::getCurrentOperatorOffset();
|
||||
|
||||
$params = [
|
||||
':api_key' => $apiKey,
|
||||
':end_time' => $dateRange['endDate'],
|
||||
':start_time' => $dateRange['startDate'],
|
||||
':resolution' => $this->getResolution($request),
|
||||
':offset' => strval($offset), // str for postgres
|
||||
];
|
||||
|
||||
return $this->execQuery($query, $params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class BaseEventsCount extends \Models\BaseSql {
|
||||
use \Traits\DateRange;
|
||||
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
protected $alertTypesParams;
|
||||
protected $editTypesParams;
|
||||
protected $normalTypesParams;
|
||||
|
||||
protected $alertFlatIds;
|
||||
protected $editFlatIds;
|
||||
protected $normalFlatIds;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
[$this->alertTypesParams, $this->alertFlatIds] = $this->getArrayPlaceholders(\Utils\Constants::get('ALERT_EVENT_TYPES'), 'alert');
|
||||
[$this->editTypesParams, $this->editFlatIds] = $this->getArrayPlaceholders(\Utils\Constants::get('EDITING_EVENT_TYPES'), 'edit');
|
||||
[$this->normalTypesParams, $this->normalFlatIds] = $this->getArrayPlaceholders(\Utils\Constants::get('NORMAL_EVENT_TYPES'), 'normal');
|
||||
}
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$itemsByDate = [];
|
||||
$items = $this->getCounts($apiKey);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$itemsByDate[$item['ts']] = [
|
||||
$item['event_normal_type_count'],
|
||||
$item['event_editing_type_count'],
|
||||
$item['event_alert_type_count'],
|
||||
];
|
||||
}
|
||||
$request = $this->f3->get('REQUEST');
|
||||
// use offset shift because $startTs/$endTs compared with shifted ['ts']
|
||||
$offset = \Utils\TimeZones::getCurrentOperatorOffset();
|
||||
$datesRange = $this->getLatestNDatesRange(180, $offset);
|
||||
$endTs = strtotime($datesRange['endDate']);
|
||||
$startTs = strtotime($datesRange['startDate']);
|
||||
$step = \Utils\Constants::get('CHART_RESOLUTION')[$this->getResolution($request)];
|
||||
|
||||
$endTs = $endTs - ($endTs % $step);
|
||||
$startTs = $startTs - ($startTs % $step);
|
||||
|
||||
while ($endTs >= $startTs) {
|
||||
if (!isset($itemsByDate[$startTs])) {
|
||||
$itemsByDate[$startTs] = [null, null, null];
|
||||
}
|
||||
|
||||
$startTs += $step;
|
||||
}
|
||||
|
||||
ksort($itemsByDate);
|
||||
|
||||
$ox = [];
|
||||
$l1 = [];
|
||||
$l2 = [];
|
||||
$l3 = [];
|
||||
|
||||
foreach ($itemsByDate as $key => $value) {
|
||||
$ox[] = $key;
|
||||
$l1[] = $value[0];
|
||||
$l2[] = $value[1];
|
||||
$l3[] = $value[2];
|
||||
}
|
||||
|
||||
return [$ox, $l1, $l2, $l3];
|
||||
}
|
||||
|
||||
protected function executeOnRangeById(string $query, int $apiKey): array {
|
||||
$request = $this->f3->get('REQUEST');
|
||||
// do not use offset because :start_time/:end_time compared with UTC event.time
|
||||
$dateRange = $this->getLatestNDatesRange(180);
|
||||
$offset = \Utils\TimeZones::getCurrentOperatorOffset();
|
||||
|
||||
$params = [
|
||||
':api_key' => $apiKey,
|
||||
':end_time' => $dateRange['endDate'],
|
||||
':start_time' => $dateRange['startDate'],
|
||||
':resolution' => $this->getResolution($request),
|
||||
':id' => $request['id'],
|
||||
':offset' => strval($offset), // str for postgres
|
||||
];
|
||||
|
||||
$params = array_merge($params, $this->alertTypesParams);
|
||||
$params = array_merge($params, $this->editTypesParams);
|
||||
$params = array_merge($params, $this->normalTypesParams);
|
||||
|
||||
return $this->execQuery($query, $params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Blacklist extends Base {
|
||||
public function getData(int $apiKey): array {
|
||||
$data = $this->getFirstLine($apiKey);
|
||||
|
||||
$timestamps = array_column($data, 'ts');
|
||||
$line1 = array_column($data, 'ts_new_records');
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, tbl.created + :offset))::bigint AS ts,
|
||||
COUNT(*) AS ts_new_records
|
||||
FROM (
|
||||
SELECT DISTINCT
|
||||
blacklist.accountid,
|
||||
blacklist.created,
|
||||
extra.type,
|
||||
CASE extra.type
|
||||
WHEN \'ip\' THEN blacklist.ip
|
||||
WHEN \'email\' THEN blacklist.email
|
||||
WHEN \'phone\' THEN blacklist.phone
|
||||
END AS value
|
||||
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
event_account.id AS accountid,
|
||||
event_account.latest_decision AS created,
|
||||
CASE WHEN event_ip.fraud_detected THEN split_part(event_ip.ip::text, \'/\', 1) ELSE NULL END AS ip,
|
||||
event_ip.fraud_detected AS ip_fraud,
|
||||
CASE WHEN event_email.fraud_detected THEN event_email.email ELSE NULL END AS email,
|
||||
event_email.fraud_detected AS email_fraud,
|
||||
CASE WHEN event_phone.fraud_detected THEN event_phone.phone_number ELSE NULL END AS phone,
|
||||
event_phone.fraud_detected AS phone_fraud
|
||||
FROM event
|
||||
|
||||
LEFT JOIN event_account
|
||||
ON event_account.id = event.account
|
||||
|
||||
LEFT JOIN event_ip
|
||||
ON event_ip.id = event.ip
|
||||
|
||||
LEFT JOIN event_email
|
||||
ON event_email.id = event.email
|
||||
|
||||
LEFT JOIN event_phone
|
||||
ON event_phone.id = event.phone
|
||||
|
||||
WHERE
|
||||
event_account.key = :api_key AND
|
||||
event_account.fraud IS TRUE AND
|
||||
event_account.latest_decision >= :start_time AND
|
||||
event_account.latest_decision <= :end_time AND
|
||||
(
|
||||
event_email.fraud_detected IS TRUE OR
|
||||
event_ip.fraud_detected IS TRUE OR
|
||||
event_phone.fraud_detected IS TRUE
|
||||
)
|
||||
) AS blacklist,
|
||||
LATERAL (
|
||||
VALUES
|
||||
(CASE WHEN ip_fraud = true THEN \'ip\' END),
|
||||
(CASE WHEN email_fraud = true THEN \'email\' END),
|
||||
(CASE WHEN phone_fraud = true THEN \'phone\' END)
|
||||
) AS extra(type)
|
||||
|
||||
WHERE
|
||||
extra.type IS NOT NULL
|
||||
) AS tbl
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Bot extends BaseEventsCount {
|
||||
public function getCounts(int $apiKey): array {
|
||||
$query = (
|
||||
"SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(CASE WHEN event.type IN ({$this->normalFlatIds}) THEN TRUE END) AS event_normal_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->editFlatIds}) THEN TRUE END) AS event_editing_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->alertFlatIds}) THEN TRUE END) AS event_alert_type_count
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_device
|
||||
ON (event.device = event_device.id)
|
||||
|
||||
INNER JOIN event_ua_parsed
|
||||
ON (event_device.user_agent = event_ua_parsed.id)
|
||||
|
||||
WHERE
|
||||
event_ua_parsed.id = :id AND
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts"
|
||||
);
|
||||
|
||||
return $this->executeOnRangeById($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Bots extends Base {
|
||||
protected $DB_TABLE_NAME = 'event_device';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$data = $this->getFirstLine($apiKey);
|
||||
|
||||
$ox = array_column($data, 'ts');
|
||||
$l1 = array_column($data, 'bot_count');
|
||||
|
||||
return $this->addEmptyDays([$ox, $l1]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(DISTINCT (
|
||||
CASE WHEN event_ua_parsed.modified IS TRUE THEN event.device END)
|
||||
) AS bot_count
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_device
|
||||
ON(event.device = event_device.id)
|
||||
INNER JOIN event_ua_parsed
|
||||
ON(event_device.user_agent=event_ua_parsed.id)
|
||||
|
||||
WHERE
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Country extends BaseEventsCount {
|
||||
public function getCounts(int $apiKey): array {
|
||||
$query = (
|
||||
"SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(CASE WHEN event.type IN ({$this->normalFlatIds}) THEN TRUE END) AS event_normal_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->editFlatIds}) THEN TRUE END) AS event_editing_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->alertFlatIds}) THEN TRUE END) AS event_alert_type_count
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_ip
|
||||
ON (event.ip = event_ip.id)
|
||||
|
||||
INNER JOIN countries
|
||||
ON (event_ip.country = countries.id)
|
||||
|
||||
WHERE
|
||||
countries.id = :id AND
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts"
|
||||
);
|
||||
|
||||
return $this->executeOnRangeById($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Domain extends BaseEventsCount {
|
||||
public function getCounts(int $apiKey): array {
|
||||
$query = (
|
||||
"SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(CASE WHEN event.type IN ({$this->normalFlatIds}) THEN TRUE END) AS event_normal_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->editFlatIds}) THEN TRUE END) AS event_editing_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->alertFlatIds}) THEN TRUE END) AS event_alert_type_count
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_email
|
||||
ON (event.email = event_email.id)
|
||||
|
||||
WHERE
|
||||
event_email.domain = :id AND
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts"
|
||||
);
|
||||
|
||||
return $this->executeOnRangeById($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Domains extends Base {
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$field1 = 'unique_domains_count';
|
||||
$data1 = $this->getFirstLine($apiKey);
|
||||
|
||||
$field2 = 'ts_new_domains';
|
||||
$data2 = $this->getSecondLine($apiKey);
|
||||
|
||||
$data0 = $this->concatDataLines($data1, $field1, $data2, $field2);
|
||||
|
||||
$indexedData = array_values($data0);
|
||||
$timestamps = array_column($indexedData, 'ts');
|
||||
$line1 = array_column($indexedData, $field1);
|
||||
$line2 = array_column($indexedData, $field2);
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1, $line2]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(DISTINCT event_email.domain) AS unique_domains_count
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_email
|
||||
ON (event.email = event_email.id)
|
||||
|
||||
WHERE
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey);
|
||||
}
|
||||
|
||||
private function getSecondLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event_domain.created + :offset))::bigint AS ts,
|
||||
COUNT(event_domain.id) AS ts_new_domains
|
||||
FROM
|
||||
event_domain
|
||||
|
||||
WHERE
|
||||
event_domain.key = :api_key AND
|
||||
event_domain.created >= :start_time AND
|
||||
event_domain.created <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Emails extends Base {
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$data = $this->getFirstLine($apiKey);
|
||||
|
||||
$timestamps = array_column($data, 'ts');
|
||||
$line1 = array_column($data, 'email_count');
|
||||
$line2 = array_column($data, 'blockemails_count');
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1, $line2]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(DISTINCT event.email) AS email_count,
|
||||
COUNT(DISTINCT (
|
||||
CASE WHEN event_email.blockemails IS TRUE THEN event.email END)
|
||||
) AS blockemails_count
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_email
|
||||
ON (event.email = event_email.id)
|
||||
|
||||
WHERE
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Events extends Base {
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$data = $this->getFirstLine($apiKey);
|
||||
|
||||
$timestamps = array_column($data, 'ts');
|
||||
$line1 = array_column($data, 'event_normal_type_count');
|
||||
$line2 = array_column($data, 'event_editing_type_count');
|
||||
$line3 = array_column($data, 'event_alert_type_count');
|
||||
$line4 = array_column($data, 'unauthorized_event_count');
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1, $line2, $line3, $line4]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$request = $this->f3->get('REQUEST');
|
||||
$dateRange = $this->getDatesRange($request);
|
||||
if (!$dateRange) {
|
||||
$dateRange = [
|
||||
'endDate' => date('Y-m-d H:i:s'),
|
||||
'startDate' => date('Y-m-d H:i:s', 0),
|
||||
];
|
||||
}
|
||||
$offset = \Utils\TimeZones::getCurrentOperatorOffset();
|
||||
[$alertTypesParams, $alertFlatIds] = $this->getArrayPlaceholders(\Utils\Constants::get('ALERT_EVENT_TYPES'), 'alert');
|
||||
[$editTypesParams, $editFlatIds] = $this->getArrayPlaceholders(\Utils\Constants::get('EDITING_EVENT_TYPES'), 'edit');
|
||||
[$normalTypesParams, $normalFlatIds] = $this->getArrayPlaceholders(\Utils\Constants::get('NORMAL_EVENT_TYPES'), 'normal');
|
||||
$params = [
|
||||
':api_key' => $apiKey,
|
||||
':end_time' => $dateRange['endDate'],
|
||||
':start_time' => $dateRange['startDate'],
|
||||
':resolution' => $this->getResolution($request),
|
||||
':offset' => strval($offset),
|
||||
':unauth' => \Utils\Constants::get('UNAUTHORIZED_USERID'),
|
||||
];
|
||||
$params = array_merge($params, $alertTypesParams);
|
||||
$params = array_merge($params, $editTypesParams);
|
||||
$params = array_merge($params, $normalTypesParams);
|
||||
|
||||
$query = (
|
||||
"SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(CASE WHEN event.type IN ({$normalFlatIds}) THEN TRUE END) AS event_normal_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$editFlatIds}) THEN TRUE END) AS event_editing_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$alertFlatIds}) THEN TRUE END) AS event_alert_type_count,
|
||||
COUNT(CASE WHEN event_account.userid = :unauth THEN TRUE END) AS unauthorized_event_count
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
LEFT JOIN event_account
|
||||
ON event.account = event_account.id
|
||||
|
||||
WHERE
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts"
|
||||
);
|
||||
|
||||
return $this->execQuery($query, $params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Ip extends BaseEventsCount {
|
||||
public function getCounts(int $apiKey): array {
|
||||
$query = (
|
||||
"SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(CASE WHEN event.type IN ({$this->normalFlatIds}) THEN TRUE END) AS event_normal_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->editFlatIds}) THEN TRUE END) AS event_editing_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->alertFlatIds}) THEN TRUE END) AS event_alert_type_count
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
WHERE
|
||||
event.ip = :id AND
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts"
|
||||
);
|
||||
|
||||
return $this->executeOnRangeById($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Ips extends Base {
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$data = $this->getFirstLine($apiKey);
|
||||
|
||||
$timestamps = array_column($data, 'ts');
|
||||
$line1 = array_column($data, 'residence_ip_count');
|
||||
$line2 = array_column($data, 'total_privacy');
|
||||
$line3 = array_column($data, 'suspicious_ip_count');
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1, $line2, $line3]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(DISTINCT event.ip) AS unique_ip_count,
|
||||
|
||||
COUNT(DISTINCT
|
||||
CASE
|
||||
WHEN event_ip.data_center IS TRUE OR
|
||||
event_ip.tor IS TRUE OR
|
||||
event_ip.vpn IS TRUE
|
||||
THEN event.ip
|
||||
ELSE NULL
|
||||
END
|
||||
) AS total_privacy,
|
||||
|
||||
COUNT(DISTINCT event.ip) - COUNT(DISTINCT
|
||||
CASE
|
||||
WHEN event_ip.data_center IS TRUE OR
|
||||
event_ip.tor IS TRUE OR
|
||||
event_ip.vpn IS TRUE
|
||||
THEN event.ip
|
||||
ELSE NULL
|
||||
END
|
||||
) AS residence_ip_count,
|
||||
|
||||
COUNT(DISTINCT
|
||||
CASE
|
||||
WHEN event_ip.blocklist IS TRUE OR
|
||||
event_ip.fraud_detected IS TRUE
|
||||
THEN event.ip
|
||||
ELSE NULL
|
||||
END
|
||||
) AS suspicious_ip_count
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_ip
|
||||
ON (event.ip = event_ip.id)
|
||||
|
||||
WHERE
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Isp extends BaseEventsCount {
|
||||
public function getCounts(int $apiKey): array {
|
||||
$query = (
|
||||
"SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(CASE WHEN event.type IN ({$this->normalFlatIds}) THEN TRUE END) AS event_normal_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->editFlatIds}) THEN TRUE END) AS event_editing_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->alertFlatIds}) THEN TRUE END) AS event_alert_type_count
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_ip
|
||||
ON (event.ip = event_ip.id)
|
||||
|
||||
LEFT JOIN event_isp
|
||||
ON (event_ip.isp = event_isp.id)
|
||||
|
||||
WHERE
|
||||
event_isp.id = :id AND
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts"
|
||||
);
|
||||
|
||||
return $this->executeOnRangeById($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Isps extends Base {
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$field1 = 'unique_isps_count';
|
||||
$data1 = $this->getFirstLine($apiKey);
|
||||
|
||||
$field2 = 'ts_new_isps';
|
||||
$data2 = $this->getSecondLine($apiKey);
|
||||
|
||||
$data0 = $this->concatDataLines($data1, $field1, $data2, $field2);
|
||||
$indexedData = array_values($data0);
|
||||
|
||||
$timestamps = array_column($indexedData, 'ts');
|
||||
$line1 = array_column($indexedData, $field1);
|
||||
$line2 = array_column($indexedData, $field2);
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1, $line2]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(DISTINCT event_isp.id) AS unique_isps_count
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_ip
|
||||
ON (event.ip = event_ip.id)
|
||||
|
||||
LEFT JOIN event_isp
|
||||
ON (event_ip.isp = event_isp.id)
|
||||
|
||||
WHERE
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey);
|
||||
}
|
||||
|
||||
private function getSecondLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event_isp.created + :offset))::bigint AS ts,
|
||||
COUNT(event_isp.id) AS ts_new_isps
|
||||
FROM
|
||||
event_isp
|
||||
|
||||
WHERE
|
||||
event_isp.key = :api_key AND
|
||||
event_isp.created >= :start_time AND
|
||||
event_isp.created <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Logbook extends Base {
|
||||
protected $DB_TABLE_NAME = 'event_logbook';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$data = $this->getFirstLine($apiKey);
|
||||
|
||||
$timestamps = array_column($data, 'ts');
|
||||
$line1 = array_column($data, 'event_normal_type_count');
|
||||
$line2 = array_column($data, 'event_issued_type_count');
|
||||
$line3 = array_column($data, 'event_failed_type_count');
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1, $line2, $line3]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$request = $this->f3->get('REQUEST');
|
||||
$dateRange = $this->getDatesRange($request);
|
||||
if (!$dateRange) {
|
||||
$dateRange = [
|
||||
'endDate' => date('Y-m-d H:i:s'),
|
||||
'startDate' => date('Y-m-d H:i:s', 0),
|
||||
];
|
||||
}
|
||||
|
||||
//$dateRange['endDate'] = \Utils\TimeZones::localizeForActiveOperator($dateRange['endDate']);
|
||||
//$dateRange['startDate'] = \Utils\TimeZones::localizeForActiveOperator($dateRange['startDate']);
|
||||
|
||||
[$failedTypesParams, $failedFlatIds] = $this->getArrayPlaceholders(\Utils\Constants::get('FAILED_LOGBOOK_EVENT_TYPES'), 'failed');
|
||||
[$issuedTypesParams, $issuedFlatIds] = $this->getArrayPlaceholders(\Utils\Constants::get('ISSUED_LOGBOOK_EVENT_TYPES'), 'issued');
|
||||
[$normalTypesParams, $normalFlatIds] = $this->getArrayPlaceholders(\Utils\Constants::get('NORMAL_LOGBOOK_EVENT_TYPES'), 'normal');
|
||||
$params = [
|
||||
':api_key' => $apiKey,
|
||||
':end_time' => $dateRange['endDate'],
|
||||
':start_time' => $dateRange['startDate'],
|
||||
':resolution' => $this->getResolution($request),
|
||||
];
|
||||
$params = array_merge($params, $failedTypesParams);
|
||||
$params = array_merge($params, $issuedTypesParams);
|
||||
$params = array_merge($params, $normalTypesParams);
|
||||
|
||||
$query = (
|
||||
"SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event_logbook.started))::bigint AS ts,
|
||||
COUNT(CASE WHEN event_error_type.value IN ({$normalFlatIds}) THEN TRUE END) AS event_normal_type_count,
|
||||
COUNT(CASE WHEN event_error_type.value IN ({$issuedFlatIds}) THEN TRUE END) AS event_issued_type_count,
|
||||
COUNT(CASE WHEN event_error_type.value IN ({$failedFlatIds}) THEN TRUE END) AS event_failed_type_count
|
||||
|
||||
FROM
|
||||
event_logbook
|
||||
|
||||
LEFT JOIN event_error_type
|
||||
ON event_logbook.error_type = event_error_type.id
|
||||
|
||||
WHERE
|
||||
event_logbook.key = :api_key AND
|
||||
event_logbook.started >= :start_time AND
|
||||
event_logbook.started <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts"
|
||||
);
|
||||
|
||||
return $this->execQuery($query, $params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Phones extends Base {
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$data = $this->getFirstLine($apiKey);
|
||||
|
||||
$timestamps = array_column($data, 'ts');
|
||||
$line1 = array_column($data, 'phone_count');
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event_phone.lastseen + :offset))::bigint AS ts,
|
||||
COUNT(*) AS phone_count
|
||||
FROM
|
||||
event_phone
|
||||
|
||||
WHERE
|
||||
event_phone.key = :api_key AND
|
||||
event_phone.lastseen >= :start_time AND
|
||||
event_phone.lastseen <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Resource extends BaseEventsCount {
|
||||
public function getCounts(int $apiKey): array {
|
||||
$query = (
|
||||
"SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(CASE WHEN event.type IN ({$this->normalFlatIds}) THEN TRUE END) AS event_normal_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->editFlatIds}) THEN TRUE END) AS event_editing_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->alertFlatIds}) THEN TRUE END) AS event_alert_type_count
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
WHERE
|
||||
event.url = :id AND
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts"
|
||||
);
|
||||
|
||||
return $this->executeOnRangeById($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Resources extends Base {
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$data = $this->getFirstLine($apiKey);
|
||||
|
||||
$timestamps = array_column($data, 'ts');
|
||||
$line1 = array_column($data, 'count_200');
|
||||
$line2 = array_column($data, 'count_404');
|
||||
$line3 = array_column($data, 'count_500');
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1, $line2, $line3]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(DISTINCT event.id) AS url_count,
|
||||
|
||||
COUNT(DISTINCT (
|
||||
CASE WHEN event.http_code=200 OR event.http_code IS NULL THEN event.id END)
|
||||
) AS count_200,
|
||||
|
||||
COUNT(DISTINCT (
|
||||
CASE WHEN event.http_code = 404 THEN event.id END)
|
||||
) AS count_404,
|
||||
|
||||
COUNT(DISTINCT (
|
||||
CASE WHEN event.http_code IN(403, 500) THEN event.id END)
|
||||
) AS count_500
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
WHERE
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class ReviewQueue extends Base {
|
||||
use \Traits\DateRange;
|
||||
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$field1 = 'ts_new_users_whitelisted';
|
||||
$data1 = $this->getFirstLine($apiKey);
|
||||
|
||||
$field2 = 'ts_new_added_to_review';
|
||||
$data2 = $this->getSecondLine($apiKey);
|
||||
|
||||
$field3 = 'ts_new_users_blacklisted';
|
||||
$data3 = $this->getThirdLine($apiKey);
|
||||
|
||||
$data0 = $this->concatDataLines($data1, $field1, $data2, $field2, $data3, $field3);
|
||||
|
||||
$indexedData = array_values($data0);
|
||||
$timestamps = array_column($indexedData, 'ts');
|
||||
$line1 = array_column($indexedData, $field1);
|
||||
$line2 = array_column($indexedData, $field2);
|
||||
$line3 = array_column($indexedData, $field3);
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1, $line2, $line3]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event_account.latest_decision + :offset))::bigint AS ts,
|
||||
COUNT(event_account.id) as ts_new_users_whitelisted
|
||||
FROM
|
||||
event_account
|
||||
|
||||
WHERE
|
||||
event_account.key = :api_key AND
|
||||
event_account.fraud IS FALSE AND
|
||||
event_account.latest_decision >= :start_time AND
|
||||
event_account.latest_decision <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey, false);
|
||||
}
|
||||
|
||||
private function getSecondLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event_account.added_to_review + :offset))::bigint AS ts,
|
||||
COUNT(event_account.id) AS ts_new_added_to_review
|
||||
FROM
|
||||
event_account
|
||||
|
||||
WHERE
|
||||
event_account.key = :api_key AND
|
||||
event_account.added_to_review IS NOT NULL AND
|
||||
event_account.added_to_review >= :start_time AND
|
||||
event_account.added_to_review <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey, false);
|
||||
}
|
||||
|
||||
private function getThirdLine(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event_account.latest_decision + :offset))::bigint AS ts,
|
||||
COUNT(event_account.id) as ts_new_users_blacklisted
|
||||
FROM
|
||||
event_account
|
||||
|
||||
WHERE
|
||||
event_account.key = :api_key AND
|
||||
event_account.fraud IS TRUE AND
|
||||
event_account.latest_decision >= :start_time AND
|
||||
event_account.latest_decision <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class SessionStat extends Base {
|
||||
protected $DB_TABLE_NAME = 'event_session';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$itemsByDate = [];
|
||||
$items = $this->getCounts($apiKey);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$itemsByDate[$item['ts']] = [
|
||||
$item['new_device_count_sum'],
|
||||
$item['new_ip_count_sum'],
|
||||
$item['event_session_cnt'],
|
||||
$item['event_count_max'],
|
||||
];
|
||||
}
|
||||
|
||||
$request = $this->f3->get('REQUEST');
|
||||
// use offset shift because $startTs/$endTs compared with shifted ['ts']
|
||||
$offset = \Utils\TimeZones::getCurrentOperatorOffset();
|
||||
$datesRange = $this->getLatestNDatesRange(14, $offset);
|
||||
$endTs = strtotime($datesRange['endDate']);
|
||||
$startTs = strtotime($datesRange['startDate']);
|
||||
$step = \Utils\Constants::get('CHART_RESOLUTION')[$this->getResolution($request)];
|
||||
|
||||
$endTs = $endTs - ($endTs % $step);
|
||||
$startTs = $startTs - ($startTs % $step);
|
||||
|
||||
$midTs = $startTs + $step * 7;
|
||||
|
||||
foreach ($itemsByDate as $ts => $value) {
|
||||
if ($ts <= $midTs) {
|
||||
$newTs = $ts + $step * 7;
|
||||
if (!array_key_exists($newTs, $itemsByDate)) {
|
||||
$itemsByDate[$newTs] = [
|
||||
0, 0, 0, 0,
|
||||
$value[0], $value[1], $value[2], $value[3],
|
||||
];
|
||||
} else {
|
||||
$itemsByDate[$newTs][] = $value[0];
|
||||
$itemsByDate[$newTs][] = $value[1];
|
||||
$itemsByDate[$newTs][] = $value[2];
|
||||
$itemsByDate[$newTs][] = $value[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ($endTs >= $startTs) {
|
||||
if (!isset($itemsByDate[$startTs]) && $startTs > $midTs) {
|
||||
$itemsByDate[$startTs] = [0, 0, 0, 0, 0, 0, 0, 0];
|
||||
} elseif (isset($itemsByDate[$startTs]) && count($itemsByDate[$startTs]) === 4) {
|
||||
$itemsByDate[$startTs][] = 0;
|
||||
$itemsByDate[$startTs][] = 0;
|
||||
$itemsByDate[$startTs][] = 0;
|
||||
$itemsByDate[$startTs][] = 0;
|
||||
}
|
||||
|
||||
$startTs += $step;
|
||||
}
|
||||
|
||||
foreach (array_keys($itemsByDate) as $key) {
|
||||
if ($key <= $midTs) {
|
||||
unset($itemsByDate[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
ksort($itemsByDate);
|
||||
|
||||
$result = [array_keys($itemsByDate)];
|
||||
|
||||
for ($i = 0; $i < 8; ++$i) {
|
||||
$result[] = array_column($itemsByDate, $i);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function executeOnRangeById(string $query, int $apiKey): array {
|
||||
$request = $this->f3->get('REQUEST');
|
||||
// do not use offset because :start_time/:end_time compared with UTC event.time
|
||||
$dateRange = $this->getLatestNDatesRange(14);
|
||||
$offset = \Utils\TimeZones::getCurrentOperatorOffset();
|
||||
|
||||
$params = [
|
||||
':api_key' => $apiKey,
|
||||
':end_time' => $dateRange['endDate'],
|
||||
':start_time' => $dateRange['startDate'],
|
||||
//':resolution' => $this->getResolution($request),
|
||||
':resolution' => 60 * 60 * 24,
|
||||
':id' => $request['id'],
|
||||
':offset' => strval($offset), // str for postgres
|
||||
];
|
||||
|
||||
return $this->execQuery($query, $params);
|
||||
}
|
||||
|
||||
private function getCounts(int $apiKey): array {
|
||||
$query = (
|
||||
'SELECT
|
||||
((EXTRACT(EPOCH FROM event_session.created)::bigint + :offset::bigint) / :resolution) * :resolution as ts,
|
||||
|
||||
COUNT(event_session.id) AS event_session_cnt,
|
||||
MAX(event_session_stat.event_count) AS event_count_max,
|
||||
FLOOR(AVG(event_session_stat.event_count))::int AS event_count_avg,
|
||||
MAX(event_session_stat.device_count) AS device_count_max,
|
||||
FLOOR(AVG(event_session_stat.device_count))::int AS device_count_avg,
|
||||
MAX(event_session_stat.ip_count) AS ip_count_max,
|
||||
FLOOR(AVG(event_session_stat.ip_count))::int AS ip_count_avg,
|
||||
MAX(event_session_stat.country_count) AS country_count_max,
|
||||
FLOOR(AVG(event_session_stat.country_count))::int AS country_count_avg,
|
||||
SUM(event_session_stat.new_ip_count) AS new_ip_count_sum,
|
||||
SUM(event_session_stat.new_device_count) AS new_device_count_sum,
|
||||
jsonb_agg(event_session_stat.event_types) AS event_types,
|
||||
jsonb_agg(event_session_stat.http_codes) AS http_codes
|
||||
|
||||
FROM
|
||||
event_session
|
||||
|
||||
LEFT JOIN event_session_stat
|
||||
ON event_session.id = event_session_stat.session_id
|
||||
|
||||
WHERE
|
||||
event_session.account_id = :id AND
|
||||
event_session.key = :api_key AND
|
||||
event_session.created >= :start_time AND
|
||||
event_session.created <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->executeOnRangeById($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class User extends BaseEventsCount {
|
||||
public function getCounts(int $apiKey) {
|
||||
$query = (
|
||||
"SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event.time + :offset))::bigint AS ts,
|
||||
COUNT(CASE WHEN event.type IN ({$this->normalFlatIds}) THEN TRUE END) AS event_normal_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->editFlatIds}) THEN TRUE END) AS event_editing_type_count,
|
||||
COUNT(CASE WHEN event.type IN ({$this->alertFlatIds}) THEN TRUE END) AS event_alert_type_count
|
||||
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_account
|
||||
ON (event.account = event_account.id)
|
||||
|
||||
WHERE
|
||||
event_account.id = :id AND
|
||||
event.key = :api_key AND
|
||||
event.time >= :start_time AND
|
||||
event.time <= :end_time
|
||||
|
||||
GROUP BY ts
|
||||
ORDER BY ts"
|
||||
);
|
||||
|
||||
return $this->executeOnRangeById($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Users extends Base {
|
||||
use \Traits\DateRange;
|
||||
|
||||
protected $DB_TABLE_NAME = 'event_account';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$data0 = [];
|
||||
$data1 = $this->getFirstLine($apiKey);
|
||||
$iters = count($data1);
|
||||
|
||||
for ($i = 0; $i < $iters; ++$i) {
|
||||
$item = $data1[$i];
|
||||
$ts = $item['ts'];
|
||||
$score = $item['score'];
|
||||
|
||||
if (!isset($data0[$ts])) {
|
||||
$data0[$ts] = [
|
||||
'ts' => $ts,
|
||||
'ts_new_users_with_trust_score_high' => 0,
|
||||
'ts_new_users_with_trust_score_medium' => 0,
|
||||
'ts_new_users_with_trust_score_low' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$inf = \Utils\Constants::get('USER_HIGH_SCORE_INF');
|
||||
if ($score >= \Utils\Constants::get('USER_HIGH_SCORE_INF')) {
|
||||
++$data0[$ts]['ts_new_users_with_trust_score_high'];
|
||||
}
|
||||
|
||||
$inf = \Utils\Constants::get('USER_MEDIUM_SCORE_INF');
|
||||
$sup = \Utils\Constants::get('USER_MEDIUM_SCORE_SUP');
|
||||
if ($score >= $inf && $score < $sup) {
|
||||
++$data0[$ts]['ts_new_users_with_trust_score_medium'];
|
||||
}
|
||||
|
||||
$inf = \Utils\Constants::get('USER_LOW_SCORE_INF');
|
||||
$sup = \Utils\Constants::get('USER_LOW_SCORE_SUP');
|
||||
if ($score >= $inf && $score < $sup) {
|
||||
++$data0[$ts]['ts_new_users_with_trust_score_low'];
|
||||
}
|
||||
}
|
||||
|
||||
$indexedData = array_values($data0);
|
||||
$timestamps = array_column($indexedData, 'ts');
|
||||
$line1 = array_column($indexedData, 'ts_new_users_with_trust_score_high');
|
||||
$line2 = array_column($indexedData, 'ts_new_users_with_trust_score_medium');
|
||||
$line3 = array_column($indexedData, 'ts_new_users_with_trust_score_low');
|
||||
|
||||
return $this->addEmptyDays([$timestamps, $line1, $line2, $line3]);
|
||||
}
|
||||
|
||||
private function getFirstLine(int $apiKey) {
|
||||
$query = (
|
||||
'SELECT
|
||||
EXTRACT(EPOCH FROM date_trunc(:resolution, event_account.created + :offset))::bigint AS ts,
|
||||
event_account.id,
|
||||
event_account.score
|
||||
FROM
|
||||
event_account
|
||||
|
||||
WHERE
|
||||
event_account.key = :api_key AND
|
||||
event_account.created >= :start_time AND
|
||||
event_account.created <= :end_time
|
||||
|
||||
GROUP BY ts, event_account.id
|
||||
ORDER BY ts'
|
||||
);
|
||||
|
||||
return $this->execute($query, $apiKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tirreno ~ Open source user analytics
|
||||
* Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
*
|
||||
* Licensed under GNU Affero General Public License version 3 of the or any later version.
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Tirreno Technologies Sàrl (https://www.tirreno.com)
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPL License
|
||||
* @link https://www.tirreno.com Tirreno(tm)
|
||||
*/
|
||||
|
||||
namespace Models\Chart;
|
||||
|
||||
class Watchlist extends Base {
|
||||
private $userIds = [];
|
||||
protected $DB_TABLE_NAME = 'event';
|
||||
|
||||
public function getData(int $apiKey): array {
|
||||
$params = $this->getRequestParams($apiKey);
|
||||
$params[':users_ids'] = $this->userIds;
|
||||
|
||||
$query = (
|
||||
"SELECT
|
||||
TEXT(date_trunc('day', event.time)) AS day,
|
||||
COUNT(event.id) AS event_count
|
||||
FROM
|
||||
event
|
||||
|
||||
INNER JOIN event_account
|
||||
ON (event.account = event_account.id)
|
||||
|
||||
INNER JOIN event_url
|
||||
ON (event.url = event_url.id)
|
||||
|
||||
INNER JOIN event_ip
|
||||
ON (event.ip = event_ip.id)
|
||||
|
||||
INNER JOIN countries
|
||||
ON (event_ip.country = countries.id)
|
||||
|
||||
WHERE
|
||||
event.key = :api_key
|
||||
%s
|
||||
|
||||
GROUP BY day
|
||||
ORDER BY day"
|
||||
);
|
||||
//$request = $this->f3->get('REQUEST');
|
||||
//$dateRange = $this->getDatesRange($request);
|
||||
|
||||
return $this->execQuery($query, $params);
|
||||
}
|
||||
|
||||
public function setUsersIds(array $userIds): void {
|
||||
$this->userIds = $userIds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user