def exec(self, task_input, task_output): task_output["readings"] = self.data_readings resources = os.dir_res_list(task_output["res_loc"]) splitter_threads = [] for elem in resources: res_path = os.path_join(task_output["res_loc"], elem) if not os.is_path_file(res_path): continue splitter = _Splitter(elem, res_path, self.data_readings) splitter.start() splitter_threads.append(splitter) if len(splitter_threads) > 5: for thread in splitter_threads: thread.join() splitter_threads = [] for thread in splitter_threads: thread.join()
def exec(self, task_input, task_output): path = task_output["res_loc"] path = os.path_join(path, "apple_health_export", "electrocardiograms") resources = os.dir_res_list(path) workers = [] for elem in resources: res_path = os.path_join(path, elem) if os.is_path_file(res_path): splitted_elem = elem.split('.') backup_name = f"{splitted_elem[0]}.bak" worker = DataPreparerWorker(res_path, backup_name) worker.start() workers.append(worker) for worker in workers: worker.join() task_output["res_loc"] = path
def exec(self, task_input, task_output): labels_information_loc = task_input["labels_information_location"] resources_path = task_output["res_loc"] labels_info = jReader.parse_data(labels_information_loc) os.makedirs(task_input["training_loc"], True) resources = os.dir_res_list(resources_path) training_path = f"{task_input['training_loc']}{os.get_path_seperator()}training.csv" labels_path = f"{task_input['training_loc']}{os.get_path_seperator()}labels.csv" with open(training_path, 'w') as training_file: with open(labels_path, 'w') as labels_file: labels_file.write("Sinus, AF\n") index = 0 while index < task_input["readings"]: training_file.write(f"x_{index}") index += 1 if index < task_input["readings"]: training_file.write(',') training_file.write("\n") self.prep_training_file(training_file, labels_file, labels_info, task_output["res_loc"], resources)
def _setup(self, task_output): self.training_readings = task_output['readings'] ressources = os.dir_res_list(task_output["res_loc"]) training_data = self._training_loc(task_output["res_loc"]) task_output["training_loc"] = training_data backup = self._bakup_saved(training_data) return ressources, training_data, backup
def exec(self, task_input, task_output): #res_name = task_output["res_loc"].split("/") is_not_fantasia = task_output["res_loc"][-len("fantasia" ):] != "fantasia" if is_not_fantasia: return ressources = os.dir_res_list(task_output["res_loc"]) self._normalize_elements(ressources, task_output)
def exec(self, task_input, task_output): self.headders = task_input["headders"] res_loc = task_output["res_loc"] folder_res = op.dir_res_list(res_loc) for folder_res_elem in folder_res: target_res = op.path_join(res_loc, folder_res_elem) try: self._apply_headders(target_res) except Exception as e: print(e)
def exec(self, task_input, task_output): resources = os.dir_res_list(task_output["res_loc"]) workers = [] for resource in resources: worker = DataNormalizer(task_output["res_loc"], resource) worker.start() workers.append(worker) for worker in workers: worker.join()
def get_min_readings(self, path): resources = os.dir_res_list(path) readings = [] for elem in resources: readings.append(self.count(os.path_join(path, elem))) min_reading = readings[0] for elem in readings: if elem < min_reading: min_reading = elem return min_reading - 1
def exec(self, task_input, task_output): ressources, training_data, backup = self._setup(task_output) with open(training_data, 'w') as training: if backup is not None and os.is_path_file(backup): self._merge_training(training, backup) else: headders = self._get_headders(task_output["readings"]) training.write(headders) for split_folder in ressources: split_dir = os.path_join(task_output["res_loc"], split_folder) if os.is_path_file(split_dir) and not os.is_dir(split_dir): continue self.append_training_set(training, split_dir, os.dir_res_list(split_dir)) os.remove_dir(split_dir)
def exec(self, task_input, task_output): min_readings = self.get_min_readings(task_output["res_loc"]) index = 0 resources = os.dir_res_list(task_output["res_loc"]) workers = [] for elem in resources: path = os.path_join(task_output["res_loc"], elem) worker = NormalizeReadingsCountWorker(path, min_readings, index) worker.start() workers.append(worker) index += 1 for worker in workers: worker.join()
def exec(self, task_input, task_output): sampling_frequency = task_input["sampled_frequency"] target_frequency = task_input["target_frequency"] doubling_rate = math.ceil(sampling_frequency / (((target_frequency / sampling_frequency) - 1) * sampling_frequency)) res_elems = os.dir_res_list(task_output["res_loc"]) for res_elem in res_elems: origin_path = os.path_join(task_output["res_loc"], res_elem) if os.is_path_file(origin_path): backup_path = os.copy_file(origin_path, f"{task_input['name']}_bakup.bak") with open(origin_path, 'w') as file: with open(backup_path) as backup_file: temp_reading = backup_file.readline() sampling_nr = 1 while temp_reading != "": temp_reading = backup_file.readline() if temp_reading != "": splitted = temp_reading.split(',') file.write(f"{sampling_nr},{splitted[1]},{splitted[2]}") if "f2" in res_elem: file.write("\n") sampling_nr += 1 for _ in range(1, doubling_rate): temp_reading = backup_file.readline() if temp_reading != "": splitted = temp_reading.split(',') file.write(f"{sampling_nr},{splitted[1]},{splitted[2]}") if "f2" in res_elem: file.write("\n") sampling_nr += 1 if temp_reading != "": splitted = temp_reading.split(',') file.write(f"{sampling_nr},{splitted[1]},{splitted[2]}") if "f2" in res_elem: file.write("\n") sampling_nr += 1 splitted = temp_reading.split(',') file.write(f"{sampling_nr},{splitted[1]},{splitted[2]}") if "f2" in res_elem: file.write("\n") sampling_nr += 1 temp_reading = backup_file.readline() os.remove_file(backup_path)