Unverified Commit d4878f4c by Joseph Glass Committed by GitHub

Merge pull request #315 from snac-cooperative/development

Add NARA reports page
parents 75e536df 7a559562
Pipeline #1235 passed with stages
in 15 minutes 55 seconds
......@@ -1932,6 +1932,23 @@ class WebUIExecutor {
$display->setTemplate("report_list_page");
break;
case "nara":
$ask = array(
"command" => "report",
"type" => "nara",
);
$serverResponse = $this->connect->query($ask);
if (!isset($serverResponse["result"]) || $serverResponse["result"] != "success")
return $this->drawErrorPage($serverResponse, $display);
if (isset($this->permissions["ViewAdminDashboard"]) && $this->permissions["ViewAdminDashboard"]) {
$display->setData($serverResponse);
$display->setTemplate("report_nara_stats_page");
} else {
$this->displayPermissionDeniedPage("Admin Dashboard", $display);
}
break;
case "dashboard":
$display->setTemplate("dashboard/reporting");
break;
......
......@@ -160,6 +160,21 @@ $.fn.modal.Constructor.prototype.enforceFocus = $.noop;
</div>
{% endif %}
</div>
<div class="col-md-4">
<!-- Right column -->
{% if permissions.ViewAdminDashboard %}
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title">NARA Reports</h3>
</div>
<div class="panel-body">
<div class="list-group">
<a href="{{control.snacURL}}/reports/nara" class="list-group-item"><i class="fa fa-list fa-fw" aria-hidden="true"></i> NARA Edit Stats</a>
</div>
</div>
</div>
{% endif %}
</div>
</div>
<div class="row">
......
<!DOCTYPE html>
<html>
<head>
<title>Outbound Links Report - Social Networks and Archival Context</title>
<!-- JQuery -->
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>
<!-- Helper Scripts -->
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<!-- Select Upgrades -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/js/select2.min.js"></script>
<link rel="stylesheet" href="{{control.snacURL}}/css/select2-bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<!-- Datatables -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<!-- C3 chart library -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/c3@0.4.18/c3.css">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/c3@0.4.18/c3.min.js"></script>
<!-- SNAC Styles -->
<link rel="stylesheet" href="{{control.snacURL}}/css/snac.css{{control.noCache}}">
<!-- SNAC Javascript -->
<script src="{{control.snacURL}}/javascript/admin.js{{control.noCache}}"></script>
<script src="{{control.snacURL}}/javascript/save_actions.js{{control.noCache}}"></script>
<script src="{{control.snacURL}}/javascript/select_loaders.js{{control.noCache}}"></script>
<script src="{{control.snacURL}}/javascript/scripts.js{{control.noCache}}"></script>
<script src="{{control.snacURL}}/javascript/relation_search.js{{control.noCache}}"></script>
<script src="{{control.snacURL}}/javascript/html2canvas.js{{control.noCache}}"></script>
<script src="{{control.snacURL}}/javascript/feedback.js{{control.noCache}}"></script>
<style>
.theme-dropdown .dropdown-menu {
position: static;
display: block;
margin-bottom: 20px;
}
.snac > p > .btn {
margin: 5px 0;
}
.snac .navbar .container {
width: auto;
}
</style>
</head>
<body role="document">
{% from 'page_navigation.html' import topNavigation,footer %}
{{ topNavigation(X, user, permissions, control) }}
<div class="container snac" role="main">
<h1>NARA Edits Report</h1>
<ol class="breadcrumb">
<li><a href="{{control.snacURL}}/reports/dashboard">Reports</a></li>
<li>NARA Edits Report</li>
</ol>
<div class="row">
<div class="col-md-12">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">NARA Report for {{data.month|replace({", " : ""})}}</h3>
</div>
<div class="panel-body">
<h4>Number of NARA edits in the past month: {{data.naraEditCount}}</h4>
<h4>Number of NARA publishes in the past month: {{data.naraPublishesCount}}</h4>
<h4>Number of referrals from SNAC to National Archive Catalog: {{data.naraReferralsCount}}</h4>
<h4>Number of NARA resources Edited in the past month: {{data.naraEditedResourcesCount}}</h4>
<h4>Total Current Number of NARA resources in SNAC: {{data.naraResourcesCount}}</h4>
</div>
</div>
</div>
</div>
</div>
</div>
{{ footer(X, user, permissions, control) }}
</body>
</html>
......@@ -3976,6 +3976,9 @@ class ServerExecutor {
case "outbound": // Outbound data is generated on the fly, instead of being pulled from a precompiled report
return $this->readAnalytics($input);
break;
case "nara": // NARA data is generated on the fly, instead of being pulled from a precompiled report
return $this->readNaraReport($input);
break;
case "general":
default:
break;
......@@ -4284,9 +4287,9 @@ class ServerExecutor {
}
/**
* Record Analytics by Domain
* Read Analytics by Domain
*
* Record outgoing link traffic hit
* Read outgoing link traffic
*
* @param string[] $input Input array from the Server object
*/
......@@ -4310,4 +4313,21 @@ class ServerExecutor {
$trafficData["total"] = json_encode($visits[2]["Total"]);
return $trafficData;
}
/**
* Get NARA edit counts
*
* Get NARA edits
*
* @param string[] $input Input array from the Server object
*/
public function readNaraReport() {
$naraStats = $this->cStore->readNaraReport();
if (!isset($naraStats)) {
return ["result" => "failure"];
}
$naraStats["result"] = "success";
return $naraStats;
}
}
......@@ -5195,6 +5195,19 @@ class DBUtil
return $visits;
}
/**
* Read NARA Report
*
* Read stats for NARA entities from the last month
*
* @return array $results
*/
public function readNaraReport() {
$results = $this->sql->selectNaraStats();
if (isset($results['naraEditCount']))
return $results;
}
}
......@@ -6889,6 +6889,61 @@ class SQL
return $results;
}
/**
* Select NARA Stats
*
* Read stats for NARA entities from the last month
*
* @return array $results Array of dates and hit counts
*/
public function selectNaraStats() {
// ID 83561837 - Including Jerry's non-NARA account in the stats
$sql = "SELECT to_char((current_date - interval '1' month), 'Month, yyyy') as current_month,
count(*) FROM version_history
WHERE timestamp BETWEEN date_trunc('month', current_date - interval '1' month) AND date_trunc('month', current_date)
AND user_id IN (SELECT id FROM appuser WHERE work_email ilike '%nara.gov' or id = 83561837);";
$result = $this->sdb->query($sql, array());
$naraEditCount = $this->sdb->fetchRow($result);
$sql = "SELECT count(*) FROM version_history
WHERE timestamp BETWEEN date_trunc('month', current_date - interval '1' month) AND date_trunc('month', current_date)
AND status IN ('published') AND user_id IN (SELECT id FROM appuser WHERE work_email ilike '%nara.gov' or id = 83561837);";
$result = $this->sdb->query($sql, array());
$naraPublishesCount = $this->sdb->fetchRow($result);
$sql = "SELECT count(*) FROM outbound_link
WHERE url ilike '%catalog.archives.gov%'
AND timestamp BETWEEN date_trunc('month', current_date - interval '1' month) AND date_trunc('month', current_date);";
$result = $this->sdb->query($sql, array());
$naraReferralsCount = $this->sdb->fetchRow($result);
$sql = "SELECT count(distinct id) FROM resource_cache
WHERE href ilike '%catalog.archives.gov%'
AND updated_at BETWEEN date_trunc('month', current_date - interval '1' month) AND date_trunc('month', current_date);";
$result = $this->sdb->query($sql, array());
$naraEditedResourcesCount = $this->sdb->fetchRow($result);
$sql = "SELECT count(distinct id) FROM resource_cache
WHERE href ilike '%catalog.archives.gov%';";
$result = $this->sdb->query($sql, array());
$naraTotalResourceCount = $this->sdb->fetchRow($result);
$sql = "SELECT count(distinct id) FROM resource_cache
WHERE href ilike '%catalog.archives.gov%' and is_deleted;";
$result = $this->sdb->query($sql, array());
$naraDeletedResourceCount = $this->sdb->fetchRow($result);
$results = [];
$results['month'] = $naraEditCount['current_month'];
$results['naraEditCount'] = $naraEditCount['count'];
$results['naraPublishesCount'] = $naraPublishesCount['count'];
$results['naraReferralsCount'] = $naraReferralsCount['count'];
$results['naraResourcesCount'] = (int) $naraTotalResourceCount['count'] - (int) $naraDeletedResourceCount['count'];
$results['naraEditedResourcesCount'] = $naraEditedResourcesCount['count'];
return $results;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment