From 9419134a01d9d70ac6e7a92396b469dcfcc720e8 Mon Sep 17 00:00:00 2001 From: philpMartin Date: Thu, 30 Jul 2020 14:32:06 +0200 Subject: [PATCH] Some Ref JsonImp --- main_package/classes/json_importer.py | 18 ++++++++++++++---- main_package/classes/structure_estimator.py | 2 +- main_package/tests/test_structure_estimator.py | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/main_package/classes/json_importer.py b/main_package/classes/json_importer.py index 5f9e097..5e1f2c0 100644 --- a/main_package/classes/json_importer.py +++ b/main_package/classes/json_importer.py @@ -39,11 +39,12 @@ class JsonImporter(AbstractImporter): def import_data(self): raw_data = self.read_json_file() + self.import_variables(raw_data) self.import_trajectories(raw_data) self.compute_row_delta_in_all_samples_frames(self.time_key) self.clear_data_frame_list() self.import_structure(raw_data) - self.import_variables(raw_data, self.sorter) + # self.import_variables(raw_data, self.sorter) def import_trajectories(self, raw_data: pd.DataFrame): self.normalize_trajectories(raw_data, 0, self.samples_label) @@ -51,10 +52,13 @@ class JsonImporter(AbstractImporter): def import_structure(self, raw_data: pd.DataFrame): self._df_structure = self.one_level_normalizing(raw_data, 0, self.structure_label) - def import_variables(self, raw_data: pd.DataFrame, sorter: typing.List): + def import_variables(self, raw_data: pd.DataFrame): self._df_variables = self.one_level_normalizing(raw_data, 0, self.variables_label) + self.sorter = self._df_variables[self.variables_key].to_list() + self.sorter.sort() + print("Sorter:", self.sorter) self._df_variables[self.variables_key] = self._df_variables[self.variables_key].astype("category") - self._df_variables[self.variables_key] = self._df_variables[self.variables_key].cat.set_categories(sorter) + self._df_variables[self.variables_key] = self._df_variables[self.variables_key].cat.set_categories(self.sorter) self._df_variables = self._df_variables.sort_values([self.variables_key]) def read_json_file(self) -> typing.List: @@ -105,7 +109,7 @@ class JsonImporter(AbstractImporter): self.df_samples_list = [pd.DataFrame(sample) for sample in raw_data[indx][trajectories_key]] #for sample_indx, sample in enumerate(raw_data[indx][trajectories_key]): #self.df_samples_list.append(pd.DataFrame(sample)) - self.sorter = list(self.df_samples_list[0].columns.values)[1:] + #self.sorter = list(self.df_samples_list[0].columns.values)[1:] def compute_row_delta_sigle_samples_frame(self, sample_frame: pd.DataFrame, time_header_label: str, columns_header: typing.List, shifted_cols_header: typing.List) \ @@ -126,6 +130,12 @@ class JsonImporter(AbstractImporter): self.df_samples_list[indx] = self.compute_row_delta_sigle_samples_frame(sample, time_header_label, self.sorter, shifted_cols_header) self._concatenated_samples = pd.concat(self.df_samples_list) + complete_header = self.sorter[:] + complete_header.insert(0, 'Time') + complete_header.extend(shifted_cols_header) + print("Complete Header", complete_header) + self._concatenated_samples = self._concatenated_samples[complete_header] + print("Concat Samples", self._concatenated_samples) def build_list_of_samples_array(self, data_frame: pd.DataFrame) -> typing.List: """ diff --git a/main_package/classes/structure_estimator.py b/main_package/classes/structure_estimator.py index b22a091..95b2493 100644 --- a/main_package/classes/structure_estimator.py +++ b/main_package/classes/structure_estimator.py @@ -191,7 +191,7 @@ class StructureEstimator: while b < len(u): #for parent_id in u: parent_indx = 0 - while u and parent_indx < tests_parents_numb and b < len(u): + while parent_indx < len(u): # list_without_test_parent = u.remove(parent_id) removed = False #print("b", b) diff --git a/main_package/tests/test_structure_estimator.py b/main_package/tests/test_structure_estimator.py index 14651cb..131a328 100644 --- a/main_package/tests/test_structure_estimator.py +++ b/main_package/tests/test_structure_estimator.py @@ -32,6 +32,7 @@ class TestStructureEstimator(unittest.TestCase): lp.print_stats() #se1.ctpc_algorithm() print(se1.complete_graph.edges) + print(self.s1.structure.list_of_edges()) def aux_test_complete_test(self, estimator, test_par, test_child, p_set): estimator.complete_test(test_par, test_child, p_set)