Skip to content

Commit

Permalink
Merged PR320 changes into this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
chuanlin2018 committed Jan 4, 2024
2 parents d8b4d24 + d692bbb commit 1e9373c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 70 deletions.
78 changes: 25 additions & 53 deletions angular/src/app/landing/landingpage.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,71 +297,43 @@ 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.fileLevelMetrics = JSON.parse(response);
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++){
this.metricsData.hasCurrentMetrics = this.metricsService.findFileLevelMatch(this.fileLevelMetrics.FilesMetrics, this.md.ediid, this.md['@id'],this.md.components[i].filepath);

if(this.metricsData.hasCurrentMetrics) break;
}
}else{
this.metricsData.hasCurrentMetrics = false;
}
this.recordLevelMetrics = JSON.parse(await event.body.text());

let hasFile = 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(this.md.components && this.md.components.length > 0){
this.md.components.forEach(element => {
if(element.filepath){
hasFile = true;
return;
}
});
}

let hasFile = false;
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]["total_size_download"] : 0;

if(this.md.components && this.md.components.length > 0){
this.md.components.forEach(element => {
if(element.filepath){
hasFile = true;
return;
}
});
}
this.metricsData.totalUsers = this.recordLevelMetrics.DataSetMetrics[0] != undefined? this.recordLevelMetrics.DataSetMetrics[0].number_users : 0;

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.totalUsers = this.metricsData.totalUsers == undefined? 0 : this.metricsData.totalUsers;

this.metricsData.dataReady = true;
}
},
(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.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
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
23 changes: 10 additions & 13 deletions angular/src/app/metrics/metrics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ export class MetricsComponent implements OnInit {
*/
handleSum(files: TreeNode[]){
this.totalFileSize = 0;
files.forEach(child => {
for(let child of files) {
const {downloads, fileSize} = this.sumFolder(child);
this.totalFileSize += fileSize;
})
}
}

/**
Expand All @@ -302,11 +302,11 @@ export class MetricsComponent implements OnInit {
*/
sumFolder(node: TreeNode){
if (node.children.length > 0) {
node.children.forEach(child => {
for(let child of node.children) {
const {downloads, fileSize} = this.sumFolder(child);
node.data.success_get += downloads;
node.data.download_size += fileSize;
});
};
}

var downloads = node.data.success_get;
Expand Down Expand Up @@ -448,7 +448,7 @@ export class MetricsComponent implements OnInit {
filenameDisp = "..." + filename.substr(filename.length - this.maxLabelLength);
}

filenameWithPath = this.fileLevelData.FilesMetrics[i].filepath.substr(this.fileLevelData.FilesMetrics[i].filepath.indexOf(this.ediid)+this.ediid.length+1);
filenameWithPath = this.fileLevelData.FilesMetrics[i].filepath;
filenameWithPath = decodeURI(filenameWithPath);
filenameWithPath = '/' + filenameWithPath.replace(new RegExp('%20', 'g'), " ").trim();
filenameWithPathDisp = filenameWithPath;
Expand Down Expand Up @@ -487,9 +487,6 @@ export class MetricsComponent implements OnInit {
}
}
}

// var sum = this.chartData.reduce((sum, current) => sum + current[1], 0);
// this.recordLevelTotalDownloads = sum;
}

/**
Expand Down Expand Up @@ -528,7 +525,7 @@ export class MetricsComponent implements OnInit {
}

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

return totalDownload;
Expand Down Expand Up @@ -620,7 +617,7 @@ export class MetricsComponent implements OnInit {
var i = 1;
var tempfiletest = "";

paths.forEach((path) => {
for(let path of paths) {
//Remove hidden type files and sha files
if (path.filepath && !path['@type'].includes('nrd:Hidden') && !path.filepath.endsWith('sha256')) {
if (!path.filepath.startsWith("/"))
Expand All @@ -630,7 +627,7 @@ export class MetricsComponent implements OnInit {
pathParts.shift(); // Remove first blank element from the parts array.
let currentLevel = tree; // initialize currentLevel to root

pathParts.forEach((part) => {
for(let part of pathParts) {
// check to see if the path already exists.
const existingPath = currentLevel.filter(level => level.data.name === part);
if (existingPath.length > 0) {
Expand Down Expand Up @@ -667,10 +664,10 @@ export class MetricsComponent implements OnInit {
currentLevel.push(newPart);
currentLevel = newPart.children;
}
});
};
}
i = i + 1;
});
};
return tree;
}

Expand Down

0 comments on commit 1e9373c

Please sign in to comment.