From 289f204752d0e54be2273c1a1650e11b042d8e77 Mon Sep 17 00:00:00 2001 From: M_Kececi Date: Mon, 6 Jul 2026 18:01:18 +0300 Subject: [PATCH] Fix product performance grouped JSON build --- svc/queries/product_performance.go | 30 +++++++++++++++++-- svc/routes/product_performance_excel.go | 30 +++++++++++++++++-- .../pages/ProductPerformanceProfitability.vue | 18 +++++++++-- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/svc/queries/product_performance.go b/svc/queries/product_performance.go index b671361..0b73137 100644 --- a/svc/queries/product_performance.go +++ b/svc/queries/product_performance.go @@ -6282,8 +6282,8 @@ func productPerformanceProductScore(suffix string, salesUSD, salesIndex, margin, score := 0.30*productPerformanceMarginComponentScore(margin) + 0.20*productPerformanceRatioScore(stockTurnover, productPerformanceStockTurnoverTarget(suffix)) + 0.20*revenueScore + - 0.15*productPerformanceRatioScore(marketCount, 8) + - 0.15*productPerformanceRatioScore(customerCount, 25) + 0.15*productPerformanceRatioScore(marketCount, productPerformanceMarketSpreadTarget(suffix)) + + 0.15*productPerformanceRatioScore(customerCount, productPerformanceCustomerSpreadTarget(suffix)) return productPerformanceRoundScore(score) } @@ -6291,6 +6291,32 @@ func productPerformanceStockTurnoverTarget(suffix string) float64 { return 4 } +func productPerformanceMarketSpreadTarget(suffix string) float64 { + switch suffix { + case "90d": + return 3 + case "180d": + return 5 + case "365d": + return 6 + default: + return 8 + } +} + +func productPerformanceCustomerSpreadTarget(suffix string) float64 { + switch suffix { + case "90d": + return 8 + case "180d": + return 15 + case "365d": + return 18 + default: + return 25 + } +} + func productPerformanceCustomerScore(suffix string, salesUSD, margin, productGroupCount, salesQty float64) float64 { if salesUSD <= 0 { return 1 diff --git a/svc/routes/product_performance_excel.go b/svc/routes/product_performance_excel.go index 4d92275..66a3d42 100644 --- a/svc/routes/product_performance_excel.go +++ b/svc/routes/product_performance_excel.go @@ -962,11 +962,37 @@ func productPerformanceExcelProductScore(suffix string, salesUSD, stockTurnover, score := 0.30*productPerformanceExcelMarginScore(margin) + 0.20*productPerformanceExcelRatioScore(stockTurnover, 4) + 0.20*revenueScore + - 0.15*productPerformanceExcelRatioScore(marketCount, 8) + - 0.15*productPerformanceExcelRatioScore(customerCount, 25) + 0.15*productPerformanceExcelRatioScore(marketCount, productPerformanceExcelMarketSpreadTarget(suffix)) + + 0.15*productPerformanceExcelRatioScore(customerCount, productPerformanceExcelCustomerSpreadTarget(suffix)) return productPerformanceExcelRoundScore(score) } +func productPerformanceExcelMarketSpreadTarget(suffix string) float64 { + switch suffix { + case "90d": + return 3 + case "180d": + return 5 + case "365d": + return 6 + default: + return 8 + } +} + +func productPerformanceExcelCustomerSpreadTarget(suffix string) float64 { + switch suffix { + case "90d": + return 8 + case "180d": + return 15 + case "365d": + return 18 + default: + return 25 + } +} + func productPerformanceExcelProductRevenueTarget(suffix string) float64 { switch suffix { case "180d": diff --git a/ui/src/pages/ProductPerformanceProfitability.vue b/ui/src/pages/ProductPerformanceProfitability.vue index dd67a2c..3a85a6f 100644 --- a/ui/src/pages/ProductPerformanceProfitability.vue +++ b/ui/src/pages/ProductPerformanceProfitability.vue @@ -3707,8 +3707,8 @@ function productScore100 ({ suffix = '90d', salesUSD = 0, margin = 0, stockTurno 0.30 * marginScore(margin) + 0.20 * ratioScore(stockTurnover, stockTurnoverTarget(suffix)) + 0.20 * revenue + - 0.15 * ratioScore(marketCount, 8) + - 0.15 * ratioScore(customerCount, 25) + 0.15 * ratioScore(marketCount, marketSpreadTarget(suffix)) + + 0.15 * ratioScore(customerCount, customerSpreadTarget(suffix)) ) } @@ -3775,6 +3775,20 @@ function stockTurnoverTarget () { return 4 } +function marketSpreadTarget (suffix) { + if (suffix === '90d') return 3 + if (suffix === '180d') return 5 + if (suffix === '365d') return 6 + return 8 +} + +function customerSpreadTarget (suffix) { + if (suffix === '90d') return 8 + if (suffix === '180d') return 15 + if (suffix === '365d') return 18 + return 25 +} + function periodCount (row, prefix, suffix) { const keyed = Number(row?.[`${prefix}_${suffix}`] || 0) if (keyed > 0) return keyed