Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle metrics that has no filepath #323

Merged
merged 7 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AppComponent {
this.gaCode = this.cfg.get("gaCode", "") as string;
this.ga4Code = this.cfg.get("ga4Code", "") as string;
let homeurl = this.cfg.get("locations.portalBase", "data.nist.gov") as string;
console.log('homeurl', homeurl);

const url = new URL(homeurl);
this.hostName = url.hostname;

Expand Down
14 changes: 11 additions & 3 deletions angular/src/app/landing/data-files/data-files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class DataFilesComponent implements OnInit, OnChanges {
}

this.buildTree();
console.log("files", this.files);

// If total file count > virtual scrolling threshold, set virtual scrolling to true.
this.virtualScroll = this.fileCount > FileCountForVirtualScroll? true : false;

Expand All @@ -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
86 changes: 29 additions & 57 deletions angular/src/app/landing/landingpage.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { Themes, ThemesPrefs } from '../shared/globals/globals';
encapsulation: ViewEncapsulation.None
})
export class LandingPageComponent implements OnInit, AfterViewInit {
pdrid: string;
layoutCompact: boolean = true;
layoutMode: string = 'horizontal';
profileMode: string = 'inline';
Expand Down Expand Up @@ -223,6 +224,7 @@ export class LandingPageComponent implements OnInit, AfterViewInit {
metadataError = "not-found";
}
else{
this.pdrid = this.md["@id"];
this.theme = ThemesPrefs.getTheme((new NERDResource(this.md)).theme());

if(this.inBrowser){
Expand Down Expand Up @@ -250,9 +252,6 @@ export class LandingPageComponent implements OnInit, AfterViewInit {

if (this.editRequested) {
showError = false;
// console.log("Returning from authentication redirection (editmode="+
// this.editRequested+")");

// Need to pass reqID (resID) because the resID in editControlComponent
// has not been set yet and the startEditing function relies on it.
this.edstatsvc.startEditing(this.reqId);
Expand Down Expand Up @@ -297,74 +296,47 @@ export class LandingPageComponent implements OnInit, AfterViewInit {
getMetrics() {
let ediid = this.md.ediid;

this.metricsService.getFileLevelMetrics(ediid).subscribe(async (event) => {
// Some large dataset might take a while to download. Only handle the response
// when download is completed
this.metricsService.getRecordLevelMetrics(ediid).subscribe(async (event) => {
if(event.type == HttpEventType.Response){
let response = await event.body.text();
this.recordLevelMetrics = JSON.parse(await event.body.text());

this.fileLevelMetrics = JSON.parse(response);
let hasFile = false;

if(this.fileLevelMetrics.FilesMetrics != undefined && this.fileLevelMetrics.FilesMetrics.length > 0 && this.md.components){
// check if there is any current metrics data
for(let i = 1; i < this.md.components.length; i++){
let filepath = this.md.components[i].filepath;
if(filepath) filepath = filepath.trim();

this.metricsData.hasCurrentMetrics = this.fileLevelMetrics.FilesMetrics.find(x => x.filepath.substr(x.filepath.indexOf(ediid)+ediid.length+1).trim() == filepath) != undefined;
if(this.metricsData.hasCurrentMetrics) break;
if(this.md.components && this.md.components.length > 0){
for(let com of this.md.components) {
if(com.filepath){
hasFile = true;
break;
}
}
}else{
this.metricsData.hasCurrentMetrics = false;
}

if(this.metricsData.hasCurrentMetrics){
this.metricsService.getRecordLevelMetrics(ediid).subscribe(async (event) => {
if(event.type == HttpEventType.Response){
this.recordLevelMetrics = JSON.parse(await event.body.text());
if(hasFile){
for(let metrics of this.recordLevelMetrics.DataSetMetrics) {
if((!this.pdrid || metrics["pdrid"].toLowerCase() == 'nan' || metrics["pdrid"].trim() == this.pdrid) && metrics["last_time_logged"]){
//Now check if there is any metrics data
this.metricsData.totalDatasetDownload = metrics != undefined? metrics.record_download : 0;

this.metricsData.totalDownloadSize = metrics != undefined? metrics["total_size_download"] : 0;

let hasFile = false;

if(this.md.components && this.md.components.length > 0){
this.md.components.forEach(element => {
if(element.filepath){
hasFile = true;
return;
}
});
}

if(hasFile){
//Now check if there is any metrics data
this.metricsData.totalDatasetDownload = this.recordLevelMetrics.DataSetMetrics[0] != undefined? this.recordLevelMetrics.DataSetMetrics[0].record_download : 0;

this.metricsData.totalDownloadSize = this.recordLevelMetrics.DataSetMetrics[0] != undefined? this.recordLevelMetrics.DataSetMetrics[0].record_download * this.datasetSize : 0;

this.metricsData.totalUsers = this.recordLevelMetrics.DataSetMetrics[0] != undefined? this.recordLevelMetrics.DataSetMetrics[0].number_users : 0;

this.metricsData.totalUsers = this.metricsData.totalUsers == undefined? 0 : this.metricsData.totalUsers;
}

this.metricsData.dataReady = true;
this.metricsData.totalUsers = metrics != undefined? metrics.number_users : 0;
}
},
(err) => {
console.error("Failed to retrieve dataset metrics: ", err);
this.metricsData.hasCurrentMetrics = false;
this.showMetrics = true;
this.metricsData.dataReady = true;
});
}else{
this.metricsData.dataReady = true;
}

this.metricsData.totalUsers = this.metricsData.totalUsers == undefined? 0 : this.metricsData.totalUsers;

this.metricsData.hasCurrentMetrics = true;
this.showMetrics = true;
}
this.showMetrics = true;

this.metricsData.dataReady = true;
}
},
(err) => {
console.error("Failed to retrieve file metrics: ", err);
console.error("Failed to retrieve dataset metrics: ", err);
this.metricsData.hasCurrentMetrics = false;
this.showMetrics = true;
this.metricsData.dataReady = true; // ready to display message
this.metricsData.dataReady = true;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,6 @@ export class HorizontalBarchartComponent implements OnInit {
.attr('opacity', 0.6)
.style('fill', '#00e68a')

// draw a yellow dash line at the end of the active bar
// line style is defined in line#limit
chart.append('line')
.attr('id', 'limit')
.attr('x1', xScale(actual[1]))
.attr('y1', 0)
.attr('x2', xScale(actual[1]))
.attr('y2', height)
.attr('stroke', 'red')

d3.selectAll('.label')
.filter(function(d) { return d[0] == actual[0]; })
.attr('opacity', 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
8 changes: 4 additions & 4 deletions angular/src/app/metrics/metrics.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let fileLevelData = {
"FilesMetrics": [
{
"ediid": "3A1EE2F169DD3B8CE0531A570681DB5D1491",
"filepath": "3A1EE2F169DD3B8CE0531A570681DB5D1491/1491_optSortSph20160701.m",
"filepath": "1491_optSortSph20160701.m",
"success_head": 0,
"success_get": 103,
"failure_head": 0,
Expand All @@ -30,7 +30,7 @@ let fileLevelData = {
},
{
"ediid": "3A1EE2F169DD3B8CE0531A570681DB5D1491",
"filepath": "3A1EE2F169DD3B8CE0531A570681DB5D1491/sub1/1491_optSortSphEvaluated20160701.cdf",
"filepath": "sub1/1491_optSortSphEvaluated20160701.cdf",
"success_head": 0,
"success_get": 73,
"failure_head": 0,
Expand All @@ -42,7 +42,7 @@ let fileLevelData = {
},
{
"ediid": "3A1EE2F169DD3B8CE0531A570681DB5D1491",
"filepath": "3A1EE2F169DD3B8CE0531A570681DB5D1491/1491_optSortSphEvaluated20160701.cdf",
"filepath": "1491_optSortSphEvaluated20160701.cdf",
"success_head": 0,
"success_get": 206,
"failure_head": 0,
Expand All @@ -54,7 +54,7 @@ let fileLevelData = {
},
{
"ediid": "3A1EE2F169DD3B8CE0531A570681DB5D1491",
"filepath": "3A1EE2F169DD3B8CE0531A570681DB5D1491/sub2/looooooooooooooooooooooooooooooooooooooooong_name_1491_optSortSphEvaluated20160701.cdf",
"filepath": "sub2/looooooooooooooooooooooooooooooooooooooooong_name_1491_optSortSphEvaluated20160701.cdf",
"success_head": 0,
"success_get": 207,
"failure_head": 0,
Expand Down
Loading
Loading