Fix product performance grouped JSON build
This commit is contained in:
+21
@@ -227,6 +227,7 @@ InitRoutes — FULL V3 (Method-aware) PERMISSION EDITION
|
||||
func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router {
|
||||
|
||||
r := mux.NewRouter()
|
||||
mountUploads(r)
|
||||
mountSPA(r)
|
||||
|
||||
/*
|
||||
@@ -1517,6 +1518,26 @@ func main() {
|
||||
|
||||
}
|
||||
|
||||
func mountUploads(r *mux.Router) {
|
||||
root := strings.TrimSpace(os.Getenv("BLOB_ROOT"))
|
||||
if root == "" {
|
||||
return
|
||||
}
|
||||
uploadsRoot := filepath.Join(root, "uploads")
|
||||
if fi, err := os.Stat(uploadsRoot); err != nil || !fi.IsDir() {
|
||||
return
|
||||
}
|
||||
fileServer := http.StripPrefix("/uploads/", http.FileServer(http.Dir(uploadsRoot)))
|
||||
r.PathPrefix("/uploads/").Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
fileServer.ServeHTTP(w, r)
|
||||
})).Methods(http.MethodGet, http.MethodHead, http.MethodOptions)
|
||||
}
|
||||
|
||||
func mountSPA(r *mux.Router) {
|
||||
r.NotFoundHandler = http.HandlerFunc(spaIndex)
|
||||
r.HandleFunc("/", spaIndex).Methods(http.MethodGet)
|
||||
|
||||
@@ -6129,6 +6129,10 @@ func productPerformanceMapVariantKey(row map[string]any) string {
|
||||
|
||||
func deriveProductPerformanceGroupMetrics(out map[string]any, groupField string) {
|
||||
normalizeProductPerformanceCostFields(out)
|
||||
isGroup := strings.TrimSpace(groupField) != ""
|
||||
if isGroup {
|
||||
out["group_field"] = groupField
|
||||
}
|
||||
preservedCustomerScores := map[string]float64{}
|
||||
preservedProductScores := map[string]float64{}
|
||||
for _, suffix := range productPerformancePeriodSuffixes() {
|
||||
@@ -6149,7 +6153,7 @@ func deriveProductPerformanceGroupMetrics(out map[string]any, groupField string)
|
||||
qty := floatFromMap(out, "sales_qty_"+suffix)
|
||||
stockQty := floatFromMap(out, "stock_qty")
|
||||
turnoverBase := floatFromMap(out, "avg_stock_"+suffix)
|
||||
if turnoverBase <= 0 {
|
||||
if turnoverBase <= 0 && !isGroup {
|
||||
turnoverBase = stockQty
|
||||
}
|
||||
days := productPerformancePeriodDays(out, suffix)
|
||||
@@ -6381,7 +6385,7 @@ func productPerformanceSalesPeriodScore(row map[string]any, suffix string) float
|
||||
stockTurnover := floatFromMap(row, "stock_turnover_"+suffix)
|
||||
if stockTurnover == 0 {
|
||||
avgStock := floatFromMap(row, "avg_stock_"+suffix)
|
||||
if avgStock <= 0 {
|
||||
if avgStock <= 0 && strings.TrimSpace(stringFromMap(row, "group_field")) == "" {
|
||||
avgStock = floatFromMap(row, "stock_qty")
|
||||
}
|
||||
if avgStock > 0 {
|
||||
|
||||
Reference in New Issue
Block a user