Skip to content

Commit

Permalink
DEV-177
Browse files Browse the repository at this point in the history
  • Loading branch information
Palabola committed Jun 13, 2024
1 parent e219c2c commit 090b072
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/app/pages/server-details/chartOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export const barChartOptions: ChartConfiguration<'bar'>['options'] = {
grid: {
color: '#4B5563',
},
title: {
display: true,
color: '#FFF',
text: 'USD/h',
},
},
},
plugins: {
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/server-details/server-details.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ <h3 class="text-2xl">Availability</h3>
<td>
<div><b>{{item.display_name}}</b> / {{item.api_reference}} </div>
</td>
<td *ngIf="item['spot']"> ${{item['spot'].price}}/{{item['spot'].unit | reduceUnitName}}</td>
<td *ngIf="!item['spot']"> - </td>
<td *ngIf="item['ondemand']"> ${{item['ondemand'].price}}/{{item['ondemand'].unit | reduceUnitName}}</td>
<td *ngIf="!item['ondemand']"> - </td>
<td *ngIf="item['spot'].price"> {{item['spot'].price}}{{item['spot'].currency}}/{{item['spot'].unit | reduceUnitName}}</td>
<td *ngIf="!item['spot'].price"> - </td>
<td *ngIf="item['ondemand'].price"> {{item['ondemand'].price}}{{item['ondemand'].currency}}/{{item['ondemand'].unit | reduceUnitName}}</td>
<td *ngIf="!item['ondemand'].price"> - </td>
</tr>
</tbody>
</table>
Expand Down
20 changes: 14 additions & 6 deletions src/app/pages/server-details/server-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export class ServerDetailsComponent implements OnInit {
});

this.regionFilters = [];

this.serverDetails.prices?.sort((a, b) => a.price - b.price);
this.serverDetails.prices?.forEach((price: ServerPricePKs) => {
const region = this.regionFilters.find((z) => z.region_id === price.region_id);
Expand All @@ -205,6 +206,10 @@ export class ServerDetailsComponent implements OnInit {
this.regionFilters[0].selected = true;
}

if(this.serverDetails.prices?.length > 0 && (this.barChartOptions?.scales as any)?.y?.title?.text) {
(this.barChartOptions!.scales as any).y.title.text = `${this.serverDetails.prices[0].currency}/h`;
}

this.refreshGraphs();

this.title = `${this.serverDetails.display_name} by ${this.serverDetails.vendor.name} - Spare Cores`;
Expand Down Expand Up @@ -441,6 +446,7 @@ export class ServerDetailsComponent implements OnInit {

this.serverDetails.prices.forEach((price: ServerPricePKs) => {
const zone = this.availabilityRegions.find((z) => z.region_id === price.region_id);
const allocation = price.allocation || 'spot';
if(!zone) {
const data: any = {
region_id: price.region_id,
Expand All @@ -449,21 +455,23 @@ export class ServerDetailsComponent implements OnInit {
spot: {
price: 0,
unit: price.unit,
count: 0
count: 0,
currency: price.currency
},
ondemand: {
price: 0,
unit: price.unit,
count: 0
count: 0,
currency: price.currency
}
};
data[price.allocation || 'spot'].price += price.price;
data[price.allocation || 'spot'].count++;
data[allocation].price += price.price;
data[allocation].count++;

this.availabilityRegions.push(data);
} else {
zone[price.allocation || 'spot'].price += price.price;
zone[price.allocation || 'spot'].count++;
zone[allocation].price += price.price;
zone[allocation].count++;
}
});

Expand Down

0 comments on commit 090b072

Please sign in to comment.