diff --git a/main_package/classes/json_importer.py b/main_package/classes/json_importer.py index 2e7907a..2cb37f3 100644 --- a/main_package/classes/json_importer.py +++ b/main_package/classes/json_importer.py @@ -118,7 +118,6 @@ class JsonImporter(AbstractImporter): for indx, sample in enumerate(self.df_samples_list): self.df_samples_list[indx] = self.compute_row_delta_sigle_samples_frame(sample, time_header_label, columns_header, shifted_cols_header) - #print(self.df_samples_list[indx]) self._concatenated_samples = pd.concat(self.df_samples_list) def build_list_of_samples_array(self, data_frame): diff --git a/main_package/classes/sample_path.py b/main_package/classes/sample_path.py index d1bd3da..aeb71f3 100644 --- a/main_package/classes/sample_path.py +++ b/main_package/classes/sample_path.py @@ -25,7 +25,9 @@ class SamplePath: def build_trajectories(self): self.importer.import_data() - self._trajectories = tr.Trajectory(self.importer.build_list_of_samples_array(self.importer.concatenated_samples)) + self._trajectories = \ + tr.Trajectory(self.importer.build_list_of_samples_array(self.importer.concatenated_samples), + len(self.importer.sorter) + 1) #self.trajectories.append(trajectory) self.importer.clear_data_frames() diff --git a/main_package/classes/structure.py b/main_package/classes/structure.py index 7f1bea8..d40ea2d 100644 --- a/main_package/classes/structure.py +++ b/main_package/classes/structure.py @@ -12,7 +12,6 @@ class Structure: def __init__(self, structure, variables): self.structure_frame = structure self.variables_frame = variables - #self._nodes_indexes = self.list_of_nodes_indexes() self.name_label = variables.columns.values[0] self.value_label = variables.columns.values[1] diff --git a/main_package/classes/trajectory.py b/main_package/classes/trajectory.py index a41fb6a..ab97686 100644 --- a/main_package/classes/trajectory.py +++ b/main_package/classes/trajectory.py @@ -14,15 +14,17 @@ class Trajectory: """ - def __init__(self, list_of_columns): - print(list_of_columns) + def __init__(self, list_of_columns, original_cols_number): + if type(list_of_columns[0][0]) != np.float64: + raise TypeError('The first array in the list has to be Times') + #TODO valutare se vale la pena ordinare la lista di numpy array per tipo + self.original_cols_number = original_cols_number self._actual_trajectory = np.array(list_of_columns[1:], dtype=np.int).T self._times = np.array(list_of_columns[0], dtype=np.float) - print(self._times) @property def trajectory(self): - return self._actual_trajectory[:, :4] + return self._actual_trajectory[:, :self.original_cols_number] @property def complete_trajectory(self): diff --git a/main_package/tests/test_json_importer.py b/main_package/tests/test_json_importer.py index 95b9f6e..7d66c8a 100644 --- a/main_package/tests/test_json_importer.py +++ b/main_package/tests/test_json_importer.py @@ -109,7 +109,11 @@ class TestJsonImporter(unittest.TestCase): def test_import_data(self): j1 = ji.JsonImporter('../data', 'samples', 'dyn.str', 'variables', 'Time', 'Name') j1.import_data() + self.assertEqual(list(j1.variables[j1.variables_key]), + list(j1.concatenated_samples.columns.values[1:len(j1.variables[j1.variables_key]) + 1])) print(j1.variables) + print(j1.structure) + print(j1.concatenated_samples) diff --git a/main_package/tests/test_trajectory.py b/main_package/tests/test_trajectory.py new file mode 100644 index 0000000..f983e60 --- /dev/null +++ b/main_package/tests/test_trajectory.py @@ -0,0 +1,24 @@ +import unittest +import numpy as np + +import trajectory as tr + + +class TestTrajecotry(unittest.TestCase): + + def test_init(self): + cols_list = [np.array([1.2,1.3,.14]), np.arange(1,4), np.arange(4,7)] + t1 = tr.Trajectory(cols_list, len(cols_list)) + self.assertTrue(np.array_equal(cols_list[0], t1.times)) + self.assertTrue(np.array_equal(np.ravel(t1.complete_trajectory[:, : 1]), cols_list[1])) + self.assertTrue(np.array_equal(np.ravel(t1.complete_trajectory[:, 1: 2]), cols_list[2])) + self.assertEqual(len(cols_list) - 1, t1.complete_trajectory.shape[1]) + + def test_init_first_array_not_float_type(self): + cols_list = [np.arange(1, 4), np.arange(4, 7), np.array([1.2, 1.3, .14])] + self.assertRaises(TypeError, tr.Trajectory, cols_list, len(cols_list)) + + + +if __name__ == '__main__': + unittest.main()