+ статистика
+ логирование исправить: уведомления (сломался софт)
This commit is contained in:
parent
5c2cbbbad0
commit
e01f43dc35
13 changed files with 637 additions and 51 deletions
Binary file not shown.
|
|
@ -1,5 +1,5 @@
|
|||
from database.db_session import get_session
|
||||
from database.models import Auth
|
||||
from database.models import Auth, Notifications, Users
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
def create_user(login, password):
|
||||
|
|
@ -26,3 +26,20 @@ def check_user(login, password):
|
|||
return False
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
|
||||
def log_db_event(event_message, root):
|
||||
# Логирование события с базы данных
|
||||
try:
|
||||
# Пример добавления события в лог
|
||||
with open('logs/database_logs.txt', 'a') as log_file:
|
||||
log_file.write(event_message + "\n")
|
||||
|
||||
# Уведомление для администратора
|
||||
notification = Notifications(root)
|
||||
notification.show_info("Событие", f"Событие успешно записано: {event_message}")
|
||||
|
||||
except Exception as e:
|
||||
# Если ошибка при записи в лог
|
||||
notification = Notifications(root)
|
||||
notification.show_error("Ошибка", f"Ошибка при записи в лог: {str(e)}")
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
# database/db_session.py
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from config import DATABASE_URL
|
||||
|
|
@ -22,4 +21,4 @@ def init_db():
|
|||
|
||||
def get_session():
|
||||
"""Возвращает сессию для работы с базой данных."""
|
||||
return Session()
|
||||
return Session()
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
from sqlalchemy import Column, Integer, String, ForeignKey, Text
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, Text, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
|
|
@ -26,6 +27,8 @@ class Users(Base):
|
|||
# Связи
|
||||
auth = relationship("Auth", back_populates="user") # Обратная связь с Auth
|
||||
dog = relationship("Dogs", back_populates="users") # Связь с таблицей Dogs
|
||||
game_sessions = relationship("GameSession", back_populates="user") # Связь с таблицей GameSession
|
||||
notifications = relationship("Notifications", back_populates="user") # Связь с уведомлениями
|
||||
|
||||
|
||||
class Dogs(Base):
|
||||
|
|
@ -47,9 +50,36 @@ class Questions(Base):
|
|||
__tablename__ = 'questions'
|
||||
question_id = Column(Integer, primary_key=True)
|
||||
dog_id = Column(Integer, ForeignKey('dogs.dog_id'))
|
||||
question_text = Column(Text, nullable=False)
|
||||
question_text = Column(Text, nullable=False) # Исправлено поле
|
||||
image_url = Column(String)
|
||||
helpful_info = Column(Text)
|
||||
incorrect_attempts = Column(Integer, default=0)
|
||||
|
||||
# Связь с таблицей Dogs
|
||||
dog = relationship("Dogs", back_populates="questions")
|
||||
|
||||
|
||||
class GameSession(Base):
|
||||
__tablename__ = 'game_sessions'
|
||||
session_id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey('users.user_id'))
|
||||
level = Column(Integer, nullable=False)
|
||||
score = Column(Integer, default=0)
|
||||
duration = Column(Integer) # Время игры в секундах
|
||||
start_time = Column(DateTime, default=func.now()) # Исправлено
|
||||
end_time = Column(DateTime, nullable=True)
|
||||
|
||||
# Связь с таблицей Users
|
||||
user = relationship("Users", back_populates="game_sessions")
|
||||
|
||||
class Notifications(Base):
|
||||
__tablename__ = 'notifications'
|
||||
notification_id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey('users.user_id'))
|
||||
message = Column(Text, nullable=False)
|
||||
timestamp = Column(DateTime, default=func.now())
|
||||
is_read = Column(Integer, default=0) # 0 - не прочитано, 1 - прочитано
|
||||
|
||||
# Связь с таблицей Users
|
||||
user = relationship("Users", back_populates="notifications")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue