Обновляет Dockerfile, добавляет скрипт инициализации Airflow, улучшает документацию в README.md, изменяет название DAG и добавляет описание задач, а также улучшает логи в классе UserActionTransfer.
This commit is contained in:
@@ -27,7 +27,7 @@ class TargetDBRepo:
|
||||
batch = users.iloc[i:i + BATCH_SIZE]
|
||||
records = batch.to_dict(orient="records")
|
||||
session.run(query, {"rows": records})
|
||||
self.log.info("rows saved %s", i + BATCH_SIZE)
|
||||
self.log.info("Rows %s–%s saved (%s)", i, i+len(batch), len(batch))
|
||||
|
||||
def get_number_of_users(self) -> int:
|
||||
with self.driver.session() as session:
|
||||
|
||||
@@ -13,6 +13,9 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class UserActionTransfer:
|
||||
"""
|
||||
Класс для работы с переносом пользовательских действий в Neo4j.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -22,7 +25,9 @@ class UserActionTransfer:
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def generate_sample_data(self):
|
||||
"""Генерация тестовых данных и сохранение в CSV файл"""
|
||||
"""
|
||||
Генерирует тестовые данные действий пользователей и сохраняет их в CSV-файл.
|
||||
"""
|
||||
actions = self.get_fake_user_action_data()
|
||||
csv_file_path = self.get_csv_file_path()
|
||||
actions.to_csv(csv_file_path, index=False)
|
||||
@@ -34,6 +39,9 @@ class UserActionTransfer:
|
||||
logging.info(f"Data preview: %s", actions.head())
|
||||
|
||||
def load_data_to_neo4j(self) -> None:
|
||||
"""
|
||||
Загружает данные из CSV-файла во временной директории в базу данных Neo4j.
|
||||
"""
|
||||
csv_file_path = Variable.get("user_action_data_path")
|
||||
|
||||
if not csv_file_path or not os.path.exists(csv_file_path):
|
||||
@@ -52,7 +60,9 @@ class UserActionTransfer:
|
||||
logging.info("Temporary CSV file cleaned up")
|
||||
|
||||
def check_neo4j_connection(self):
|
||||
"""Проверка соединения с БД"""
|
||||
"""
|
||||
Проверяет соединение с базой данных Neo4j.
|
||||
"""
|
||||
try:
|
||||
result = self.target_db.check_connection()
|
||||
log.info(f"Neo4j message: {result}")
|
||||
@@ -64,13 +74,19 @@ class UserActionTransfer:
|
||||
|
||||
@staticmethod
|
||||
def get_csv_file_path() -> str:
|
||||
"""
|
||||
Возвращает путь к CSV-файлу во временной директории для пользовательских действий.
|
||||
"""
|
||||
temp_dir = tempfile.gettempdir()
|
||||
return os.path.join(temp_dir, "user_action_data.csv")
|
||||
|
||||
@staticmethod
|
||||
def get_fake_user_action_data() -> pd.DataFrame:
|
||||
"""
|
||||
Генерирует случайные тестовые данные действий пользователей.
|
||||
"""
|
||||
actions = ["login", "purchase", "view", "logout", "search"]
|
||||
ids = list(range(1, 10001))
|
||||
ids = list(range(1, 12491))
|
||||
action = []
|
||||
timestamp = []
|
||||
for _ in ids:
|
||||
|
||||
Reference in New Issue
Block a user