def run(self): path_split = self.path.split(os.get_path_seperator()) backup_name = path_split[len(path_split) - 1] backup_name = backup_name.split('.')[0] backup = os.copy_file(self.path, f"{backup_name}{self.backup_name_index}.bak") with open(self.path, 'w') as data_file: with open(backup) as backup_file: data_file.write(backup_file.readline()) data_reading = backup_file.readline() index = 0 while index < self.readings and data_reading != "": data_file.write(data_reading) data_reading = backup_file.readline() index += 1 os.remove_file(backup)
def _calc_labels_loc(self, path): splitted = path.split(os.get_path_seperator()) label_path = f"{splitted[0]}{os.get_path_seperator()}{splitted[1]}" for path_elem in range(2, len(splitted) - 1): label_path = os.path_join(label_path, splitted[path_elem]) path_name = f"{splitted[len(splitted) - 1][:-4]}_labels.csv" return path, os.path_join(label_path, path_name)
def _training_loc(self, res_loc): path_split = res_loc.split(os.get_path_seperator()) training_path = f"{path_split[0]}{os.get_path_seperator()}{path_split[1]}" for x in range(2, len(path_split) - 1): training_path = os.path_join(training_path, path_split[x]) training_path = os.path_join(training_path, "training") os.makedirs(training_path, True) return os.path_join(training_path, f"{path_split[len(path_split) - 1]}.csv")