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)

[((12, 11, 12, 54), 'os.path.join', 'os.path.join', ({(12, 24, 12, 43): 'settings.MODELS_DIR', (12, 45, 12, 53): 'name_dir'}, {}), '(settings.MODELS_DIR, name_dir)', False, 'import os\n'), ((23, 16, 23, 50), 'os.path.join', 'os.path.join', ({(23, 29, 23, 38): 'directory', (23, 40, 23, 49): 'file_name'}, {}), '(directory, file_name)', False, 'import os\n'), ((24, 4, 24, 31), 'numpy.save', 'np.save', ({(24, 12, 24, 21): 'file_path', (24, 23, 24, 30): 'q_table'}, {}), '(file_path, q_table)', True, 'import numpy as np\n'), ((14, 8, 14, 22), 'os.mkdir', 'os.mkdir', ({(14, 17, 14, 21): 'path'}, {}), '(path)', False, 'import os\n'), ((10, 10, 10, 18), 'datetime.datetime.now', 'dt.now', ({}, {}), '()', True, 'from datetime import datetime as dt\n'), ((17, 15, 17, 58), 'os.path.join', 'os.path.join', ({(17, 28, 17, 47): 'settings.MODELS_DIR', (17, 49, 17, 57): 'name_dir'}, {}), '(settings.MODELS_DIR, name_dir)', False, 'import os\n'), ((18, 8, 18, 22), 'os.mkdir', 'os.mkdir', ({(18, 17, 18, 21): 'path'}, {}), '(path)', False, 'import os\n')]