Spaces:
Sleeping
Sleeping
File size: 2,478 Bytes
0f7aaa7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | -- ============================================================
-- schema_demand.sql β monitor-ml-aceites
-- Tablas para el pipeline de demanda (Fase 2)
-- Ejecutar en el SQL Editor de Supabase (una sola vez)
-- ============================================================
-- βββ Forecasts de demanda βββββββββββββββββββββββββββββββββ
-- Almacena predicciones Prophet por producto.
-- Generadas localmente con train_demand_model.py
-- El agente demand_monitor las lee desde Supabase.
CREATE TABLE IF NOT EXISTS demand_forecasts (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
forecast_run_at TIMESTAMPTZ DEFAULT NOW(),
product TEXT NOT NULL, -- nombre del producto
target_date DATE NOT NULL, -- fecha central de la predicciΓ³n
horizon VARCHAR(20) NOT NULL, -- 'week_1' | 'month_1' | 'month_2' | 'month_3'
predicted_qty DECIMAL(14,2) NOT NULL, -- cantidad predicha (unidades/kg/litros segΓΊn datos)
lower_bound DECIMAL(14,2), -- intervalo de confianza 80% inferior
upper_bound DECIMAL(14,2), -- intervalo de confianza 80% superior
unit TEXT DEFAULT 'units', -- unidad de la cantidad ('units', 'kg', 'liters')
model_name TEXT DEFAULT 'sales_demand_forecast',
data_points INTEGER, -- puntos de datos usados para entrenar
mape DECIMAL(6,2), -- error del modelo (%)
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_demand_forecasts_run
ON demand_forecasts (forecast_run_at DESC);
CREATE INDEX IF NOT EXISTS idx_demand_forecasts_product
ON demand_forecasts (product, horizon, forecast_run_at DESC);
-- βββ Log de importaciones Excel βββββββββββββββββββββββββββ
-- Registra cada archivo importado con el mapeo de columnas detectado.
CREATE TABLE IF NOT EXISTS excel_imports (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
filename TEXT NOT NULL,
imported_at TIMESTAMPTZ DEFAULT NOW(),
rows_imported INTEGER,
column_mapping JSONB, -- mapeo detectado por Claude {date, product, quantity, ...}
products_found JSONB, -- lista de productos ΓΊnicos encontrados
status TEXT DEFAULT 'success',
notes TEXT
);
|