From ca9b673d77dde14d9c0218eeefa8928bf0d92426 Mon Sep 17 00:00:00 2001 From: chuanlin2018 Date: Wed, 13 Dec 2023 12:07:12 -0500 Subject: [PATCH 1/5] Handle metrics that has no filepath --- angular/src/app/landing/landingpage.component.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/angular/src/app/landing/landingpage.component.ts b/angular/src/app/landing/landingpage.component.ts index f0c8ed4b..6ad6a271 100644 --- a/angular/src/app/landing/landingpage.component.ts +++ b/angular/src/app/landing/landingpage.component.ts @@ -311,7 +311,10 @@ export class LandingPageComponent implements OnInit, AfterViewInit { 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; + this.metricsData.hasCurrentMetrics = this.fileLevelMetrics.FilesMetrics.find(x => { + x.filepath? x.filepath.substr(x.filepath.indexOf(ediid)+ediid.length+1).trim() == filepath : false + }) != undefined; + if(this.metricsData.hasCurrentMetrics) break; } }else{ From d8b4d24969ca6a87d76b688cd8e22a729e272af7 Mon Sep 17 00:00:00 2001 From: chuanlin2018 Date: Thu, 14 Dec 2023 16:44:21 -0500 Subject: [PATCH 2/5] Handle new metrics structure --- angular/src/app/app.component.ts | 2 +- .../data-files/data-files.component.ts | 2 +- .../src/app/landing/landingpage.component.ts | 10 +---- .../horizontal-barchart.component.ts | 10 ----- angular/src/app/metrics/metrics.component.ts | 15 ++++--- .../shared/metrics-service/metrics.service.ts | 43 +++++++++++++++++++ 6 files changed, 55 insertions(+), 27 deletions(-) diff --git a/angular/src/app/app.component.ts b/angular/src/app/app.component.ts index b1d8b593..e6679fa7 100644 --- a/angular/src/app/app.component.ts +++ b/angular/src/app/app.component.ts @@ -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; diff --git a/angular/src/app/landing/data-files/data-files.component.ts b/angular/src/app/landing/data-files/data-files.component.ts index bb770ed9..64f83400 100644 --- a/angular/src/app/landing/data-files/data-files.component.ts +++ b/angular/src/app/landing/data-files/data-files.component.ts @@ -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; diff --git a/angular/src/app/landing/landingpage.component.ts b/angular/src/app/landing/landingpage.component.ts index 6ad6a271..207b68ba 100644 --- a/angular/src/app/landing/landingpage.component.ts +++ b/angular/src/app/landing/landingpage.component.ts @@ -302,19 +302,13 @@ export class LandingPageComponent implements OnInit, AfterViewInit { // when download is completed 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++){ - let filepath = this.md.components[i].filepath; - if(filepath) filepath = filepath.trim(); + this.metricsData.hasCurrentMetrics = this.metricsService.findFileLevelMatch(this.fileLevelMetrics.FilesMetrics, this.md.ediid, this.md['@id'],this.md.components[i].filepath); - this.metricsData.hasCurrentMetrics = this.fileLevelMetrics.FilesMetrics.find(x => { - x.filepath? x.filepath.substr(x.filepath.indexOf(ediid)+ediid.length+1).trim() == filepath : false - }) != undefined; - if(this.metricsData.hasCurrentMetrics) break; } }else{ diff --git a/angular/src/app/metrics/horizontal-barchart/horizontal-barchart.component.ts b/angular/src/app/metrics/horizontal-barchart/horizontal-barchart.component.ts index 889b0674..debf0c0d 100644 --- a/angular/src/app/metrics/horizontal-barchart/horizontal-barchart.component.ts +++ b/angular/src/app/metrics/horizontal-barchart/horizontal-barchart.component.ts @@ -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) diff --git a/angular/src/app/metrics/metrics.component.ts b/angular/src/app/metrics/metrics.component.ts index ccef3a60..d862be18 100644 --- a/angular/src/app/metrics/metrics.component.ts +++ b/angular/src/app/metrics/metrics.component.ts @@ -136,7 +136,6 @@ export class MetricsComponent implements OnInit { this.cleanupFileLevelData(this.files); this.fileLevelData.FilesMetrics = this.metricsData; this.handleSum(this.files); - if(this.fileLevelData.FilesMetrics.length > 0){ this.noChartData = false; this.createChartData(); @@ -252,7 +251,8 @@ export class MetricsComponent implements OnInit { let metricsData: any[] = []; for(let node of files){ - let found = this.fileLevelData.FilesMetrics.find(x => x.filepath.substr(x.filepath.indexOf(this.ediid)+this.ediid.length).trim() == node.data.filePath.trim() && !x.filepath.endsWith('sha256')); + 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; @@ -498,9 +498,9 @@ export class MetricsComponent implements OnInit { */ getLastDownloadDate(){ if (this.fileLevelData.FilesMetrics.length) { - var lastDownloadTime = this.fileLevelData.FilesMetrics.reduce((m,v,i) => (v.timestamp > m.timestamp) && i ? v : m).timestamp; + var lastDownloadTime = this.fileLevelData.FilesMetrics.reduce((m,v,i) => (v.last_time_logged > m.last_time_logged) && i ? v : m).last_time_logged; - return this.datePipe.transform(this.fileLevelData.FilesMetrics.reduce((m,v,i) => (v.timestamp > m.timestamp) && i ? v : m).timestamp, "MMM d, y"); + return this.datePipe.transform(this.fileLevelData.FilesMetrics.reduce((m,v,i) => (v.last_time_logged > m.last_time_logged) && i ? v : m).last_time_logged, "MMM d, y"); } } @@ -523,7 +523,7 @@ export class MetricsComponent implements OnInit { let totalDownload = 0; if(this.fileLevelData != undefined) { this.fileLevelData.FilesMetrics.forEach( (file) => { - totalDownload += file.success_get * file.download_size; + totalDownload += file.success_get * file.total_size_download; }); } @@ -604,7 +604,7 @@ export class MetricsComponent implements OnInit { createNewDataHierarchy() { var testdata: TreeNode = {} if (this.record['components'] != null) { - testdata["data"] = this.arrangeIntoTree(this.record['components']); + testdata["data"] = this.arrangeIntoTree(this.record['components'], this.record['@id']); this.files.push(testdata); } } @@ -614,7 +614,7 @@ export class MetricsComponent implements OnInit { * @param paths * @returns */ - private arrangeIntoTree(paths) { + private arrangeIntoTree(paths, pdrid) { const tree: TreeNode[] = []; // This example uses the underscore.js library. var i = 1; @@ -647,6 +647,7 @@ export class MetricsComponent implements OnInit { data: { cartId: tempId, ediid: this.ediid, + pdrid: pdrid, name: part, mediatype: path.mediaType, size: path.size, diff --git a/angular/src/app/shared/metrics-service/metrics.service.ts b/angular/src/app/shared/metrics-service/metrics.service.ts index 56c276d2..58c68b5b 100644 --- a/angular/src/app/shared/metrics-service/metrics.service.ts +++ b/angular/src/app/shared/metrics-service/metrics.service.ts @@ -22,6 +22,11 @@ export class MetricsService { } + /** + * Request file level metrics data based on ediid + * @param ediid + * @returns http response + */ getFileLevelMetrics(ediid: string): Observable { let url = this.metricsBackend + "files?exclude=_id&include=ediid,filepath,success_get,download_size&ediid=" + ediid; @@ -32,6 +37,11 @@ export class MetricsService { return this.http.request(request); } + /** + * Request record level metrics data based on ediid + * @param ediid + * @returns http response + */ getRecordLevelMetrics(ediid: string): Observable { let url = this.metricsBackend + "records/" + ediid; @@ -41,4 +51,37 @@ export class MetricsService { return this.http.request(request); } + + /** + * Find a match of metrics data based on given ediid, pdrid and filepath. Ignore sha files. + * @param fileLevelData File level metrics data returned from getFileLevelMetrics() + * @param ediid ediid in nerdm record to find a match + * @param pdrid pdrid in nerdm record to find a match + * @param filepath filepath in nerdm record to find a match + * @returns metrics data if a match found. Otherwise return null. + */ + 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/', ''); + let _filepath = filepath.trim(); + let ret: any = null; + if(fileLevelData){ + if(_filepath) { + if(filepath[0]=="/") _filepath = filepath.slice(1); + _filepath = _filepath.trim(); + } + + for(let x of fileLevelData) { + if(x.pdrid.replace('ark:/88434/', '') == _pdrid.replace('ark:/88434/', '') && x.ediid.replace('ark:/88434/', '') == _ediid && (x.filepath? x.filepath.trim()==_filepath : false) && !x.filepath.endsWith('sha256')) { + ret = x; + break; + } + } + } + + return ret; + } } From 91f98f5bec2768b8aa5308eb7836c62ac60bf058 Mon Sep 17 00:00:00 2001 From: chuanlin2018 Date: Mon, 8 Jan 2024 14:58:37 -0500 Subject: [PATCH 3/5] Fixed the calculation of total download size --- .../src/app/landing/landingpage.component.ts | 11 ++++------- angular/src/app/metrics/metrics.component.ts | 7 ++----- .../shared/metrics-service/metrics.service.ts | 17 ++++++++++++----- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/angular/src/app/landing/landingpage.component.ts b/angular/src/app/landing/landingpage.component.ts index a2173a62..1f2071fd 100644 --- a/angular/src/app/landing/landingpage.component.ts +++ b/angular/src/app/landing/landingpage.component.ts @@ -250,9 +250,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); @@ -304,12 +301,12 @@ export class LandingPageComponent implements OnInit, AfterViewInit { let hasFile = false; if(this.md.components && this.md.components.length > 0){ - this.md.components.forEach(element => { - if(element.filepath){ + for(let com of this.md.components) { + if(com.filepath){ hasFile = true; - return; + break; } - }); + } } if(hasFile){ diff --git a/angular/src/app/metrics/metrics.component.ts b/angular/src/app/metrics/metrics.component.ts index 9bdfec6d..2c0a7d46 100644 --- a/angular/src/app/metrics/metrics.component.ts +++ b/angular/src/app/metrics/metrics.component.ts @@ -515,14 +515,11 @@ export class MetricsComponent implements OnInit { /** * Get total recordset level download size in bytes + * 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; - if(this.fileLevelData != undefined) { - this.fileLevelData.FilesMetrics.forEach( (file) => { - totalDownload += file.success_get * file.total_size_download; - }); - } if(this.recordLevelData != undefined) { totalDownload += this.recordLevelData.DataSetMetrics[0]["total_size_download"]; diff --git a/angular/src/app/shared/metrics-service/metrics.service.ts b/angular/src/app/shared/metrics-service/metrics.service.ts index 58c68b5b..8f393e48 100644 --- a/angular/src/app/shared/metrics-service/metrics.service.ts +++ b/angular/src/app/shared/metrics-service/metrics.service.ts @@ -28,8 +28,7 @@ export class MetricsService { * @returns http response */ getFileLevelMetrics(ediid: string): Observable { - let url = this.metricsBackend + "files?exclude=_id&include=ediid,filepath,success_get,download_size&ediid=" + ediid; - + let url = this.metricsBackend + "files/" + ediid; const request = new HttpRequest( "GET", url, { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'responseType': 'blob' }), reportProgress: true, responseType: 'blob' }); @@ -75,9 +74,17 @@ export class MetricsService { } for(let x of fileLevelData) { - if(x.pdrid.replace('ark:/88434/', '') == _pdrid.replace('ark:/88434/', '') && x.ediid.replace('ark:/88434/', '') == _ediid && (x.filepath? x.filepath.trim()==_filepath : false) && !x.filepath.endsWith('sha256')) { - ret = x; - break; + if(_pdrid.toLowerCase() == 'nan') { + if((x.filepath? x.filepath.trim()==_filepath : false) && x.ediid.replace('ark:/88434/', '') == _ediid && !x.filepath.endsWith('sha256')) { + ret = x; + break; + } + }else { + if(x.pdrid.replace('ark:/88434/', '') == _pdrid && x.ediid.replace('ark:/88434/', '') == _ediid && (x.filepath? x.filepath.trim()==_filepath : false) && !x.filepath.endsWith('sha256')) { + ret = x; + break; + } + } } } From d9e6b025603e4e1d9a54cceaf783426c75aeb9eb Mon Sep 17 00:00:00 2001 From: chuanlin2018 Date: Tue, 9 Jan 2024 13:16:33 -0500 Subject: [PATCH 4/5] Handle multiple pdrids --- .../data-files/data-files.component.ts | 12 +- .../src/app/metrics/metrics.component.html | 6 +- angular/src/app/metrics/metrics.component.ts | 116 +++++++++--------- .../shared/metrics-service/metrics.service.ts | 5 +- 4 files changed, 76 insertions(+), 63 deletions(-) diff --git a/angular/src/app/landing/data-files/data-files.component.ts b/angular/src/app/landing/data-files/data-files.component.ts index 64f83400..6b6662b1 100644 --- a/angular/src/app/landing/data-files/data-files.component.ts +++ b/angular/src/app/landing/data-files/data-files.component.ts @@ -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() { @@ -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); } /** diff --git a/angular/src/app/metrics/metrics.component.html b/angular/src/app/metrics/metrics.component.html index 1579e2e2..d1d3a28a 100644 --- a/angular/src/app/metrics/metrics.component.html +++ b/angular/src/app/metrics/metrics.component.html @@ -52,7 +52,7 @@
Total dataset downloads - {{TotalDatasetDownloads}} + {{totalDatasetDownloads}}
@@ -62,7 +62,7 @@
Total unique users - {{TotalUniqueUsers}} + {{totalUniqueUsers}}
@@ -149,7 +149,7 @@
-
Total No. files: {{filescount}}, Total dataset size: {{TotalFileSize}}
+
Total No. files: {{filescount}}, Total dataset size: {{totalFileSizeForDisplay}}
diff --git a/angular/src/app/metrics/metrics.component.ts b/angular/src/app/metrics/metrics.component.ts index 2c0a7d46..917e6ea0 100644 --- a/angular/src/app/metrics/metrics.component.ts +++ b/angular/src/app/metrics/metrics.component.ts @@ -32,6 +32,7 @@ export class MetricsComponent implements OnInit { // Data ediid: string; + pdrid: string; files: TreeNode[] = []; fileLevelData: any; firstTimeLogged: string = ''; @@ -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; @@ -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){ @@ -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; @@ -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); } } @@ -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); } /** @@ -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}; } @@ -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 @@ -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 @@ -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 diff --git a/angular/src/app/shared/metrics-service/metrics.service.ts b/angular/src/app/shared/metrics-service/metrics.service.ts index 8f393e48..fb21b3ce 100644 --- a/angular/src/app/shared/metrics-service/metrics.service.ts +++ b/angular/src/app/shared/metrics-service/metrics.service.ts @@ -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/', ''); @@ -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; @@ -84,7 +84,6 @@ export class MetricsService { ret = x; break; } - } } } From 9cb10b3b88223b9974562e448c0fabb6ec569699 Mon Sep 17 00:00:00 2001 From: chuanlin2018 Date: Wed, 10 Jan 2024 11:57:09 -0500 Subject: [PATCH 5/5] Check last_time_logged to select correct record. Add same logic to landing page as well. --- .../src/app/landing/landingpage.component.ts | 18 ++++++++++++------ angular/src/app/metrics/metrics.component.ts | 3 +-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/angular/src/app/landing/landingpage.component.ts b/angular/src/app/landing/landingpage.component.ts index 1f2071fd..2b01c215 100644 --- a/angular/src/app/landing/landingpage.component.ts +++ b/angular/src/app/landing/landingpage.component.ts @@ -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'; @@ -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){ @@ -310,12 +312,16 @@ export class LandingPageComponent implements OnInit, AfterViewInit { } 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; - - this.metricsData.totalUsers = this.recordLevelMetrics.DataSetMetrics[0] != undefined? this.recordLevelMetrics.DataSetMetrics[0].number_users : 0; + 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; + + this.metricsData.totalUsers = metrics != undefined? metrics.number_users : 0; + } + } this.metricsData.totalUsers = this.metricsData.totalUsers == undefined? 0 : this.metricsData.totalUsers; diff --git a/angular/src/app/metrics/metrics.component.ts b/angular/src/app/metrics/metrics.component.ts index 917e6ea0..fb932e58 100644 --- a/angular/src/app/metrics/metrics.component.ts +++ b/angular/src/app/metrics/metrics.component.ts @@ -185,7 +185,6 @@ export class MetricsComponent implements OnInit { case HttpEventType.Response: // this.recordLevelData = JSON.parse(JSON.stringify(event.body)); this.recordLevelData = JSON.parse(await event.body.text()); - if(this.recordLevelData.DataSetMetrics != undefined && this.recordLevelData.DataSetMetrics.length > 0){ this.handleRecordLevelData(); @@ -254,7 +253,7 @@ export class MetricsComponent implements OnInit { // 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){ + if((!this.pdrid || metrics["pdrid"].toLowerCase() == 'nan' || metrics["pdrid"].trim() == this.pdrid) && metrics["last_time_logged"]){ this.firstTimeLogged = this.datePipe.transform(metrics.first_time_logged, "MMM d, y"); this.recordLevelTotalDownloads = metrics.success_get; this.totalDatasetDownloads = metrics.record_download;