fixed order

This commit is contained in:
2025-12-09 15:01:09 -06:00
parent 05505db4a9
commit b764c5f36e
+22 -10
View File
@@ -31,22 +31,17 @@ interface RawOsEntry {
sistema_operativo: string;
total: string;
}
// Función profesional para transformar tu JSON a OsEntry[]
function transformPlatform(raw: RawOsEntry[]): OsEntry[] {
const rows: OsEntry[] = raw.map((item) => ({
os: item.sistema_operativo,
count: Number(item.total), // Convierte string a número
}));
const order = {
function transformPlatform(raw: RawOsEntry[]): OsEntry[] {
const order: Record<string, number> = {
"Windows 11": 1,
"Windows 10": 2,
"Windows 7/8": 3,
"Windows XP/Vista": 4,
Linux: 5,
"Mac OS (13 - Ventura, 14 - Sonoma)": 6,
"MAC OS (SEQUOIA)": 7,
"MAC OS (SEQUOIA)": 6,
"Mac OS (13 - Ventura, 14 - Sonoma)": 7,
"Mac OS X (Mojave, Catalina, 11 - Big Sur, 12 - Monterrey)": 8,
"Mac OS X (Snow Leopard, Lion, Mountain Lion, Mavericks)": 9,
"Mac OS X (Yosemite, El Capitan, Sierra, High Sierra)": 10,
@@ -60,7 +55,24 @@ function transformPlatform(raw: RawOsEntry[]): OsEntry[] {
"Windows Server 2016/2019": 15,
"Windows Server 2008/2012": 16,
"Windows Server 2000/2003": 17,
} as const;
};
function cleanName(rawName: string): string {
return rawName
.normalize("NFKD")
.replace(/\u00A0/g, " ")
.replace(/\s+/g, " ")
.trim();
}
// mapeamos y limpiamos antes del sort
const rows: OsEntry[] = raw.map((item) => {
const cleaned = cleanName(item.sistema_operativo);
return {
os: cleaned,
count: Number(item.total),
};
});
rows.sort((a, b) => {
const orderA = (order as Record<string, number>)[a.os] ?? 999;