from datetime import datetime as dt
import os

import numpy as np

import settings


def mkdir():
    now = dt.now().replace(second=0, microsecond=0)
    name_dir = "q_agent_train_" + now.strftime("%Y-%m-%d_%H:%M:%S")
    path = os.path.join(settings.MODELS_DIR, name_dir)
    try:
        os.mkdir(path)
    except FileExistsError:
        name_dir += "_2"
        path = os.path.join(settings.MODELS_DIR, name_dir)
        os.mkdir(path)
    return path


def save_model(q_table: str, directory: str, file_name: str):
    file_path = os.path.join(directory, file_name)
    np.save(file_path, q_table)

[((229, 272), 'os.path.join', 'os.path.join', (['settings.MODELS_DIR', 'name_dir'], {}), '(settings.MODELS_DIR, name_dir)\n', (241, 272), False, 'import os\n'), ((536, 570), 'os.path.join', 'os.path.join', (['directory', 'file_name'], {}), '(directory, file_name)\n', (548, 570), False, 'import os\n'), ((575, 602), 'numpy.save', 'np.save', (['file_path', 'q_table'], {}), '(file_path, q_table)\n', (582, 602), True, 'import numpy as np\n'), ((290, 304), 'os.mkdir', 'os.mkdir', (['path'], {}), '(path)\n', (298, 304), False, 'import os\n'), ((108, 116), 'datetime.datetime.now', 'dt.now', ([], {}), '()\n', (114, 116), True, 'from datetime import datetime as dt\n'), ((373, 416), 'os.path.join', 'os.path.join', (['settings.MODELS_DIR', 'name_dir'], {}), '(settings.MODELS_DIR, name_dir)\n', (385, 416), False, 'import os\n'), ((425, 439), 'os.mkdir', 'os.mkdir', (['path'], {}), '(path)\n', (433, 439), False, 'import os\n')]