fix: hype cycle findTechnology matched wrong tech (1G instead of 1.6T)
findTechnology used loose includes() matching — '1.6T OSFP-XD' matched '1G SFP' first because query contained '1'. Now matches exact name first, then by speed prefix with proper unit parsing (G/T).
This commit is contained in:
parent
9a5b21a19a
commit
46af736db3
@ -458,11 +458,27 @@ export function computeAllHypeCycles(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function findTechnology(query: string): TechGeneration | undefined {
|
export function findTechnology(query: string): TechGeneration | undefined {
|
||||||
const q = query.toLowerCase();
|
const q = query.toLowerCase().trim();
|
||||||
const allTechs = [...TECH_GENERATIONS, ...SPECIAL_TECHS];
|
const allTechs = [...TECH_GENERATIONS, ...SPECIAL_TECHS];
|
||||||
return allTechs.find((t) =>
|
|
||||||
t.name.toLowerCase().includes(q) ||
|
// 1. Exact name match
|
||||||
q.includes(t.speedGbps.toString()) ||
|
const exact = allTechs.find((t) => t.name.toLowerCase() === q);
|
||||||
q.includes(t.formFactor.toLowerCase())
|
if (exact) return exact;
|
||||||
);
|
|
||||||
|
// 2. Name contains query or query contains name
|
||||||
|
const nameMatch = allTechs.find((t) => t.name.toLowerCase().includes(q));
|
||||||
|
if (nameMatch) return nameMatch;
|
||||||
|
|
||||||
|
// 3. Fuzzy: match by speed prefix (e.g. "400G", "1.6T", "800G")
|
||||||
|
const speedMatch = q.match(/^(\d+(?:\.\d+)?)\s*(g|t)\b/i);
|
||||||
|
if (speedMatch) {
|
||||||
|
const num = parseFloat(speedMatch[1]);
|
||||||
|
const unit = speedMatch[2].toLowerCase();
|
||||||
|
const targetGbps = unit === "t" ? num * 1000 : num;
|
||||||
|
const found = allTechs.find((t) => t.speedGbps === targetGbps);
|
||||||
|
if (found) return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Match by form factor
|
||||||
|
return allTechs.find((t) => q.includes(t.formFactor.toLowerCase()));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user