Esempio n. 1
0
def write_string_to_pathfile(string, filepath):
    """
    Write a string to a path file
    :param string: string to write
    :param path: path where write
    """
    try:
        folders.create_directory_from_fullpath(filepath)
        file = open(filepath, 'w+')
        file.write(str(string))
    except:
        raise ValueError(Errors.write_string_to_file)
Esempio n. 2
0
 def load_actual_information(self):
     """
     Information path contains best accuracy to compare before save.
     """
     # TODO (@gabvaztor) DOCs
     configuration = None
     folders.create_directory_from_fullpath(self.information_path)
     folders.create_file_from_fullpath(self.information_path)
     if os.stat(self.information_path).st_size != 0:
         with open(self.information_path) as json_configuration:
             dict = json.load(json_configuration)
             configuration = Configuration(dict)
     return configuration
Esempio n. 3
0
def get_temp_file_from_fullpath(fullpath):
    """
    Create and return the temp fullpath from another fullpath

    Args:
        fullpath: the fullpath

    Returns: the created temp fullpath
    """
    basename = os.path.basename(fullpath)
    path = os.path.dirname(fullpath) + "\\temp\\"
    folders.create_directory_from_fullpath(path)

    return path + basename
Esempio n. 4
0
 def load_actual_configuration(self):
     """
     :return: configuration
     """
     # TODO (@gabvaztor) DOCS
     configuration = None
     folders.create_directory_from_fullpath(self.configuration_path)
     folders.create_file_from_fullpath(self.configuration_path)
     try:
         if os.stat(self.configuration_path).st_size != 0:
             with open(self.configuration_path) as json_configuration:
                 dict = json.load(json_configuration)
                 configuration = Configuration(dict)
     except Exception:
         input(
             "Configuration problem: There is not a Configuration json file or this has nothing. Press Ok to"
             "continue the execution and the file will be created automatically or stop the program and create for"
             "your own")
     return configuration
Esempio n. 5
0
def create_historic_folder(filepath, type_file, test_accuracy=""):
    """
    Used when filepath exists to create a folder with actual_time to historicize
    :param filepath: file to save  
    :param type_file: Type of file (Information or Configuration)
    """

    # TODO (gabvaztor) Using new SettingObject path
    actual_time = str(
        time.strftime("%Y-%m-%d_%Hh%Mm%Ss", time.gmtime(time.time())))
    directory = os.path.dirname(filepath)
    filename = actual_time + "_" + os.path.basename(filepath)
    low_stripe = ""
    if test_accuracy and test_accuracy is not "":
        low_stripe = "_"
    information_folder = "\\History_Information\\" + type_file + "\\" + str(test_accuracy) + low_stripe + \
                         actual_time + "\\"
    folder = directory + information_folder
    folders.create_directory_from_fullpath(folder)
    return folder + filename
Esempio n. 6
0
def save_numpy_arrays_generic(folder_to_save,
                              numpy_files,
                              names=None,
                              **kwargs):
    """
    Save the accuracies and losses into a type_file folder.
    names and numpy_files are two list.
    :param folder_to_save:
    :param numpy_files:
    :param names: Must have same size than numpy_files

    """
    debug_mode = kwargs["DEBUG"] if "DEBUG" in kwargs else False
    # TODO (@gabvaztor) finish Docs
    folders.create_directory_from_fullpath(folder_to_save)
    for index in range(len(numpy_files)):
        if names:
            np.save(folder_to_save + names[index], numpy_files[index])
        else:
            name_file = Dictionary.filename_numpy_default
            np.save(folder_to_save + name_file + str(index + 1),
                    numpy_files[index])
    if not debug_mode:
        print("Files has been saved in numpy format")