О проекте
Команда: Shabytskie
Кейс HackAlem.ai: Логистика — Электрокомплект · ekt.kz
Стадия: Рабочий MVP
Задача кейса: Автоматический расчёт заказов поставщикам для пополнения склада, с утверждением менеджером
Суть
Сервис и Streamlit-дашборд, которые считают рекомендуемые заказы поставщикам по истории продаж: количество, срочность и обоснование по каждой позиции, группировка по поставщикам, правка и утверждение менеджером, экспорт в XLSX/CSV для 1С.
Как устроено
Пайплайн (src/) загружает продажи, остатки, товар в пути, справочники поставщиков и категорий, периоды отсутствия товара и прогноз роста. Разовые крупные заказы отсекаются как аномалии, потерянный спрос в периоды дефицита восстанавливается, затем строится прогноз с сезонностью и трендом. Заказ считается по политике запасов: период пересмотра, уровень сервиса z (1.65 ≈ 95%), срок поставки; горизонт прогноза покрывает самый долгий срок поставки плюс период пересмотра. В дашборде есть карточка артикула с графиком за 120 дней и пошаговым расчётом, а также режимы demo / local / production с входом через OIDC.
Ключевые решения
- прогноз спроса с сезонностью и трендом
- детекция аномалий (разовые крупные заказы)
- восстановление спроса в периоды дефицита
- страховой запас по уровню сервиса z
- генератор синтетических данных
- экспорт CSV для 1С
- аутентификация OIDC
Особенности
Много внимания безопасности и работе с реальными выгрузками: три режима запуска (demo / local только на loopback / production с OIDC), лимиты на размер и число загрузок, удаление временных файлов, распознавание форматов 1С (разделители, дата с днём впереди, десятичная запятая, CP1251) и выгрузка CSV для 1С с BOM.
Стек
Python · Streamlit · pytest/unittest · nginx · OIDC
Проект создан за 5 часов на финале хакатона HackAlem.ai (23 сентября 2026, Астана). Код — BAITC-Hacks/hack-6eaef586-shabytskie.
README
README.mdElectrical kit: automatic calculation of orders to suppliers
The service generates recommended orders to suppliers based on sales history. For each item, it provides the quantity, urgency, and justification, and groups the entire list by supplier. The calculation takes into account seasonality, steady growth, current stock levels, goods in transit, categories, planned growth, and lost demand during periods when the product is unavailable. One‑off large orders, including large sales to a single customer, are excluded from regular requirements.
The procurement department manager initiates the calculation by warehouse or category, receives a list of suppliers, adjusts the quantity if necessary, and approves the order. Nothing is automatically sent to the supplier: the approval only saves the files for the responsible employee.
Launch
Python 3.12 is required for the fixed set of dependencies. Run the commands from the repository folder.
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade 'pip>=26.2,<27'
python -m pip install -r requirements.txt
# quick start: without arguments, it runs on demo data from data/demo (creates them if necessary)
python main.py
# synthetic data + reference tables (data/demo/*.csv)
python -m src.generate_synthetic_data
# full calculation
python main.py --input data/demo/synthetic_sales.csv \
--suppliers data/demo/suppliers.csv --catalog data/demo/catalog.csv \
--stockouts data/demo/stockouts.csv --growth data/demo/category_growth.csv \
--chart-sku SKU001
# only one warehouse / one category
python main.py --input data/demo/synthetic_sales.csv --warehouse WH1
python main.py --input data/demo/synthetic_sales.csv --category "Category 1"
# dashboard: by default, a secure demo mode on synthetic data
python -m streamlit run app.py
# tests
python -m unittest discover -s tests -v
On Windows, create an environment using py -3.12 -m venv .venv and activate it using the command .venv\Scripts\Activate.ps1 in PowerShell. If Python of the required version is not installed, first install Python 3.12; activation does not create the environment.
Choose the dashboard mode: APP_MODE=demo provides synthetic examples only; APP_MODE=local enables file uploads and order approval without login on the operator's own computer; APP_MODE=production requires corporate login. For production, configure OIDC according to SECURITY.md, fill in .streamlit/secrets.toml according to the example, and set APP_MODE=production. An unconfigured production mode blocks access. The CLI python main.py --input ... is also available for local calculations.
After updating the dependencies and modules, stop the old server (Ctrl+C) and launch it again: a single tab refresh may not be enough. If localhost is not responding, check http://127.0.0.1:8501 and make sure the old process has released the port.
Inventory policy parameters: --review-days (review period, default is 7), --service-z (service level z, 1.65 ≈ 95%), --default-lead-time (lead time if not specified, 14). --forecast-days sets the forecast report horizon. The forecast horizon for an order is selected automatically and covers the longest lead time plus the review period.
Local dashboard: upload files without login
After installing the dependencies above, stop any previous server with Ctrl+C and run from the repository folder. Virtual environment activation is optional when using the explicit Python paths below.
Windows / VS Code PowerShell:
$env:APP_MODE = "local"
.\.venv\Scripts\python.exe -m streamlit run app.py --server.address 127.0.0.1 --server.port 8502
macOS / Linux:
APP_MODE=local ./.venv/bin/python -m streamlit run app.py --server.address 127.0.0.1 --server.port 8502
Open http://127.0.0.1:8502 and select «Загрузить свои файлы» in the left sidebar. CSV and XLSX uploads, calculations, approval, and exports are available. Local approvals are attributed to local-operator.
Local mode requires a loopback listener (127.0.0.1 or ::1) and is intended for the operator's own computer, not public deployment through a proxy or tunnel. To return to demo mode in the same PowerShell terminal, stop the server, set $env:APP_MODE = "demo", and run the launch command again. On macOS/Linux, replace APP_MODE=local with APP_MODE=demo.
Dashboard
python -m streamlit run app.py opens the interface in a browser (http://localhost:8501). When APP_MODE is unset, only demo data is available. File uploads are available in local mode as described above, or to authorized analysts and managers in production:
- Data. Upload sales history (CSV/XLSX, for example, an export from 1C) and, if available, reference data: suppliers, items, stock levels, periods of product unavailability, growth forecast. In the “File Templates” section, you can download examples in the required format. The “Show on demo data” button runs the calculation on synthetic data without its own files.
- **Parameters.**Warehouse or category, revision period, service level. Then click the “Run calculation” button.
- Orders by supplier. Summary indicators, positions of the selected supplier with urgency and justification. The “Approved quantity” column can be edited.
- **Statement.**The manager clicks “Approve”: buttons to download the order in XLSX and CSV for 1C appear. In production, the responsible person is determined by the account; in local mode it is
local-operator. In the demo, the approval is marked as training. The order is not automatically sent to the supplier. - Article card. A 120‑day chart: actual sales, demand for calculation (excluding one‑off orders, with missed demand), and forecast for the coverage period. One‑off orders are marked with dots, and days when the item is out of stock are highlighted with a fill. Next, a step‑by‑step calculation of the quantity from forecast to order and a list of events.
- Trends by category. Weekly adjusted demand.
Appearance: open the ⋮ menu at the top right to switch between light and dark themes. The menu is enabled with client.toolbarMode = "viewer" in .streamlit/config.toml.
The service verifies the owner and session when reading the result. Temporary folders are deleted after an hour, and copied source files are deleted after the calculation. One calculation is allowed at a time, and up to three per user within five minutes; in the public demo, this limit is shared. Browser/Streamlit memory storage limitations and download links are described in SECURITY.md.
Demo and production deployment
For public demonstration, use APP_MODE=demo, Python 3.12, and only synthetic files from data/demo/. The platform must install requirements.txt along with requirements.lock. Set the listening address to match the network model of the chosen hosting; by default, the repository listens only to loopback.
For production deployment with real data, HTTPS, OIDC, an authentication gateway before all Streamlit routes, and resource limits are required. The deploy/nginx.conf.example template requires configuration of the domain, certificate, and gateway; it is not an already completed deployment. Configuration order and remaining restrictions: SECURITY.md. Audit results: SECURITY_REPORT.md.
Input data
Files are accepted in CSV (comma, semicolon, tab, or |; UTF-8/Windows-1251) or XLSX with a single sheet of values, without formulas, macros, or external links. Limits: 20 MB per file, 60 MB per web upload set, 100,000 rows, 40 columns, and 2 million cells per table. Column names are recognized in Russian and English; case is not important. If two columns fit into the same field, the file is rejected.
Value formats are the same as in 1C exports:
- Dates:
YYYY-MM-DD(ISO, including date cells from Excel) orDD.MM.YYYY(the day is always first:01.02.2025— 1 February). - **Numbers:You can use a space or an non‑breaking space between the digits and a comma in the fractional part (
1 234,5). - CSV for 1C as output: delimiter
;, decimal comma, whole quantities without,0, UTF‑8 with BOM. - “Out of stock” flag:
yes/no,true/false,1/0.
Rows with an incorrect date, an empty article number.
Авторы коммитов
История коммитов
- 2026-09-23 17:53new read.mexxent41
- 2026-09-23 17:50fixxxent41
- 2026-09-23 17:38Merge team updates and preserve frontend fixesxxent41
- 2026-09-23 17:37Merge team updates and preserve frontend fixesxxent41
- 2026-09-23 17:31Update README.mdagoshin
- 2026-09-23 17:27fixed frontxxent41
- 2026-09-23 17:06Fix seasonal planning and anonymous bulk-sale influenceAset
- 2026-09-23 17:01Harden uploads, access control and procurement processingAset
Все коммиты (57)
- 2026-09-23 16:55fixed bagsJudith
- 2026-09-23 16:08fixed bagsJudith
- 2026-09-23 16:07fixed bagsJudith
- 2026-09-23 16:04Declare Plotly dependency for frontend chartsAset
- 2026-09-23 15:54fixed bagsJudith
- 2026-09-23 15:28Expose backend anomaly flags in SKU chartnuraman
- 2026-09-23 15:25Support anonymized customer data: tests/test_validation.pynuraman
- 2026-09-23 15:25Support anonymized customer data: data/generate_demo.pynuraman
- 2026-09-23 15:25Support anonymized customer data: frontend/validation.pynuraman
- 2026-09-23 15:24Support anonymized customer data: frontend/data_io.pynuraman
- 2026-09-23 15:24Support anonymized customer data: README.mdnuraman
- 2026-09-23 15:24Support anonymized customer data: app.pynuraman
- 2026-09-23 15:23Harden inventory inputs and order approvalAset
- 2026-09-23 15:15Add approval workflow helpers: tests/test_review.pynuraman
- 2026-09-23 15:14Add approval workflow helpers: frontend/review.pynuraman
- 2026-09-23 15:14Improve StockPilot UI: tests/test_exports.pynuraman
- 2026-09-23 15:14Improve StockPilot UI: tests/test_app_smoke.pynuraman
- 2026-09-23 15:14Improve StockPilot UI: integration/existing_provider.pynuraman
- 2026-09-23 15:14Improve StockPilot UI: frontend/exports.pynuraman
- 2026-09-23 15:14Improve StockPilot UI: frontend/charts.pynuraman
- 2026-09-23 15:14Improve StockPilot UI: app.pynuraman
- 2026-09-23 14:55frontxxent41
- 2026-09-23 14:35Document StockPilot Streamlit dashboard and integrationnuraman
- 2026-09-23 14:34Integrate polished StockPilot requirements.txtnuraman
- 2026-09-23 14:34Integrate polished StockPilot app.pynuraman
- 2026-09-23 14:34Add StockPilot frontend: README_STOCKPILOT_UI.mdnuraman
- 2026-09-23 14:34Add StockPilot frontend: .streamlit/config.tomlnuraman
- 2026-09-23 14:33Add StockPilot frontend: docs/integration_contract.mdnuraman
- 2026-09-23 14:33Add StockPilot frontend: docs/demo_script.mdnuraman
- 2026-09-23 14:33Add StockPilot frontend: tests/test_validation.pynuraman
- 2026-09-23 14:33Add StockPilot frontend: tests/test_review_state.pynuraman
- 2026-09-23 14:33Add StockPilot frontend: tests/test_exports.pynuraman
- 2026-09-23 14:33Add StockPilot frontend: tests/test_demo_provider.pynuraman
- 2026-09-23 14:33Add StockPilot frontend: tests/test_app_smoke.pynuraman
- 2026-09-23 14:33Add StockPilot frontend: tests/test_adapter.pynuraman
- 2026-09-23 14:33Add StockPilot frontend: data/generate_demo.pynuraman
- 2026-09-23 14:33Add StockPilot frontend: integration/existing_provider.pynuraman
- 2026-09-23 14:32Add StockPilot frontend: integration/demo_provider.pynuraman
- 2026-09-23 14:32Add StockPilot frontend: integration/adapter.pynuraman
- 2026-09-23 14:32Add StockPilot frontend: integration/__init__.pynuraman
- 2026-09-23 14:32Add StockPilot frontend: frontend/validation.pynuraman
- 2026-09-23 14:32Add StockPilot frontend: frontend/exports.pynuraman
- 2026-09-23 14:32Add StockPilot frontend: frontend/data_io.pynuraman
- 2026-09-23 14:32Add StockPilot frontend: frontend/components.pynuraman
- 2026-09-23 14:31Add StockPilot frontend: frontend/charts.pynuraman
- 2026-09-23 14:31Add StockPilot frontend: frontend/__init__.pynuraman
- 2026-09-23 14:31Add StockPilot frontend: contracts.pynuraman
- 2026-09-23 14:16fixed logic code and rewrote readmeJudith
- 2026-09-23 13:29Add demand forecasting MVP with anomaly and stockout correctionAset
Структура репозитория (47 файлов)
.env.example .gitignore .streamlit/config.toml .streamlit/secrets.example.toml README.md SECURITY.md SECURITY_REPORT.md app.py data/demo/catalog.csv data/demo/category_growth.csv data/demo/stockouts.csv data/demo/suppliers.csv data/demo/synthetic_sales.csv data/processed/.gitkeep data/raw/.gitkeep deploy/nginx.conf.example main.py outputs/.gitkeep pytest.ini requirements-dev.txt requirements.lock requirements.txt site-icon.jpg src/__init__.py src/anomaly_detection.py src/config.py src/data_loader.py src/demonstrate.py src/evaluation.py src/feature_engineering.py src/forecasting.py src/generate_synthetic_data.py src/ordering.py src/pipeline.py src/preprocessing.py src/secure_files.py src/security.py src/stockout.py src/web_auth.py src/web_service.py src/worker.py tests/__init__.py tests/test_acceptance.py tests/test_app_security.py tests/test_ordering.py tests/test_pipeline.py tests/test_security.py
Ветки (2)
Обсуждение 0 комментариев
Войдите, чтобы комментироватьПока нет комментариев — будьте первым.