From 9d0674636647be3cad8f77c5c1b6b84d143e2e54 Mon Sep 17 00:00:00 2001 From: Raphael Sturgis <araphael.sturgis@lis-lab.fr> Date: Thu, 17 Mar 2022 10:41:18 +0100 Subject: [PATCH] implemented feature --- skais/ais/ais_trajectory.py | 10 ++++++++-- skais/tests/ais/test_ais_trajectory.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/skais/ais/ais_trajectory.py b/skais/ais/ais_trajectory.py index 7fb2a11..f836472 100644 --- a/skais/ais/ais_trajectory.py +++ b/skais/ais/ais_trajectory.py @@ -215,5 +215,11 @@ class AISTrajectory(AISPoints): else: return AISTrajectory(new_df, mmsi=self.mmsi) - def get_time_per_label_shift(self): - pass \ No newline at end of file + def get_time_per_label_shift(self, label_column='label'): + current_label = -1 + result = [] + for index, row in self.df.iterrows(): + if current_label != row[label_column]: + current_label = row[label_column] + result.append((row['ts_sec'], current_label)) + return result \ No newline at end of file diff --git a/skais/tests/ais/test_ais_trajectory.py b/skais/tests/ais/test_ais_trajectory.py index 0566fca..bea4d88 100644 --- a/skais/tests/ais/test_ais_trajectory.py +++ b/skais/tests/ais/test_ais_trajectory.py @@ -354,7 +354,7 @@ class TestAISTrajectory(unittest.TestCase): trajectory = AISTrajectory( pd.DataFrame( { - "label": [1 for _ in range(0, 101, 10)] + [2 for _ in range(0, 101, 10)], + "label": [1 for _ in range(11)] + [2 for _ in range(10)], "ts_sec": [i for i in range(0, 12001, 600)] } ) @@ -369,7 +369,7 @@ class TestAISTrajectory(unittest.TestCase): trajectory = AISTrajectory( pd.DataFrame( { - "label": [1 for _ in range(0, 101, 10)] + [2 for _ in range(0, 101, 10)]+ [1 for _ in range(0, 101, 10)], + "label": [1 for _ in range(11)] + [2 for _ in range(10)]+ [1 for _ in range(10)], "ts_sec": [i for i in range(0, 18001, 600)] } ) -- GitLab