fix
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/config"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/db"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/processing"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func main() {
|
||||
out := `F:\laragon\www\_MY\descrybe-v2\.codehelper\_live_llm_formula_20260816`
|
||||
jobID := uuid.MustParse("3d926dfa-de8a-4afc-b1dd-8707633c673e")
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
pool, err := db.NewPool(ctx, cfg.DatabaseURL, db.PoolOptions{
|
||||
MaxConns: 4, MinConns: 0,
|
||||
MaxConnLifetime: time.Hour, HealthCheckPeriod: 30 * time.Second,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
rows, err := pool.Query(ctx, `
|
||||
SELECT rp.gtin,
|
||||
COALESCE(pp.processed_name, pp.name, '') AS title,
|
||||
COALESCE(NULLIF(pp.processed_description, ''), pp.description, '') AS description,
|
||||
COALESCE(pp.category, '') AS category,
|
||||
COALESCE(c.name, '') AS category_name,
|
||||
c.description_template,
|
||||
pp.id
|
||||
FROM processing_job_products pjp
|
||||
JOIN raw_products rp ON rp.id = pjp.raw_product_id
|
||||
LEFT JOIN processed_products pp ON pp.id = pjp.processed_product_id
|
||||
LEFT JOIN categories c ON c.company_id = pp.company_id AND c.unique_id = pp.category
|
||||
WHERE pjp.job_id = $1
|
||||
ORDER BY rp.gtin`, jobID)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
products := []map[string]any{}
|
||||
for rows.Next() {
|
||||
var gtin, title, desc, cat, catName string
|
||||
var tmpl any
|
||||
var ppID *uuid.UUID
|
||||
if err := rows.Scan(>in, &title, &desc, &cat, &catName, &tmpl, &ppID); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
idStr := ""
|
||||
if ppID != nil {
|
||||
idStr = ppID.String()
|
||||
}
|
||||
lower := strings.ToLower(desc)
|
||||
products = append(products, map[string]any{
|
||||
"ean": gtin,
|
||||
"product_id": idStr,
|
||||
"title": title,
|
||||
"description": desc,
|
||||
"category": cat,
|
||||
"category_name": catName,
|
||||
"description_template": tmpl,
|
||||
"formula_constraint": processing.FormatDescriptionFormulaConstraint(tmpl),
|
||||
"has_h1": strings.Contains(lower, "<h1"),
|
||||
"has_h2": strings.Contains(lower, "<h2"),
|
||||
"has_p": strings.Contains(lower, "<p"),
|
||||
"has_ul": strings.Contains(lower, "<ul"),
|
||||
"desc_len": len(desc),
|
||||
"desc_ne_title": strings.TrimSpace(desc) != "" && strings.TrimSpace(desc) != strings.TrimSpace(title),
|
||||
})
|
||||
}
|
||||
raw, _ := json.MarshalIndent(products, "", " ")
|
||||
_ = os.WriteFile(out+`\db_products.json`, raw, 0o644)
|
||||
fmt.Printf("wrote %d products\n", len(products))
|
||||
for _, p := range products {
|
||||
t := p["title"].(string)
|
||||
if len(t) > 40 {
|
||||
t = t[:40]
|
||||
}
|
||||
fmt.Printf("%s cat=%s/%s h1=%v h2=%v p=%v ul=%v desc_ne_title=%v len=%v title=%q\n",
|
||||
p["ean"], p["category"], p["category_name"], p["has_h1"], p["has_h2"], p["has_p"], p["has_ul"], p["desc_ne_title"], p["desc_len"], t)
|
||||
d := p["description"].(string)
|
||||
if len(d) > 220 {
|
||||
d = d[:220]
|
||||
}
|
||||
fmt.Printf(" desc_preview=%q\n", d)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user