From 8bd52b64f7daf76d001955c71c9ed8c9cb662c46 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 31 Aug 2018 16:40:46 +0300 Subject: [PATCH] Check for segment length in all models (#127) --- analytics/models/drop_model.py | 4 +++- analytics/models/jump_model.py | 4 +++- analytics/models/peak_model.py | 2 ++ analytics/models/reverse_peak_model.py | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/analytics/models/drop_model.py b/analytics/models/drop_model.py index 8c582a8..1d25be3 100644 --- a/analytics/models/drop_model.py +++ b/analytics/models/drop_model.py @@ -39,7 +39,9 @@ class DropModel(Model): segment_from_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['from'])) segment_to_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['to'])) - segment_data = data[segment_from_index : segment_to_index + 1].reset_index(drop=True) + segment_data = data[segment_from_index: segment_to_index + 1] + if len(segment_data) == 0: + continue segment_min = min(segment_data) segment_max = max(segment_data) confidences.append(0.20 * (segment_max - segment_min)) diff --git a/analytics/models/jump_model.py b/analytics/models/jump_model.py index bc0f5d2..64ac66d 100644 --- a/analytics/models/jump_model.py +++ b/analytics/models/jump_model.py @@ -42,7 +42,9 @@ class JumpModel(Model): segment_from_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['from'])) segment_to_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['to'])) - segment_data = data.loc[segment_from_index : segment_to_index + 1].reset_index(drop=True) + segment_data = data[segment_from_index: segment_to_index + 1] + if len(segment_data) == 0: + continue segment_min = min(segment_data) segment_max = max(segment_data) confidences.append(0.20 * (segment_max - segment_min)) diff --git a/analytics/models/peak_model.py b/analytics/models/peak_model.py index ca170c7..f27ed2e 100644 --- a/analytics/models/peak_model.py +++ b/analytics/models/peak_model.py @@ -38,6 +38,8 @@ class PeakModel(Model): segment_to_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['to'])) segment_data = data[segment_from_index: segment_to_index + 1] + if len(segment_data) == 0: + continue segment_min = min(segment_data) segment_max = max(segment_data) confidences.append(0.2 * (segment_max - segment_min)) diff --git a/analytics/models/reverse_peak_model.py b/analytics/models/reverse_peak_model.py index f50cddc..6c51a9e 100644 --- a/analytics/models/reverse_peak_model.py +++ b/analytics/models/reverse_peak_model.py @@ -37,6 +37,8 @@ class ReversePeakModel(Model): segment_to_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['to'])) segment_data = data[segment_from_index: segment_to_index + 1] + if len(segment_data) == 0: + continue segment_min = min(segment_data) segment_max = max(segment_data) confidences.append(0.2 * (segment_max - segment_min))