Skip to content

Commit 07515df

Browse files
committed
Refactor SKU mapping in UsageReportService
1 parent 5c81976 commit 07515df

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

src/app/usage-report.service.ts

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const readGithubUsageReport = async (data: string, cb?: (usageReport: UsageRepor
2222
continue;
2323
}
2424
const csv = line.split(',');
25-
const [year, month, day] = csv[0].split("-").map(Number);
25+
const [year, month, day] = csv[0].split(/-|\//).map(Number);
2626
const date = new Date(year, month - 1, day);
2727
const data: UsageReportLine = {
2828
date,
@@ -77,7 +77,7 @@ export class UsageReportService {
7777
usageReportData!: string;
7878
usageReport!: CustomUsageReport;
7979
usageReportFiltered: BehaviorSubject<CustomUsageReportLine[]> = new BehaviorSubject<CustomUsageReportLine[]>([]);
80-
usageReportFilteredProduct: {[key: string]: Observable<CustomUsageReportLine[]>} = {};
80+
usageReportFilteredProduct: { [key: string]: Observable<CustomUsageReportLine[]> } = {};
8181
filters: Filter = {
8282
startDate: new Date(),
8383
endDate: new Date(),
@@ -92,6 +92,39 @@ export class UsageReportService {
9292
products: string[] = [];
9393
usernames: string[] = [];
9494
valueType: BehaviorSubject<'minutes' | 'cost'> = new BehaviorSubject<'minutes' | 'cost'>('cost')
95+
skuMapping: { [key: string]: string } = {
96+
"Compute - UBUNTU": 'Ubuntu 2',
97+
"Compute - UBUNTU_16_CORE": 'Ubuntu 16',
98+
"Compute - UBUNTU_16_CORE_ARM": 'Ubuntu 16 (ARM)',
99+
"Compute - UBUNTU_2_CORE_ARM": 'Ubuntu 2 (ARM)',
100+
"Compute - UBUNTU_32_CORE": 'Ubuntu 32',
101+
"Compute - UBUNTU_32_CORE_ARM": 'Ubuntu 32 (ARM)',
102+
"Compute - UBUNTU_4_CORE": 'Ubuntu 4',
103+
"Compute - UBUNTU_4_CORE_ARM": 'Ubuntu 4 (ARM)',
104+
"Compute - UBUNTU_4_CORE_GPU": 'Ubuntu 4 (GPU)',
105+
"Compute - UBUNTU_64_CORE": 'Ubuntu 64',
106+
"Compute - UBUNTU_64_CORE_ARM": 'Ubuntu 64 (ARM)',
107+
"Compute - UBUNTU_8_CORE": 'Ubuntu 8',
108+
"Compute - UBUNTU_8_CORE_ARM": 'Ubuntu 8 (ARM)',
109+
"Compute - MACOS": 'MacOS 3',
110+
"Compute - MACOS_12_CORE": 'MacOS 12',
111+
"Compute - MACOS_8_CORE": 'MacOS 8',
112+
"Compute - MACOS_LARGE": 'MacOS 12 (x86)',
113+
"Compute - MACOS_XLARGE": 'MacOS 6 (M1)',
114+
"Compute - WINDOWS": 'Windows 2',
115+
"Compute - WINDOWS_16_CORE": 'Windows 16',
116+
"Compute - WINDOWS_16_CORE_ARM": 'Windows 16 (ARM)',
117+
"Compute - WINDOWS_2_CORE_ARM": 'Windows 2 (ARM)',
118+
"Compute - WINDOWS_32_CORE": 'Windows 32',
119+
"Compute - WINDOWS_32_CORE_ARM": 'Windows 32 (ARM)',
120+
"Compute - WINDOWS_4_CORE": 'Windows 4',
121+
"Compute - WINDOWS_4_CORE_ARM": 'Windows 4 (ARM)',
122+
"Compute - WINDOWS_4_CORE_GPU": 'Windows 4 (GPU)',
123+
"Compute - WINDOWS_64_CORE": 'Windows 64',
124+
"Compute - WINDOWS_64_CORE_ARM": 'Windows 64 (ARM)',
125+
"Compute - WINDOWS_8_CORE": 'Windows 8',
126+
"Compute - WINDOWS_8_CORE_ARM": 'Windows 8 (ARM)',
127+
};
95128
skuOrder = [
96129
'Compute - UBUNTU',
97130
'Compute - UBUNTU_4_CORE',
@@ -127,7 +160,7 @@ export class UsageReportService {
127160
'November',
128161
'December',
129162
];
130-
163+
131164
constructor() {
132165
}
133166

@@ -241,22 +274,19 @@ export class UsageReportService {
241274
}
242275

243276
formatSku(sku: string) {
244-
let formatted;
277+
if (!sku) return sku;
278+
if (this.skuMapping[sku]) return this.skuMapping[sku];
279+
console.log(`No mapping for ${sku}`)
245280
const skuParts = sku.split('Compute - ');
246281
if (skuParts.length < 2) return sku;
247-
formatted = skuParts[1].replaceAll('_', ' ').replace(' CORE', '');
282+
const runtime = skuParts[1];
283+
let formatted = runtime.replaceAll('_', ' ').replace(' CORE', '');
248284
formatted = titlecasePipe.transform(formatted);
249285
formatted = formatted.replace('Macos', 'MacOS');
250-
switch(formatted) {
251-
case 'Ubuntu':
252-
return 'Ubuntu 2';
253-
case 'Windows':
254-
return 'Windows 2';
255-
case 'MacOS':
256-
return 'MacOS 3';
257-
default:
258-
return formatted;
286+
if (formatted.includes('ARM')) {
287+
return `${formatted} (ARM)`
259288
}
289+
return formatted;
260290
}
261291
}
262292

0 commit comments

Comments
 (0)