Skip to content

Commit

Permalink
Handle multiple pdrids
Browse files Browse the repository at this point in the history
  • Loading branch information
chuanlin2018 committed Jan 9, 2024
1 parent 91f98f5 commit d9e6b02
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 63 deletions.
12 changes: 10 additions & 2 deletions angular/src/app/landing/data-files/data-files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,14 @@ export class DataFilesComponent implements OnInit, OnChanges {
}

isRestrictedData(node: any) {
return node['comp']['@type'].includes('nrdp:RestrictedAccessPage');
if(node){
if(node['comp'])
return node['comp']['@type'].includes('nrdp:RestrictedAccessPage');
else
return false;
}else{
return false;
}
}

checkAccessPageType() {
Expand Down Expand Up @@ -631,7 +638,8 @@ export class DataFilesComponent implements OnInit, OnChanges {
* @returns boolean
*/
isLeaf(fileNode: any) {
return (fileNode.comp['@type'].indexOf('nrdp:DataFile') > -1);
if(!fileNode.comp) return false;
else return (fileNode.comp['@type'].indexOf('nrdp:DataFile') > -1);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions angular/src/app/metrics/metrics.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div style="clear: both;"></div>
<div class="min-height-20">
<span class="float-left">Total dataset downloads</span>
<span class="float-right">{{TotalDatasetDownloads}}</span>
<span class="float-right">{{totalDatasetDownloads}}</span>
</div>
<div style="clear: both;"></div>
<div class="min-height-20">
Expand All @@ -62,7 +62,7 @@
<div style="clear: both;"></div>
<div class="min-height-20">
<span class="float-left">Total unique users</span>
<span class="float-right">{{TotalUniqueUsers}}</span>
<span class="float-right">{{totalUniqueUsers}}</span>
</div>
<div style="clear: both;"></div>
<div class="min-height-20">
Expand Down Expand Up @@ -149,7 +149,7 @@
</div>

<!-- Display file level data summary -->
<div *ngIf="filescount > 0" style="margin: 1em auto 0em auto; width: 100%; text-align: right;font-size: small;padding-right: 45px;">Total No. files: {{filescount}}, Total dataset size: {{TotalFileSize}}</div>
<div *ngIf="filescount > 0" style="margin: 1em auto 0em auto; width: 100%; text-align: right;font-size: small;padding-right: 45px;">Total No. files: {{filescount}}, Total dataset size: {{totalFileSizeForDisplay}}</div>

<!-- Display tree table -->
<div #panel0 id="panel0" *ngIf="inBrowser; else filesLoading" class="flex-container" >
Expand Down
116 changes: 61 additions & 55 deletions angular/src/app/metrics/metrics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class MetricsComponent implements OnInit {

// Data
ediid: string;
pdrid: string;
files: TreeNode[] = [];
fileLevelData: any;
firstTimeLogged: string = '';
Expand All @@ -43,8 +44,12 @@ export class MetricsComponent implements OnInit {
metricsData: any[] = [];
totalFileLevelSuccessfulGet: number = 0;
totalFileSize: number = 0;
totalFileSizeForDisplay: string = "";
totalFilesinChart: number = 0;
noDatasetSummary: boolean = false;
totalDatasetDownloads: number = 0;
totalUniqueUsers: number = 0;
totalDownloadSizeInByte: number = 0;

// Chart
chartData: Array<any>;
Expand Down Expand Up @@ -117,6 +122,7 @@ export class MetricsComponent implements OnInit {
if(md) {
this.record = md as NerdmRes;
this.datasetTitle = md['title'];
this.pdrid = md['@id'];

this.createNewDataHierarchy();
if (this.files.length != 0){
Expand Down Expand Up @@ -181,9 +187,8 @@ export class MetricsComponent implements OnInit {
this.recordLevelData = JSON.parse(await event.body.text());

if(this.recordLevelData.DataSetMetrics != undefined && this.recordLevelData.DataSetMetrics.length > 0){
this.firstTimeLogged = this.datePipe.transform(this.recordLevelData.DataSetMetrics[0].first_time_logged, "MMM d, y");

this.recordLevelTotalDownloads = this.recordLevelData.DataSetMetrics[0].success_get;
this.handleRecordLevelData();

// this.xAxisLabel = "Total Downloads Since " + this.firstTimeLogged;
this.datasetSubtitle = "Metrics Since " + this.firstTimeLogged;
Expand Down Expand Up @@ -244,35 +249,50 @@ export class MetricsComponent implements OnInit {
}, 0);
}


handleRecordLevelData() {
// this.recordLevelTotalDownloads = this.recordLevelData.DataSetMetrics[0].success_get;

for(let metrics of this.recordLevelData.DataSetMetrics) {
if(!this.pdrid || metrics["pdrid"].toLowerCase() == 'nan' || metrics["pdrid"].trim() == this.pdrid){
this.firstTimeLogged = this.datePipe.transform(metrics.first_time_logged, "MMM d, y");
this.recordLevelTotalDownloads = metrics.success_get;
this.totalDatasetDownloads = metrics.record_download;
this.totalUniqueUsers = metrics.number_users;
this.totalDownloadSizeInByte = metrics["total_size_download"];
}
}
}

/**
* Remove outdated data and sha files from the metrics
*/
cleanupFileLevelData(files: TreeNode[]){
let metricsData: any[] = [];

for(let node of files){
let found = this.metricsService.findFileLevelMatch(this.fileLevelData.FilesMetrics, node.data.ediid, node.data.pdrid, node.data.filePath);

if(found){
metricsData.push(found);
node.data.success_get = found.success_get;
if(!node.data.download_size || node.data.download_size == 0){
node.data.download_size = found.download_size;
}
//Only check leaf
if(node.children.length <= 0) {
let found = this.metricsService.findFileLevelMatch(this.fileLevelData.FilesMetrics, node.data.ediid, node.data.pdrid, node.data.filePath);

if(found){
metricsData.push(found);
node.data.success_get = found.success_get;
if(!node.data.download_size || node.data.download_size == 0){
node.data.download_size = found.download_size;
}

this.totalFileLevelSuccessfulGet += found.success_get;
this.totalFilesinChart += 1;
this.totalFileLevelSuccessfulGet += found.success_get;
this.totalFilesinChart += 1;

node.data.inChart = true;
if(node.parent){
node.parent.data.inChart = true;
node.data.inChart = true;
if(node.parent){
node.parent.data.inChart = true;
}
}
}

if(node.children.length > 0){
this.cleanupFileLevelData(node.children);
}else{
this.filescount = this.filescount + 1;
}else {
this.cleanupFileLevelData(node.children);
}
}

Expand All @@ -293,6 +313,8 @@ export class MetricsComponent implements OnInit {
const {downloads, fileSize} = this.sumFolder(child);
this.totalFileSize += fileSize;
}

this.totalFileSizeForDisplay = this.commonFunctionService.formatBytes(this.totalFileSize, 2);
}

/**
Expand All @@ -310,7 +332,13 @@ export class MetricsComponent implements OnInit {
}

var downloads = node.data.success_get;
var fileSize = node.data.download_size;

var fileSize;
if(!node.data.download_size || node.data.download_size == 'nan')
fileSize = 0;
else
fileSize = node.data.download_size;

return {downloads, fileSize};
}

Expand Down Expand Up @@ -343,9 +371,9 @@ export class MetricsComponent implements OnInit {
// Add summary
csv = "# Record id," + this.ediid + "\r\n"
+ "# Total file downloads," + this.recordLevelTotalDownloads + "\r\n"
+ "# Total dataset downloads," + this.TotalDatasetDownloads + "\r\n"
+ "# Total dataset downloads," + this.totalDatasetDownloads + "\r\n"
+ "# Total bytes downloaded," + this.totalDownloadSizeInByte + "\r\n"
+ "# Total unique users," + this.TotalUniqueUsers + "\r\n"
+ "# Total unique users," + this.totalUniqueUsers + "\r\n"
+ "\r\n" + csv;

// Create link and download
Expand All @@ -358,34 +386,12 @@ export class MetricsComponent implements OnInit {
document.body.removeChild(link);
}

/**
* Return total dataset downloads
*/
get TotalDatasetDownloads() {
if(this.recordLevelData.DataSetMetrics[0] != undefined){
return this.recordLevelData.DataSetMetrics[0].record_download;
}else{
return ""
}
}

/**
* Return total download size from file level summary
*/
get TotalFileSize() {
return this.commonFunctionService.formatBytes(this.totalFileSize, 2);
}

/**
* Get total unique users
*/
get TotalUniqueUsers() {
if(this.recordLevelData.DataSetMetrics[0] != undefined){
return this.recordLevelData.DataSetMetrics[0].number_users;
}else{
return ""
}
}
// get TotalFileSize() {
// return this.commonFunctionService.formatBytes(this.totalFileSize, 2);
// }

/**
* Save the bar chart as a png file
Expand Down Expand Up @@ -518,15 +524,15 @@ export class MetricsComponent implements OnInit {
* 01/08/2024 Discussed with Deoyani, use "total_size_download" in record level data.
* No need to add file level data anymore.
*/
get totalDownloadSizeInByte() {
let totalDownload = 0;
// get totalDownloadSizeInByte() {
// let totalDownload = 0;

if(this.recordLevelData != undefined) {
totalDownload += this.recordLevelData.DataSetMetrics[0]["total_size_download"];
}
// if(this.recordLevelData != undefined) {
// totalDownload += this.recordLevelData.DataSetMetrics[0]["total_size_download"];
// }

return totalDownload;
}
// return totalDownload;
// }

/**
* Reture style for Title column of the file tree
Expand Down
5 changes: 2 additions & 3 deletions angular/src/app/shared/metrics-service/metrics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class MetricsService {
*/
findFileLevelMatch(fileLevelData: any, ediid: string, pdrid: string, filepath: string) {
if(!ediid || !pdrid || !filepath) return null;

// Strip off 'ark:/88434/' if any
let _ediid = ediid.replace('ark:/88434/', '');
let _pdrid = pdrid.replace('ark:/88434/', '');
Expand All @@ -74,7 +73,8 @@ export class MetricsService {
}

for(let x of fileLevelData) {
if(_pdrid.toLowerCase() == 'nan') {
// If file's pdrid is "NaN", do not compare pdrid
if(x.pdrid.toLowerCase() == 'nan') {
if((x.filepath? x.filepath.trim()==_filepath : false) && x.ediid.replace('ark:/88434/', '') == _ediid && !x.filepath.endsWith('sha256')) {
ret = x;
break;
Expand All @@ -84,7 +84,6 @@ export class MetricsService {
ret = x;
break;
}

}
}
}
Expand Down

0 comments on commit d9e6b02

Please sign in to comment.