Compare commits

...
4 Commits
Author SHA1 Message Date
Kirill eabc193d8b feat(utils/InitalizeDB.py): PSQL initializing
Add script with is connected to db and initialize it
2025-10-23 23:01:22 +03:00
Kirill 35f18853fc feat(utils/PostgressConnect.py): Postgress connect Functional
Added Functions with connect to postgress db by link from enviroment
2025-10-23 23:00:00 +03:00
Kirill a062d24b24 feat(utils/loadDotEnv.py): Enviroment
Function for download enviroment variables from .env to Enviroment
2025-10-23 22:57:07 +03:00
Kirill a87656274b feat(dependencies.txt): Lib fix
Added libs for working with PSQL and dot-env
2025-10-23 22:55:05 +03:00
4 changed files with 103 additions and 0 deletions
+2
View File
@@ -1 +1,3 @@
flask==3.1.2
python-dotenv
psycopg-binary==3.2.10
+79
View File
@@ -0,0 +1,79 @@
import psycopg
from PostgressConnect import PSQLConnect, PSQLCursor
from loadDotEnv import initializeENV
state = initializeENV()
conn = PSQLConnect()
cur = PSQLCursor(conn)
cur.execute('''
-- Пользователи системы
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
role VARCHAR(50) NOT NULL, -- 'operator', 'admin', 'viewer'
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Роботы
CREATE TABLE robots (
id VARCHAR(50) PRIMARY KEY, -- 'RB-001'
status VARCHAR(50) DEFAULT 'active',
battery_level INTEGER,
last_update TIMESTAMP,
current_zone VARCHAR(10),
current_row INTEGER,
current_shelf INTEGER
);
-- Товары
CREATE TABLE products (
id VARCHAR(50) PRIMARY KEY, -- 'TEL-4567'
name VARCHAR(255) NOT NULL,
category VARCHAR(100),
min_stock INTEGER DEFAULT 10,
optimal_stock INTEGER DEFAULT 100
);
-- История инвентаризации
CREATE TABLE inventory_history (
id SERIAL PRIMARY KEY,
robot_id VARCHAR(50) REFERENCES robots(id),
product_id VARCHAR(50) REFERENCES productsuid),
quantity INTEGER NOT NULL,
zone VARCHAR(10) NOT NULL,
row_number INTEGER,
shelf_number INTEGER,
status VARCHAR(50), -- 'OK', 'LOW_STOCK', 'CRITICAL'
scanned_at TIMESTAMP NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Прогнозы ИИ
CREATE TABLE ai_predictions (
id SERIAL PRIMARY KEY,
product_id VARCHAR(50) REFERENCES products(id),
prediction_date DATE NOT NULL,
days_until_stockout INTEGER,
recommended_order INTEGER,
confidence_score DECIMAL(3,2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Индексы для оптимизации
REATE INDEX idx_inventory_scanned ON inventory_history(scanned_at DESC);
CREATE INDEX idx_inventory_product ON inventory_history(product_id);
CREATE INDEX idx_inventory_zone ON inventory_history(zone);
''')
conn.commit()
cur.close()
conn.close()
print("DB is Initialized")
+10
View File
@@ -0,0 +1,10 @@
import psycopg
import os
def PSQLConnect():
conn = psycopg.connect(os.getenv('POSTDRESS_CONNECTION'))
return conn
def PSQLCursor(conn):
cur = conn.cursor()
return cur
+12
View File
@@ -0,0 +1,12 @@
import os
from dotenv import load_dotenv
def initializeENV():
dotenv_path = '../.env'
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)
print('.env is loaded')
return 1
else:
print('.env isn`t loaded')
return 0