Skip to content

Commit

Permalink
formatting values
Browse files Browse the repository at this point in the history
  • Loading branch information
Palabola committed Jun 11, 2024
1 parent 55e180f commit 0de0457
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/app/pages/server-compare/server-compare.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ <h1 class="text-white font-bold text-3xl">Server Comparison</h1>
</tr>
<ng-container *ngIf="!item.collapsed" >
<tr *ngFor="let config of item.configs">
<td>
<div [innerHTML]="serializeConfig(config.config)" ></div></td>
<td *ngFor="let value of config.values">
{{value}}
<td >
<div class="ml-2" [innerHTML]="serializeConfig(config.config)" ></div></td>
<td *ngFor="let value of config.values" [style]="isBestStyle(value, config.values, item)">
{{numberWithCommas(value)}}
</td>
</tr>
</ng-container>
Expand Down
24 changes: 23 additions & 1 deletion src/app/pages/server-compare/server-compare.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ export class ServerCompareComponent implements OnInit {
});
});

console.log(this.benchmarkMeta);

this.benchmarkMeta.forEach((benchmark: any) => {
benchmark.configs.forEach((config: any) => {
this.servers.forEach((server: any) => {
const score = server.benchmark_scores
?.find((s: any) => s.benchmark_id === benchmark.benchmark_id && JSON.stringify(s.config) === JSON.stringify(config.config));
config.values.push(
score ? score.score : '-'
score ? (Math.floor(score.score * 100) / 100) : '-'
);
});
});
Expand Down Expand Up @@ -306,6 +308,22 @@ export class ServerCompareComponent implements OnInit {
return isBest ? this.bestCellStyle : '';
}

isBestStyle(value: any, values: any[], benchmark: any) {
if(value === '-' || value === 0) return '';
let isBest = true;
values.forEach((v) => {
if(!isNaN(v)) {
if(benchmark.higher_is_better === false && v < value) {
isBest = false;
} else if(v > value) {
isBest = false;
}
}
});

return isBest ? this.bestCellStyle : '';
}

viewServer(server: ServerPKsWithPrices) {
window.open(`/server/${server.vendor_id}/${server.api_reference}`, '_blank');
}
Expand Down Expand Up @@ -369,4 +387,8 @@ export class ServerCompareComponent implements OnInit {
return result;
}

public numberWithCommas(x: number) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

}

0 comments on commit 0de0457

Please sign in to comment.