Anaquel Inteligente 3B ships three intelligence modules that sit above the core inventory layer and transform raw stock events into actionable insights. PredictionEngine (M6) forecasts when each product will run out, HeatmapEngine (M7) tracks slot interaction intensity over a sliding time window, and NarrativeEngine (M8) produces human-readable Spanish-language status messages. All three are attached toDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elzackarias/Hackaton3B-Reto1/llms.txt
Use this file to discover all available pages before exploring further.
InventoryEngine via observer callbacks registered at application startup in main.py.
PredictionEngine — M6
ThePredictionEngine uses exponential weighted smoothing over the inter-removal intervals of each SKU to estimate the current depletion rate and project a stockout timestamp.
Constructor
Smoothing factor for the exponential weighted mean of inter-removal
intervals. Higher values give more weight to the most recent event;
lower values make the estimate more stable. Range:
(0, 1).predict(history: SKUHistory) -> StockPrediction
Calculates a stockout prediction for a single SKU.
Insufficient data guard
If
len(history.events) < 2, returns a StockPrediction with minutes_remaining=None, rate_per_hour=0.0, trend="estable", and confidence="baja".Already depleted guard
If
history.stock_current <= 0, returns immediately with minutes_remaining=0.0.Compute inter-removal intervals
Events are sorted chronologically and consecutive pairs are subtracted to yield a list of intervals in minutes.
Exponential smoothing
The smoothed interval
tasa is initialised to the first interval and updated for each subsequent one:Derive rate and ETA
rate_per_hour = 60 / tasa and minutes_remaining = tasa × stock_current.
estimated_depletion = datetime.now() + timedelta(minutes=minutes_remaining).StockPrediction fields:
Identifies the product.
Units on shelf at prediction time.
Estimated removal rate in units per hour.
Projected datetime of stockout, or
None if insufficient data.Minutes until stockout at the current rate, or
None.One of
"acelerando" (accelerating), "estable" (stable), or "desacelerando" (slowing). Computed by comparing the average interval of the first half of the event series to the second half: if avg_new < avg_old × 0.8 → "acelerando"; if avg_new > avg_old × 1.2 → "desacelerando"."alta" (> 6 events), "media" (≥ 3 events), or "baja" (< 3 events).predict_all(histories: list[SKUHistory]) -> list[StockPrediction]
Convenience wrapper that calls predict() for each SKUHistory in the list and returns all results.
Usage Example
HeatmapEngine — M7
TheHeatmapEngine accumulates InteractionEvent records and generates a normalised slot-activity heatmap filtered to a configurable sliding time window.
InteractionEvent Fields
Shelf slot number (1–7) where the interaction occurred.
Product SKU in that slot.
Bounding region
(x1, y1, x2, y2) in pixel coordinates.When the interaction was recorded.
"product_moved" when a product unit is displaced, or "hand_detected" when
a hand is detected near the slot.Methods
record(interaction: InteractionEvent)
Appends an InteractionEvent to the internal list. Called from the detection callback whenever a significant frame change is detected.
get_heatmap(window_seconds=300) -> dict
Filters the interaction list to only events within the last window_seconds seconds, counts events per slot_id, and normalises intensities so the most active slot always has intensity = 1.0.
intensity descending. Slots with zero activity in the window are excluded.
reset()
Clears all recorded interactions. Call at the start of a demo or test run.
NarrativeEngine — M8
TheNarrativeEngine generates concise, emoji-decorated Spanish-language status messages for display on the retail dashboard. A per-SKU-per-type cooldown prevents the same message from being spammed every few seconds.
Constructor
Minimum seconds that must elapse before the same
(event_type, sku_id)
combination can produce a new message. Set to 0 to disable cooldown
(useful in tests).generate(event_type: str, **kwargs) -> NarrativeMessage | None
Generates a narrative message from one of the built-in templates. Returns None if the (event_type, sku_id) key is still within its cooldown window.
Supported event_type values and their required kwargs:
- retiro
- devolucion
- alerta_umbral
- prediccion
Template:
"📦 {sku_name} retirado del anaquel. Stock actual: {stock} unidades"kwargs: sku_name (str), stock (int)Severity: "info" | Icon: 📦get_recent(limit=50) -> list[NarrativeMessage]
Returns the last limit generated messages in reverse-chronological order (most recent first).
clear()
Clears both the message history and the cooldown registry. Useful between demo sessions.
NarrativeMessage Fields
12-character hex string derived from
uuid4."info", "warning", or "critical". Maps to dashboard badge colour.The rendered narrative text in Spanish.
The SKU the message pertains to, or
None for general messages (e.g., "todo_ok").When the message was generated.
Emoji that prefixes the message. Useful for standalone display in the feed.