forked from Aspen-Discovery/aspen-discovery
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from Chloe070196/summon_usage_graphs
Summon usage graphs
- Loading branch information
Showing
4 changed files
with
250 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
code/web/interface/themes/responsive/Summon/usage-graph.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{strip} | ||
<div id="main-content" class="col-sm-12"> | ||
<h1>{translate text=$graphTitle isAdminFacing=true}</h1> | ||
<div class="chart-container" style="position: relative; height:50%; width:100%"> | ||
<canvas id="chart"></canvas> | ||
</div> | ||
|
||
<h2>{translate text="Raw Data" isAdminFacing=true}</h2> | ||
<div class="adminTableRegion fixed-height-table"> | ||
<table class="adminTable table table-responsive table-striped table-bordered table-condensed smallText table-sticky"> | ||
<thead> | ||
<tr> | ||
<th>{translate text="Date" isAdminFacing=true}</th> | ||
{foreach from=$dataSeries key=seriesLabel item=seriesData} | ||
<th>{if !empty($translateDataSeries)}{translate text=$seriesLabel isAdminFacing=true}{else}{$seriesLabel}{/if}</th> | ||
{/foreach} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{foreach from=$columnLabels item=label} | ||
<tr> | ||
<td>{if !empty($translateColumnLabels)}{translate text=$label isAdminFacing=true}{else}{$label}{/if}</td> | ||
{foreach from=$dataSeries item=seriesData} | ||
<td>{if (empty($seriesData.data.$label))}0{else}{$seriesData.data.$label|number_format}{/if}</td> | ||
{/foreach} | ||
</tr> | ||
{/foreach} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
{/strip} | ||
{literal} | ||
<script> | ||
var ctx = document.getElementById('chart'); | ||
var myChart = new Chart(ctx, { | ||
type: 'line', | ||
data: { | ||
labels: [ | ||
{/literal} | ||
{foreach from=$columnLabels item=columnLabel} | ||
'{$columnLabel}', | ||
{/foreach} | ||
{literal} | ||
], | ||
datasets: [ | ||
{/literal} | ||
{foreach from=$dataSeries key=seriesLabel item=seriesData} | ||
{ldelim} | ||
label: "{translate text=$seriesLabel isAdminFacing=true}", | ||
data: [ | ||
{foreach from=$seriesData.data item=curValue} | ||
{$curValue}, | ||
{/foreach} | ||
], | ||
borderWidth: 1, | ||
borderColor: '{$seriesData.borderColor}', | ||
backgroundColor: '{$seriesData.backgroundColor}', | ||
{rdelim}, | ||
{/foreach} | ||
{literal} | ||
] | ||
}, | ||
options: { | ||
scales: { | ||
yAxes: [{ | ||
ticks: { | ||
beginAtZero: true | ||
} | ||
}], | ||
xAxes: [{ | ||
type: 'category', | ||
labels: [ | ||
{/literal} | ||
{foreach from=$columnLabels item=columnLabel} | ||
'{$columnLabel}', | ||
{/foreach} | ||
{literal} | ||
] | ||
}] | ||
} | ||
} | ||
}); | ||
</script> | ||
{/literal} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
|
||
require_once ROOT_DIR . '/services/Admin/Admin.php'; | ||
require_once ROOT_DIR . '/sys/SystemLogging/AspenUsage.php'; | ||
require_once ROOT_DIR . '/sys/Summon/UserSummonUsage.php'; | ||
require_once ROOT_DIR . '/sys/Summon/SummonRecordUsage.php'; | ||
|
||
class Summon_UsageGraphs extends Admin_Admin { | ||
|
||
function launch() { | ||
global $interface; | ||
|
||
$title = 'Summon Usage Graph'; | ||
$stat = $_REQUEST['stat']; | ||
if (!empty($_REQUEST['instance'])) { | ||
$instanceName = $_REQUEST['instance']; | ||
} else { | ||
$instanceName = ''; | ||
} | ||
|
||
$dataSeries = []; | ||
$columnLabels = []; | ||
|
||
switch ($stat) { | ||
case 'activeUsers': | ||
$title .= ' - Active Users'; | ||
break; | ||
case 'numRecordsViewed': | ||
$title .= ' - Number of Records Viewed'; | ||
break; | ||
case 'numRecordsClicked': | ||
$title .= ' - Number of Records Clicked'; | ||
break; | ||
case 'totalClicks': | ||
$title .= ' - Total Clicks'; | ||
break; | ||
} | ||
|
||
// gets data from from user_summon_usage | ||
if ($stat == 'activeUsers') { | ||
$userSummonUsage = new UserSummonUsage(); | ||
$userSummonUsage->groupBy('year, month'); | ||
if (!empty($instanceName)) { | ||
$userSummonUsage->instance = $instanceName; | ||
} | ||
$userSummonUsage->selectAdd(); | ||
$userSummonUsage->selectAdd('year'); | ||
$userSummonUsage->selectAdd('month'); | ||
$userSummonUsage->orderBy('year, month'); | ||
|
||
$dataSeries['Active Users'] = [ | ||
'borderColor' => 'rgba(255, 99, 132, 1)', | ||
'backgroundColor' => 'rgba(255, 99, 132, 0.2)', | ||
'data' => [], | ||
]; | ||
$userSummonUsage->selectAdd('COUNT(DISTINCT userId) as activeUsers'); | ||
|
||
// Collects results | ||
$userSummonUsage->find(); | ||
while($userSummonUsage->fetch()) { | ||
$curPeriod = "{$userSummonUsage->month}-{$userSummonUsage->year}"; | ||
$columnLabels[] = $curPeriod; | ||
/** @noinspection PhpUndefinedFieldInspection */ | ||
$dataSeries['Active Users']['data'][$curPeriod] = $userSummonUsage->activeUsers; | ||
} | ||
} | ||
|
||
// gets data from from summon_usage | ||
if ( | ||
$stat == 'numRecordsViewed' || | ||
$stat == 'numRecordsClicked' || | ||
$stat == 'totalClicks' | ||
){ | ||
$summonRecordUsage = new SummonRecordUsage(); | ||
$summonRecordUsage->groupBy('year, month'); | ||
if (!empty($instanceName)) { | ||
$summonRecordUsage->instance = $instanceName; | ||
} | ||
$summonRecordUsage->selectAdd(); | ||
$summonRecordUsage->selectAdd('year'); | ||
$summonRecordUsage->selectAdd('month'); | ||
$summonRecordUsage->orderBy('year, month'); | ||
|
||
if ($stat == 'numRecordsViewed') { | ||
$dataSeries['Number of Records Viewed'] = [ | ||
'borderColor' => 'rgba(255, 99, 132, 1)', | ||
'backgroundColor' => 'rgba(255, 99, 132, 0.2)', | ||
'data' => [], | ||
]; | ||
$summonRecordUsage ->selectAdd('SUM(IF(timesViewedInSearch>0,1,0)) as numRecordsViewed'); | ||
} | ||
if ($stat == 'numRecordsClicked') { | ||
$dataSeries['Number of Records Clicked'] = [ | ||
'borderColor' => 'rgba(255, 99, 132, 1)', | ||
'backgroundColor' => 'rgba(255, 99, 132, 0.2)', | ||
'data' => [], | ||
]; | ||
$summonRecordUsage ->selectAdd('SUM(IF(timesUsed>0,1,0)) as numRecordsUsed'); | ||
} | ||
if ($stat == 'totalClicks') { | ||
$dataSeries['Total Clicks'] = [ | ||
'borderColor' => 'rgba(255, 99, 132, 1)', | ||
'backgroundColor' => 'rgba(255, 99, 132, 0.2)', | ||
'data' => [], | ||
]; | ||
$summonRecordUsage ->selectAdd('SUM(timesUsed) as numClicks'); | ||
} | ||
// Collect results | ||
$summonRecordUsage->find(); | ||
while ($summonRecordUsage->fetch()) { | ||
$curPeriod = "{$summonRecordUsage->month}-{$summonRecordUsage->year}"; | ||
$columnLabels[] = $curPeriod; | ||
if ($stat == 'numRecordsViewed') { | ||
/** @noinspection PhpUndefinedFieldInspection */ | ||
$dataSeries['Number of Records Viewed']['data'][$curPeriod] = $summonRecordUsage->numRecordsViewed; | ||
} | ||
if ($stat == 'numRecordsClicked') { | ||
/** @noinspection PhpUndefinedFieldInspection */ | ||
$dataSeries['Number of Records Clicked']['data'][$curPeriod] = $summonRecordUsage->numRecordsUsed; | ||
} | ||
if ($stat == 'totalClicks') { | ||
/** @noinspection PhpUndefinedFieldInspection */ | ||
$dataSeries['Total Clicks']['data'][$curPeriod] = $summonRecordUsage->numClicks; | ||
} | ||
} | ||
} | ||
|
||
$interface->assign('columnLabels', $columnLabels); | ||
$interface->assign('dataSeries', $dataSeries); | ||
$interface->assign('translateDataSeries', true); | ||
$interface->assign('translateColumnLabels', false); | ||
|
||
$interface->assign('graphTitle', $title); | ||
$this->display('usage-graph.tpl', $title); | ||
} | ||
|
||
function getActiveAdminSection(): string { | ||
return 'summon'; | ||
} | ||
|
||
function canView(): bool { | ||
return UserAccount::userHasPermission([ | ||
'View Dashboards', | ||
'View System Reports', | ||
]); | ||
} | ||
|
||
function getBreadcrumbs(): array { | ||
$breadcrumbs = []; | ||
$breadcrumbs[] = new Breadcrumb('/Admin/Home', 'Administration Home'); | ||
$breadcrumbs[] = new Breadcrumb('/Admin/Home#summon', 'Summon'); | ||
$breadcrumbs[] = new Breadcrumb('/Summon/SummonDashboard', 'Summon Usage Dashboard'); | ||
$breadcrumbs[] = new Breadcrumb('', 'Usage Graph'); | ||
return $breadcrumbs; | ||
} | ||
} |