Skip to content

Commit

Permalink
Handle metrics missing pdrid in landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
chuanlin2018 committed Feb 29, 2024
1 parent 066872a commit a45b440
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
67 changes: 37 additions & 30 deletions angular/src/app/landing/landingpage.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,36 +300,7 @@ export class LandingPageComponent implements OnInit, AfterViewInit {
if(event.type == HttpEventType.Response){
this.recordLevelMetrics = JSON.parse(await event.body.text());

let hasFile = false;

if(this.md.components && this.md.components.length > 0){
for(let com of this.md.components) {
if(com.filepath){
hasFile = true;
break;
}
}
}

if(hasFile){
for(let metrics of this.recordLevelMetrics.DataSetMetrics) {
if((!this.pdrid || !metrics["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;

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

this.metricsData.dataReady = true;
this.handleRecordLevelData();
}
},
(err) => {
Expand All @@ -340,6 +311,42 @@ export class LandingPageComponent implements OnInit, AfterViewInit {
});
}

/**
* Handle record level data.
* If only one record in DataSetMetrics, just use it. Otherwise check if pdrid matches
* Nerdm record's pdrid. If yes, use it. Otherwise return false.
* @returns true if there is valid record level data record
*/
handleRecordLevelData() {
let met: any = null;

if(this.recordLevelMetrics.DataSetMetrics) {
if(this.recordLevelMetrics.DataSetMetrics.length > 1) {
for(let metrics of this.recordLevelMetrics.DataSetMetrics) {
if(metrics["pdrid"] && (metrics["pdrid"].toLowerCase() == 'nan' || metrics["pdrid"].trim() == this.pdrid) && metrics["last_time_logged"]){
met = metrics;
}
}
}else if(this.recordLevelMetrics.DataSetMetrics.length == 1){
met = this.recordLevelMetrics.DataSetMetrics[0];
}
}

if(met) {
this.metricsData.totalDatasetDownload = met.record_download;
this.metricsData.totalDownloadSize = met["total_size_download"];
this.metricsData.totalUsers = met.number_users;

this.metricsData.hasCurrentMetrics = true;
this.metricsData.dataReady = true;
this.showMetrics = true;
}else{
this.metricsData.hasCurrentMetrics = false;
this.showMetrics = true;
this.metricsData.dataReady = true;
}
}

/**
* Detect window scroll
*/
Expand Down
1 change: 1 addition & 0 deletions angular/src/app/metrics/metrics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class MetricsComponent implements OnInit {
this.readyDisplay = true;
});
}

/**
* Handle record level data.
* If only one record in DataSetMetrics, just use it. Otherwise check if pdrid matches
Expand Down

0 comments on commit a45b440

Please sign in to comment.