first commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/statistics/StatisticsHelper.php
|
||||
*
|
||||
* Copyright (c) 2013-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class StatisticsHelper
|
||||
*
|
||||
* @ingroup statistics
|
||||
*
|
||||
* @brief Statistics helper class.
|
||||
*/
|
||||
|
||||
namespace APP\statistics;
|
||||
|
||||
use PKP\statistics\PKPStatisticsHelper;
|
||||
|
||||
class StatisticsHelper extends PKPStatisticsHelper
|
||||
{
|
||||
public const STATISTICS_DIMENSION_ISSUE_GALLEY_ID = 'issue_galley_id';
|
||||
public const STATISTICS_DIMENSION_ISSUE_ID = 'issue_id';
|
||||
|
||||
// Metrics
|
||||
public const STATISTICS_METRIC_INVESTIGATIONS = 'metric_investigations';
|
||||
public const STATISTICS_METRIC_INVESTIGATIONS_UNIQUE = 'metric_investigations_unique';
|
||||
public const STATISTICS_METRIC_REQUESTS = 'metric_requests';
|
||||
public const STATISTICS_METRIC_REQUESTS_UNIQUE = 'metric_requests_unique';
|
||||
|
||||
/**
|
||||
* Get COUNTER DB tables metrics columns
|
||||
*/
|
||||
public static function getCounterMetricsColumns(): array
|
||||
{
|
||||
return [
|
||||
self::STATISTICS_METRIC_INVESTIGATIONS,
|
||||
self::STATISTICS_METRIC_INVESTIGATIONS_UNIQUE,
|
||||
self::STATISTICS_METRIC_REQUESTS,
|
||||
self::STATISTICS_METRIC_REQUESTS_UNIQUE,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\APP\statistics\StatisticsHelper', '\StatisticsHelper');
|
||||
define('STATISTICS_DIMENSION_ISSUE_ID', StatisticsHelper::STATISTICS_DIMENSION_ISSUE_ID);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/statistics/TemporaryItemInvestigationsDAO.php
|
||||
*
|
||||
* Copyright (c) 2022 Simon Fraser University
|
||||
* Copyright (c) 2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class TemporaryItemInvestigationsDAO
|
||||
*
|
||||
* @ingroup statistics
|
||||
*
|
||||
* @brief Operations for retrieving and adding unique item (submission) investigations (abstract, primary and supp file views).
|
||||
*/
|
||||
|
||||
namespace APP\statistics;
|
||||
|
||||
use PKP\statistics\PKPTemporaryItemInvestigationsDAO;
|
||||
|
||||
class TemporaryItemInvestigationsDAO extends PKPTemporaryItemInvestigationsDAO
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/statistics/TemporaryItemRequestsDAO.php
|
||||
*
|
||||
* Copyright (c) 2022 Simon Fraser University
|
||||
* Copyright (c) 2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class TemporaryItemRequestsDAO
|
||||
*
|
||||
* @ingroup statistics
|
||||
*
|
||||
* @brief Operations for retrieving and adding unique item (submission) requests (primary files downloads).
|
||||
*/
|
||||
|
||||
namespace APP\statistics;
|
||||
|
||||
use PKP\statistics\PKPTemporaryItemRequestsDAO;
|
||||
|
||||
class TemporaryItemRequestsDAO extends PKPTemporaryItemRequestsDAO
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/statistics/TemporaryTotalsDAO.php
|
||||
*
|
||||
* Copyright (c) 2022 Simon Fraser University
|
||||
* Copyright (c) 2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class TemporaryTotalsDAO
|
||||
*
|
||||
* @ingroup statistics
|
||||
*
|
||||
* @brief Operations for retrieving and adding total usage.
|
||||
*
|
||||
* It considers:
|
||||
* issue toc and galley views.
|
||||
*/
|
||||
|
||||
namespace APP\statistics;
|
||||
|
||||
use APP\core\Application;
|
||||
use DateTimeImmutable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PKP\statistics\PKPTemporaryTotalsDAO;
|
||||
|
||||
class TemporaryTotalsDAO extends PKPTemporaryTotalsDAO
|
||||
{
|
||||
/**
|
||||
* Get Laravel optimized array of data to insert into the table based on the log entry
|
||||
*/
|
||||
protected function getInsertData(object $entryData): array
|
||||
{
|
||||
return array_merge(
|
||||
parent::getInsertData($entryData),
|
||||
[
|
||||
'issue_id' => $entryData->issueId,
|
||||
'issue_galley_id' => $entryData->issueGalleyId,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load usage for issue (TOC and galleys views)
|
||||
*/
|
||||
public function compileIssueMetrics(string $loadId): void
|
||||
{
|
||||
$date = DateTimeImmutable::createFromFormat('Ymd', substr($loadId, -12, 8));
|
||||
DB::table('metrics_issue')->where('load_id', '=', $loadId)->orWhereDate('date', '=', $date)->delete();
|
||||
|
||||
$selectIssueMetrics = DB::table($this->table)
|
||||
->select(DB::raw('load_id, context_id, issue_id, DATE(date) as date, count(*) as metric'))
|
||||
->where('load_id', '=', $loadId)
|
||||
->where('assoc_type', '=', Application::ASSOC_TYPE_ISSUE)
|
||||
->groupBy(DB::raw('load_id, context_id, issue_id, DATE(date)'));
|
||||
DB::table('metrics_issue')->insertUsing(['load_id', 'context_id', 'issue_id', 'date', 'metric'], $selectIssueMetrics);
|
||||
|
||||
$selectIssueGalleyMetrics = DB::table($this->table)
|
||||
->select(DB::raw('load_id, context_id, issue_id, issue_galley_id, DATE(date) as date, count(*) as metric'))
|
||||
->where('load_id', '=', $loadId)
|
||||
->where('assoc_type', '=', Application::ASSOC_TYPE_ISSUE_GALLEY)
|
||||
->groupBy(DB::raw('load_id, context_id, issue_id, issue_galley_id, DATE(date)'));
|
||||
DB::table('metrics_issue')->insertUsing(['load_id', 'context_id', 'issue_id', 'issue_galley_id', 'date', 'metric'], $selectIssueGalleyMetrics);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user