import { Component, Input, OnInit, OnChanges } from '@angular/core'; import { ServerLocation } from '@creedinteractive/onguard-models'; @Component({ selector: 'onguard-server-location-card', templateUrl: './server-location-card.component.html', styleUrls: ['./server-location-card.component.scss'], }) export class ServerLocationCardComponent implements OnInit, OnChanges { @Input() data: ServerLocation; @Input() unitGrowth = false; chartData: any[] = []; loadGrade: 'good' | 'fair' | 'bad'; predictionLoadGrade: 'good' | 'fair' | 'bad'; constructor() {} ngOnInit(): void { if (this.unitGrowth) { this.data.params.growth = 1; } this.chartData.push({ name: 'Free Tokens', quantity: this.data.freeMediaTokenCapacity, id: 1, }); this.chartData.push({ name: 'Used Tokens', quantity: this.data.mediaTokensUsed, id: 2, }); this.loadGrade = this.getGradeForScore(this.data.mediaLoad); } ngOnChanges() { if (this.data && this.data.prediction) { this.predictionLoadGrade = this.getGradeForScore(this.data.prediction.ml / 100); } } getGradeForScore(score: number) { if (score < 0.65) { return 'good'; } else if (score < 0.75) { return 'fair'; } else { return 'bad'; } } }