Track inventory levels and forecast demand to prevent shortages and optimize restocking schedules.
psql
, is installed in your environment. For detailed instructions, see Download PostgreSQL.inventory
tracks the current stock levels of each product at each warehouse.
sales
describes the details of each transaction, such as the quantity purchased and the warehouse from which the item was sourced.
data_generator.py
file. This Python script utilizes the psycopg2
library to establish a connection with RisingWave so you can generate and insert synthetic data into the tables positions
and market_data
.
If you are not running RisingWave locally or using default credentials, update the connection parameters accordingly:
inventory_status
materialized view indicates whether or not a product needs to be restocked.
inventory_status
to see the results.
recent_sales
materialized view calculates the number of products sold from each warehouse within the past week. By understanding recent sale trends, you can forecast demand.
A temporal filter, timestamp > NOW() - INTERVAL '7 days'
is used to retrieve sales made within the past week. To learn more about temporal filters, see Temporal filters.
recent_sales
to see the results.
demand_forecast
materialized view predicts how long the current stock of each product will last based on recent sales trends.
A simple model is used to forecase demand, where the stock_level
found in inventory_status
is divided by the total_quantity_sold
in `recent_sales.
RisingWave supports creating materialized views on top of materialized views. When the source materialized view updates, the child materialized view will update accordingly as well.
demand_forecast
to see the results.
Ctrl+C
to close the connection between RisingWave and psycopg2
.