diff --git a/src/features/grid/api/get-product-rows.ts b/src/features/grid/api/get-product-rows.ts index 354e461..568cb6d 100644 --- a/src/features/grid/api/get-product-rows.ts +++ b/src/features/grid/api/get-product-rows.ts @@ -474,8 +474,8 @@ async function enrichWithNetworkMetrics(productMap: Map): Pr if (byCodeCentrale.size === 0) return; const metrics = await getNetworkMetricsByCodeCentrale([...byCodeCentrale.keys()]); - const firstMatch = [...byCodeCentrale.keys()].find((cc) => metrics.has(cc)); - console.log(`[getProductRows] réseau: ${byCodeCentrale.size} codes centraux → ${metrics.size} matchés en cache. Sample:`, firstMatch ? JSON.stringify(metrics.get(firstMatch)) : "aucun match"); + const sampleKey = [...byCodeCentrale.keys()].find((cc) => (metrics.get(cc)?.caReseau ?? 0) > 0) ?? [...byCodeCentrale.keys()].find((cc) => metrics.has(cc)); + console.log(`[getProductRows] réseau: ${byCodeCentrale.size} codes centraux → ${metrics.size} matchés en cache. Sample:`, sampleKey ? JSON.stringify(metrics.get(sampleKey)) : "aucun match"); for (const [cc, products] of byCodeCentrale.entries()) { const m = metrics.get(cc); if (!m) continue; diff --git a/src/lib/qlik-playwright.ts b/src/lib/qlik-playwright.ts index 13d8405..632a0dd 100644 --- a/src/lib/qlik-playwright.ts +++ b/src/lib/qlik-playwright.ts @@ -112,17 +112,20 @@ export async function fetchNetworkMetricsPlaywright( } // Résoudre les master measures par TITRE (le qLibraryId fiable = qInfo.qId, ≠ GUID QRS). const norm = (s: string) => s.replace(/\s+/g, " ").trim().toLowerCase(); - const ml = await rpc("CreateSessionObject", { qProp: { qInfo: { qType: "MeasureList" }, qMeasureListDef: { qType: "measure", qData: { title: "/qMetaDef/title" } } } }, doc); + const ml = await rpc("CreateSessionObject", { qProp: { qInfo: { qType: "MeasureList" }, qMeasureListDef: { qType: "measure", qData: { title: "/qMetaDef/title", expr: "/qMeasure/qDef/qDef" } } } }, doc); const mll = await rpc("GetLayout", {}, (ml.qReturn as { qHandle: number }).qHandle); - const items = (((mll.qLayout as { qMeasureList?: { qItems?: Array<{ qInfo: { qId: string }; qMeta?: { title?: string }; qData?: { title?: string } }> } }).qMeasureList?.qItems) ?? []); + const items = (((mll.qLayout as { qMeasureList?: { qItems?: Array<{ qInfo: { qId: string }; qMeta?: { title?: string }; qData?: { title?: string; expr?: string } }> } }).qMeasureList?.qItems) ?? []); const byTitle = new Map(); - for (const it of items) { const t = it.qMeta?.title ?? it.qData?.title ?? ""; if (t) byTitle.set(norm(t), it.qInfo.qId); } + const exprById = new Map(); + for (const it of items) { const t = it.qMeta?.title ?? it.qData?.title ?? ""; if (t) byTitle.set(norm(t), it.qInfo.qId); exprById.set(it.qInfo.qId, it.qData?.expr ?? ""); } const pickMeasure = (title: string, fallback: string) => byTitle.get(norm(title)) ?? fallback; const rCamag = pickMeasure("CA par Magasin N", mcamag); const rCouv = pickMeasure("Couverture de stock Quantité N", mcouv); const rMarge = pickMeasure("Marge % N", mmarge); const rRupt = pickMeasure("Stock Rupture % N", mrupt); console.log("measures résolues par titre: " + JSON.stringify({ rCamag, rCouv, rMarge, rRupt }) + " (sur " + items.length + " mesures)"); + console.log("expr rupture (" + rRupt + "): " + (exprById.get(rRupt) ?? "n/a")); + console.log("expr couverture (" + rCouv + "): " + (exprById.get(rCouv) ?? "n/a")); const obj = await rpc("CreateSessionObject", { qProp: { qInfo: { qType: "cf-net" }, qHyperCubeDef: { qDimensions: [{ qLibraryId: dim }], qMeasures: [{ qLibraryId: mca }, { qLibraryId: mqte }, { qLibraryId: mnb }, { qLibraryId: rCamag }, { qLibraryId: rCouv }, { qLibraryId: rMarge }, { qLibraryId: rRupt }],